]> git.pld-linux.org Git - packages/kernel.git/blame - 2.6.0-sysfs-3of4-lkml.patch
- added description of djurban's branch
[packages/kernel.git] / 2.6.0-sysfs-3of4-lkml.patch
CommitLineData
c3e6af00 1diff -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
4@@ -47,7 +47,7 @@
5 #include <linux/devfs_fs_kernel.h>
6 #include <linux/stat.h>
7 #include <linux/init.h>
8-
9+#include <linux/device.h>
10 #include <linux/tty.h>
11 #include <linux/kmod.h>
12
13@@ -180,6 +180,91 @@
14 return err;
15 }
16
17+/* Misc class implementation */
18+
19+/*
20+ * TODO for 2.7:
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.
23+ */
24+struct misc_dev {
25+ struct list_head node;
26+ dev_t dev;
27+ struct class_device class_dev;
28+};
29+#define to_misc_dev(d) container_of(d, struct misc_dev, class_dev)
30+
31+static LIST_HEAD(misc_dev_list);
32+static spinlock_t misc_dev_list_lock = SPIN_LOCK_UNLOCKED;
33+
34+static void release_misc_dev(struct class_device *class_dev)
35+{
36+ struct misc_dev *misc_dev = to_misc_dev(class_dev);
37+ kfree(misc_dev);
38+}
39+
40+static struct class misc_class = {
41+ .name = "misc",
42+ .release = &release_misc_dev,
43+};
44+
45+static ssize_t show_dev(struct class_device *class_dev, char *buf)
46+{
47+ struct misc_dev *misc_dev = to_misc_dev(class_dev);
48+ return print_dev_t(buf, misc_dev->dev);
49+}
50+static CLASS_DEVICE_ATTR(dev, S_IRUGO, show_dev, NULL);
51+
52+static void misc_add_class_device(struct miscdevice *misc)
53+{
54+ struct misc_dev *misc_dev = NULL;
55+ int retval;
56+
57+ misc_dev = kmalloc(sizeof(*misc_dev), GFP_KERNEL);
58+ if (!misc_dev)
59+ return;
60+ memset(misc_dev, 0x00, sizeof(*misc_dev));
61+
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);
67+ if (retval)
68+ goto error;
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);
73+ return;
74+error:
75+ kfree(misc_dev);
76+}
77+
78+static void misc_remove_class_device(struct miscdevice *misc)
79+{
80+ struct misc_dev *misc_dev = NULL;
81+ struct list_head *tmp;
82+ int found = 0;
83+
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)) {
88+ found = 1;
89+ break;
90+ }
91+ }
92+ if (found) {
93+ list_del(&misc_dev->node);
94+ spin_unlock(&misc_dev_list_lock);
95+ class_device_unregister(&misc_dev->class_dev);
96+ } else {
97+ spin_unlock(&misc_dev_list_lock);
98+ }
99+}
100+
101+
102 static struct file_operations misc_fops = {
103 .owner = THIS_MODULE,
104 .open = misc_open,
105@@ -236,6 +321,7 @@
106
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);
110
111 /*
112 * Add it to the front, so that later devices can "override"
113@@ -265,6 +351,7 @@
114
115 down(&misc_sem);
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));
121@@ -285,6 +372,7 @@
122 if (ent)
123 ent->proc_fops = &misc_proc_fops;
124 #endif
125+ class_register(&misc_class);
126 #ifdef CONFIG_MVME16x
127 rtc_MK48T08_init();
128 #endif
129@@ -319,4 +407,4 @@
130 }
131 return 0;
132 }
133-module_init(misc_init);
134+subsys_initcall(misc_init);
135diff -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
138@@ -36,12 +36,15 @@
139
140 #define TUN_MINOR 200
141
142+struct device;
143+
144 struct miscdevice
145 {
146 int minor;
147 const char *name;
148 struct file_operations *fops;
149 struct list_head list;
150+ struct device *dev;
151 char devfs_name[64];
152 };
153
This page took 0.921822 seconds and 4 git commands to generate.