linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / fs / char_dev.c
index 3483d3c..4e163af 100644 (file)
@@ -4,6 +4,7 @@
  *  Copyright (C) 1991, 1992  Linus Torvalds
  */
 
+#include <linux/config.h>
 #include <linux/init.h>
 #include <linux/fs.h>
 #include <linux/slab.h>
 #include <linux/errno.h>
 #include <linux/module.h>
 #include <linux/smp_lock.h>
+#include <linux/devfs_fs_kernel.h>
 #include <linux/seq_file.h>
 
 #include <linux/kobject.h>
 #include <linux/kobj_map.h>
 #include <linux/cdev.h>
-#include <linux/mutex.h>
 
 #ifdef CONFIG_KMOD
 #include <linux/kmod.h>
@@ -26,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;
@@ -51,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);
        }
 }
 
@@ -79,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) {
@@ -118,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);
 }
@@ -132,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 &&
@@ -142,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;
 }
 
@@ -182,30 +185,8 @@ int alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count,
        return 0;
 }
 
-/**
- * register_chrdev() - Register a major number for character devices.
- * @major: major device number or 0 for dynamic allocation
- * @name: name of this range of devices
- * @fops: file operations associated with this devices
- *
- * If @major == 0 this functions will dynamically allocate a major and return
- * its number.
- *
- * If @major > 0 this function will attempt to reserve a device with the given
- * major number and will return zero on success.
- *
- * Returns a -ve errno on failure.
- *
- * The name of this device has nothing to do with the name of the device in
- * /dev. It only helps to keep track of the different owners of devices. If
- * your module name has only one type of devices it's ok to use e.g. the name
- * of the module here.
- *
- * This function registers a range of 256 minor numbers. The first minor number
- * is 0.
- */
 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;
@@ -361,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,
 };
 
@@ -419,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);
@@ -428,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);