* 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>
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;
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);
}
}
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) {
}
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);
}
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 &&
cd = *cp;
*cp = cd->next;
}
- mutex_unlock(&chrdevs_lock);
+ up(&chrdevs_lock);
return cd;
}
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;
* 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,
};
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);
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);