1 diff -Nru a/drivers/char/misc.c b/drivers/char/misc.c
2 --- a/drivers/char/misc.c Mon Dec 22 15:56:26 2003
3 +++ b/drivers/char/misc.c Mon Dec 22 15:56:26 2003
5 #include <linux/devfs_fs_kernel.h>
6 #include <linux/stat.h>
7 #include <linux/init.h>
9 +#include <linux/device.h>
10 #include <linux/tty.h>
11 #include <linux/kmod.h>
17 +/* Misc class implementation */
21 + * - add a struct class_device to struct miscdevice and make all usages of
22 + * them dynamic. This will let us get rid of struct misc_dev below.
25 + struct list_head node;
27 + struct class_device class_dev;
29 +#define to_misc_dev(d) container_of(d, struct misc_dev, class_dev)
31 +static LIST_HEAD(misc_dev_list);
32 +static spinlock_t misc_dev_list_lock = SPIN_LOCK_UNLOCKED;
34 +static void release_misc_dev(struct class_device *class_dev)
36 + struct misc_dev *misc_dev = to_misc_dev(class_dev);
40 +static struct class misc_class = {
42 + .release = &release_misc_dev,
45 +static ssize_t show_dev(struct class_device *class_dev, char *buf)
47 + struct misc_dev *misc_dev = to_misc_dev(class_dev);
48 + return print_dev_t(buf, misc_dev->dev);
50 +static CLASS_DEVICE_ATTR(dev, S_IRUGO, show_dev, NULL);
52 +static void misc_add_class_device(struct miscdevice *misc)
54 + struct misc_dev *misc_dev = NULL;
57 + misc_dev = kmalloc(sizeof(*misc_dev), GFP_KERNEL);
60 + memset(misc_dev, 0x00, sizeof(*misc_dev));
62 + misc_dev->dev = MKDEV(MISC_MAJOR, misc->minor);
63 + misc_dev->class_dev.dev = misc->dev;
64 + misc_dev->class_dev.class = &misc_class;
65 + snprintf(misc_dev->class_dev.class_id, BUS_ID_SIZE, "%s", misc->name);
66 + retval = class_device_register(&misc_dev->class_dev);
69 + class_device_create_file(&misc_dev->class_dev, &class_device_attr_dev);
70 + spin_lock(&misc_dev_list_lock);
71 + list_add(&misc_dev->node, &misc_dev_list);
72 + spin_unlock(&misc_dev_list_lock);
78 +static void misc_remove_class_device(struct miscdevice *misc)
80 + struct misc_dev *misc_dev = NULL;
81 + struct list_head *tmp;
84 + spin_lock(&misc_dev_list_lock);
85 + list_for_each(tmp, &misc_dev_list) {
86 + misc_dev = list_entry(tmp, struct misc_dev, node);
87 + if ((MINOR(misc_dev->dev) == misc->minor)) {
93 + list_del(&misc_dev->node);
94 + spin_unlock(&misc_dev_list_lock);
95 + class_device_unregister(&misc_dev->class_dev);
97 + spin_unlock(&misc_dev_list_lock);
102 static struct file_operations misc_fops = {
103 .owner = THIS_MODULE,
107 devfs_mk_cdev(MKDEV(MISC_MAJOR, misc->minor),
108 S_IFCHR|S_IRUSR|S_IWUSR|S_IRGRP, misc->devfs_name);
109 + misc_add_class_device(misc);
112 * Add it to the front, so that later devices can "override"
116 list_del(&misc->list);
117 + misc_remove_class_device(misc);
118 devfs_remove(misc->devfs_name);
119 if (i < DYNAMIC_MINORS && i>0) {
120 misc_minors[i>>3] &= ~(1 << (misc->minor & 7));
123 ent->proc_fops = &misc_proc_fops;
125 + class_register(&misc_class);
126 #ifdef CONFIG_MVME16x
133 -module_init(misc_init);
134 +subsys_initcall(misc_init);
135 diff -Nru a/include/linux/miscdevice.h b/include/linux/miscdevice.h
136 --- a/include/linux/miscdevice.h Mon Dec 22 15:56:22 2003
137 +++ b/include/linux/miscdevice.h Mon Dec 22 15:56:22 2003
140 #define TUN_MINOR 200
148 struct file_operations *fops;
149 struct list_head list;
150 + struct device *dev;