#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;
}
}
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);