X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=fs%2Fchar_dev.c;h=700697a726187863a3d4557b27410192ad7d45d9;hb=53c9c5c0e32c69f9df1822e47671c13e3402c82f;hp=038674aa88a72c09a88388ee7cf1b54839675052;hpb=922f9cfa79b52c85b6002d96cb0eefd13437c58c;p=safe%2Fjmp%2Flinux-2.6 diff --git a/fs/char_dev.c b/fs/char_dev.c index 038674a..700697a 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]; @@ -374,6 +370,8 @@ static 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 @@ static 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; }