Make checkpatch.pl shut up on fs/inode.c
[safe/jmp/linux-2.6] / fs / char_dev.c
index c3bfa76..38f7122 100644 (file)
@@ -22,9 +22,6 @@
 #include <linux/mutex.h>
 #include <linux/backing-dev.h>
 
-#ifdef CONFIG_KMOD
-#include <linux/kmod.h>
-#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;
 }
 
@@ -510,9 +512,8 @@ struct cdev *cdev_alloc(void)
 {
        struct cdev *p = kzalloc(sizeof(struct cdev), GFP_KERNEL);
        if (p) {
-               p->kobj.ktype = &ktype_cdev_dynamic;
                INIT_LIST_HEAD(&p->list);
-               kobject_init(&p->kobj);
+               kobject_init(&p->kobj, &ktype_cdev_dynamic);
        }
        return p;
 }
@@ -529,8 +530,7 @@ void cdev_init(struct cdev *cdev, const struct file_operations *fops)
 {
        memset(cdev, 0, sizeof *cdev);
        INIT_LIST_HEAD(&cdev->list);
-       cdev->kobj.ktype = &ktype_cdev_default;
-       kobject_init(&cdev->kobj);
+       kobject_init(&cdev->kobj, &ktype_cdev_default);
        cdev->ops = fops;
 }