diff options
author | Andi Kleen <andi@firstfloor.org> | 2010-01-05 06:48:02 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-03-07 20:04:47 -0500 |
commit | 38457ab3a0d36320370c715145ba6da514127194 (patch) | |
tree | 0c3f729c450b18b439dc6ce7a1542d9e8d3dd8e3 | |
parent | 1c205ae18db53ff72985dd79f3baaf2dbaba6db7 (diff) |
sysfs: Add attribute array to sysdev classes
Add a attribute array that is automatically registered and unregistered
to struct sysdev_class. This is similar to what struct class has.
A lot of drivers add list of attributes, so it's better to do
this easily in the common sysdev layer.
This adds a new field to struct sysdev_class. I audited the
whole tree and there are no dynamically allocated sysdev classes,
so this is fully compatible.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/base/sys.c | 9 | ||||
-rw-r--r-- | include/linux/sysdev.h | 2 |
2 files changed, 10 insertions, 1 deletions
diff --git a/drivers/base/sys.c b/drivers/base/sys.c index a38445c0f8c5..747c99e0568b 100644 --- a/drivers/base/sys.c +++ b/drivers/base/sys.c | |||
@@ -145,13 +145,20 @@ int sysdev_class_register(struct sysdev_class *cls) | |||
145 | if (retval) | 145 | if (retval) |
146 | return retval; | 146 | return retval; |
147 | 147 | ||
148 | return kset_register(&cls->kset); | 148 | retval = kset_register(&cls->kset); |
149 | if (!retval && cls->attrs) | ||
150 | retval = sysfs_create_files(&cls->kset.kobj, | ||
151 | (const struct attribute **)cls->attrs); | ||
152 | return retval; | ||
149 | } | 153 | } |
150 | 154 | ||
151 | void sysdev_class_unregister(struct sysdev_class *cls) | 155 | void sysdev_class_unregister(struct sysdev_class *cls) |
152 | { | 156 | { |
153 | pr_debug("Unregistering sysdev class '%s'\n", | 157 | pr_debug("Unregistering sysdev class '%s'\n", |
154 | kobject_name(&cls->kset.kobj)); | 158 | kobject_name(&cls->kset.kobj)); |
159 | if (cls->attrs) | ||
160 | sysfs_remove_files(&cls->kset.kobj, | ||
161 | (const struct attribute **)cls->attrs); | ||
155 | kset_unregister(&cls->kset); | 162 | kset_unregister(&cls->kset); |
156 | } | 163 | } |
157 | 164 | ||
diff --git a/include/linux/sysdev.h b/include/linux/sysdev.h index c2458fa8376c..b6244f9b533f 100644 --- a/include/linux/sysdev.h +++ b/include/linux/sysdev.h | |||
@@ -27,10 +27,12 @@ | |||
27 | 27 | ||
28 | 28 | ||
29 | struct sys_device; | 29 | struct sys_device; |
30 | struct sysdev_class_attribute; | ||
30 | 31 | ||
31 | struct sysdev_class { | 32 | struct sysdev_class { |
32 | const char *name; | 33 | const char *name; |
33 | struct list_head drivers; | 34 | struct list_head drivers; |
35 | struct sysdev_class_attribute **attrs; | ||
34 | 36 | ||
35 | /* Default operations for these types of devices */ | 37 | /* Default operations for these types of devices */ |
36 | int (*shutdown)(struct sys_device *); | 38 | int (*shutdown)(struct sys_device *); |