X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=fs%2Fchar_dev.c;h=4e163afc168c21cc682326ef2b3596d09c8258d1;hb=987b0145d94eecf292d8b301228356f44611ab7c;hp=f3418f7a6e9d9da9bf894840cd23eba9be77d5b7;hpb=f7ed79d23a47594e7834d66a8f14449796d4f3e6;p=linux-2.6.git diff --git a/fs/char_dev.c b/fs/char_dev.c index f3418f7a6..4e163afc1 100644 --- a/fs/char_dev.c +++ b/fs/char_dev.c @@ -20,7 +20,6 @@ #include #include #include -#include #ifdef CONFIG_KMOD #include @@ -28,7 +27,7 @@ static struct kobj_map *cdev_map; -static DEFINE_MUTEX(chrdevs_lock); +static DECLARE_MUTEX(chrdevs_lock); static struct char_device_struct { struct char_device_struct *next; @@ -53,10 +52,10 @@ void chrdev_show(struct seq_file *f, off_t offset) struct char_device_struct *cd; if (offset < CHRDEV_MAJOR_HASH_SIZE) { - mutex_lock(&chrdevs_lock); + down(&chrdevs_lock); for (cd = chrdevs[offset]; cd; cd = cd->next) seq_printf(f, "%3d %s\n", cd->major, cd->name); - mutex_unlock(&chrdevs_lock); + up(&chrdevs_lock); } } @@ -81,11 +80,13 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor, int ret = 0; int i; - cd = kzalloc(sizeof(struct char_device_struct), GFP_KERNEL); + cd = kmalloc(sizeof(struct char_device_struct), GFP_KERNEL); if (cd == NULL) return ERR_PTR(-ENOMEM); - mutex_lock(&chrdevs_lock); + memset(cd, 0, sizeof(struct char_device_struct)); + + down(&chrdevs_lock); /* temporary */ if (major == 0) { @@ -120,10 +121,10 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor, } cd->next = *cp; *cp = cd; - mutex_unlock(&chrdevs_lock); + up(&chrdevs_lock); return cd; out: - mutex_unlock(&chrdevs_lock); + up(&chrdevs_lock); kfree(cd); return ERR_PTR(ret); } @@ -134,7 +135,7 @@ __unregister_chrdev_region(unsigned major, unsigned baseminor, int minorct) struct char_device_struct *cd = NULL, **cp; int i = major_to_index(major); - mutex_lock(&chrdevs_lock); + down(&chrdevs_lock); for (cp = &chrdevs[i]; *cp; cp = &(*cp)->next) if ((*cp)->major == major && (*cp)->baseminor == baseminor && @@ -144,7 +145,7 @@ __unregister_chrdev_region(unsigned major, unsigned baseminor, int minorct) cd = *cp; *cp = cd->next; } - mutex_unlock(&chrdevs_lock); + up(&chrdevs_lock); return cd; } @@ -185,7 +186,7 @@ int alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count, } int register_chrdev(unsigned int major, const char *name, - const struct file_operations *fops) + struct file_operations *fops) { struct char_device_struct *cd; struct cdev *cdev; @@ -341,7 +342,7 @@ static void cdev_purge(struct cdev *cdev) * is contain the open that then fills in the correct operations * depending on the special file... */ -const struct file_operations def_chr_fops = { +struct file_operations def_chr_fops = { .open = chrdev_open, }; @@ -399,8 +400,9 @@ static struct kobj_type ktype_cdev_dynamic = { struct cdev *cdev_alloc(void) { - struct cdev *p = kzalloc(sizeof(struct cdev), GFP_KERNEL); + struct cdev *p = kmalloc(sizeof(struct cdev), GFP_KERNEL); if (p) { + memset(p, 0, sizeof(struct cdev)); p->kobj.ktype = &ktype_cdev_dynamic; INIT_LIST_HEAD(&p->list); kobject_init(&p->kobj); @@ -408,7 +410,7 @@ struct cdev *cdev_alloc(void) return p; } -void cdev_init(struct cdev *cdev, const struct file_operations *fops) +void cdev_init(struct cdev *cdev, struct file_operations *fops) { memset(cdev, 0, sizeof *cdev); INIT_LIST_HEAD(&cdev->list);