X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=fs%2Fchar_dev.c;h=38f71222a552e46e58e0b801e91063d714a134fb;hb=d8ae4601a4b7ea1fa17fa395c3468c0e144d1275;hp=b2dd5a0366316b4df53d0d208b444b4ca74bdd37;hpb=a5815ddf26aa8208d4ad79b4fba5e6bf7d5ba688;p=safe%2Fjmp%2Flinux-2.6 diff --git a/fs/char_dev.c b/fs/char_dev.c index b2dd5a0..38f7122 100644 --- a/fs/char_dev.c +++ b/fs/char_dev.c @@ -22,9 +22,6 @@ #include #include -#ifdef CONFIG_KMOD -#include -#endif #include "internal.h" /* @@ -55,7 +52,6 @@ static struct char_device_struct { unsigned int baseminor; int minorct; char name[64]; - struct file_operations *fops; struct cdev *cdev; /* will die */ } *chrdevs[CHRDEV_MAJOR_HASH_SIZE]; @@ -124,7 +120,7 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor, cd->major = major; cd->baseminor = baseminor; cd->minorct = minorct; - strncpy(cd->name,name, 64); + strlcpy(cd->name, name, sizeof(cd->name)); i = major_to_index(major); @@ -357,7 +353,7 @@ void cdev_put(struct cdev *p) /* * Called every time a character special file is opened */ -int chrdev_open(struct inode * inode, struct file * filp) +static int chrdev_open(struct inode *inode, struct file *filp) { struct cdev *p; struct cdev *new = NULL; @@ -374,6 +370,8 @@ int chrdev_open(struct inode * inode, struct file * filp) return -ENXIO; new = container_of(kobj, struct cdev, kobj); spin_lock(&cdev_lock); + /* Check i_cdev again in case somebody beat us to it while + we dropped the lock. */ p = inode->i_cdev; if (!p) { inode->i_cdev = p = new; @@ -388,18 +386,22 @@ int chrdev_open(struct inode * inode, struct file * filp) cdev_put(new); if (ret) return ret; + + ret = -ENXIO; filp->f_op = fops_get(p->ops); - if (!filp->f_op) { - cdev_put(p); - return -ENXIO; - } + if (!filp->f_op) + goto out_cdev_put; + if (filp->f_op->open) { - lock_kernel(); ret = filp->f_op->open(inode,filp); - unlock_kernel(); + if (ret) + goto out_cdev_put; } - if (ret) - cdev_put(p); + + return 0; + + out_cdev_put: + cdev_put(p); return ret; } @@ -511,7 +513,7 @@ struct cdev *cdev_alloc(void) struct cdev *p = kzalloc(sizeof(struct cdev), GFP_KERNEL); if (p) { INIT_LIST_HEAD(&p->list); - kobject_init_ng(&p->kobj, &ktype_cdev_dynamic); + kobject_init(&p->kobj, &ktype_cdev_dynamic); } return p; } @@ -528,7 +530,7 @@ void cdev_init(struct cdev *cdev, const struct file_operations *fops) { memset(cdev, 0, sizeof *cdev); INIT_LIST_HEAD(&cdev->list); - kobject_init_ng(&cdev->kobj, &ktype_cdev_default); + kobject_init(&cdev->kobj, &ktype_cdev_default); cdev->ops = fops; }