diff options
author | Matthew Wilcox <matthew@wil.cx> | 2008-05-28 12:28:39 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2008-07-22 00:54:52 -0400 |
commit | d2a3b9146e4f40c2e872d7567c996ef95083d802 (patch) | |
tree | c95bd0a155e1c868fcaffeb0949dd3441203f72a | |
parent | 1e41250863cd4de5ffa0678c405d001ca5b62796 (diff) |
class: add lockdep infrastructure
This adds the infrastructure to properly handle lockdep issues when the
internal class semaphore is changed to a mutex.
Matthew wrote the original patch, and Greg fixed it up to work properly
with the class_create() function.
From: Matthew Wilcox <matthew@wil.cx>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Cc: Dave Young <hidave.darkstar@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/base/class.c | 11 | ||||
-rw-r--r-- | include/linux/device.h | 25 |
2 files changed, 29 insertions, 7 deletions
diff --git a/drivers/base/class.c b/drivers/base/class.c index d24d21114ccb..89000566690c 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c | |||
@@ -134,7 +134,7 @@ static void remove_class_attrs(struct class *cls) | |||
134 | } | 134 | } |
135 | } | 135 | } |
136 | 136 | ||
137 | int class_register(struct class *cls) | 137 | int __class_register(struct class *cls, struct lock_class_key *key) |
138 | { | 138 | { |
139 | struct class_private *cp; | 139 | struct class_private *cp; |
140 | int error; | 140 | int error; |
@@ -178,6 +178,7 @@ int class_register(struct class *cls) | |||
178 | class_put(cls); | 178 | class_put(cls); |
179 | return error; | 179 | return error; |
180 | } | 180 | } |
181 | EXPORT_SYMBOL_GPL(__class_register); | ||
181 | 182 | ||
182 | void class_unregister(struct class *cls) | 183 | void class_unregister(struct class *cls) |
183 | { | 184 | { |
@@ -203,7 +204,8 @@ static void class_create_release(struct class *cls) | |||
203 | * Note, the pointer created here is to be destroyed when finished by | 204 | * Note, the pointer created here is to be destroyed when finished by |
204 | * making a call to class_destroy(). | 205 | * making a call to class_destroy(). |
205 | */ | 206 | */ |
206 | struct class *class_create(struct module *owner, const char *name) | 207 | struct class *__class_create(struct module *owner, const char *name, |
208 | struct lock_class_key *key) | ||
207 | { | 209 | { |
208 | struct class *cls; | 210 | struct class *cls; |
209 | int retval; | 211 | int retval; |
@@ -218,7 +220,7 @@ struct class *class_create(struct module *owner, const char *name) | |||
218 | cls->owner = owner; | 220 | cls->owner = owner; |
219 | cls->class_release = class_create_release; | 221 | cls->class_release = class_create_release; |
220 | 222 | ||
221 | retval = class_register(cls); | 223 | retval = __class_register(cls, key); |
222 | if (retval) | 224 | if (retval) |
223 | goto error; | 225 | goto error; |
224 | 226 | ||
@@ -228,6 +230,7 @@ error: | |||
228 | kfree(cls); | 230 | kfree(cls); |
229 | return ERR_PTR(retval); | 231 | return ERR_PTR(retval); |
230 | } | 232 | } |
233 | EXPORT_SYMBOL_GPL(__class_create); | ||
231 | 234 | ||
232 | /** | 235 | /** |
233 | * class_destroy - destroys a struct class structure | 236 | * class_destroy - destroys a struct class structure |
@@ -412,9 +415,7 @@ int __init classes_init(void) | |||
412 | 415 | ||
413 | EXPORT_SYMBOL_GPL(class_create_file); | 416 | EXPORT_SYMBOL_GPL(class_create_file); |
414 | EXPORT_SYMBOL_GPL(class_remove_file); | 417 | EXPORT_SYMBOL_GPL(class_remove_file); |
415 | EXPORT_SYMBOL_GPL(class_register); | ||
416 | EXPORT_SYMBOL_GPL(class_unregister); | 418 | EXPORT_SYMBOL_GPL(class_unregister); |
417 | EXPORT_SYMBOL_GPL(class_create); | ||
418 | EXPORT_SYMBOL_GPL(class_destroy); | 419 | EXPORT_SYMBOL_GPL(class_destroy); |
419 | 420 | ||
420 | EXPORT_SYMBOL_GPL(class_interface_register); | 421 | EXPORT_SYMBOL_GPL(class_interface_register); |
diff --git a/include/linux/device.h b/include/linux/device.h index b0556082179b..0e1d24c2ed41 100644 --- a/include/linux/device.h +++ b/include/linux/device.h | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/kobject.h> | 16 | #include <linux/kobject.h> |
17 | #include <linux/klist.h> | 17 | #include <linux/klist.h> |
18 | #include <linux/list.h> | 18 | #include <linux/list.h> |
19 | #include <linux/lockdep.h> | ||
19 | #include <linux/compiler.h> | 20 | #include <linux/compiler.h> |
20 | #include <linux/types.h> | 21 | #include <linux/types.h> |
21 | #include <linux/module.h> | 22 | #include <linux/module.h> |
@@ -205,8 +206,18 @@ struct class { | |||
205 | 206 | ||
206 | extern struct kobject *sysfs_dev_block_kobj; | 207 | extern struct kobject *sysfs_dev_block_kobj; |
207 | extern struct kobject *sysfs_dev_char_kobj; | 208 | extern struct kobject *sysfs_dev_char_kobj; |
208 | extern int __must_check class_register(struct class *class); | 209 | extern int __must_check __class_register(struct class *class, |
210 | struct lock_class_key *key); | ||
209 | extern void class_unregister(struct class *class); | 211 | extern void class_unregister(struct class *class); |
212 | |||
213 | /* This is a #define to keep the compiler from merging different | ||
214 | * instances of the __key variable */ | ||
215 | #define class_register(class) \ | ||
216 | ({ \ | ||
217 | static struct lock_class_key __key; \ | ||
218 | __class_register(class, &__key); \ | ||
219 | }) | ||
220 | |||
210 | extern int class_for_each_device(struct class *class, struct device *start, | 221 | extern int class_for_each_device(struct class *class, struct device *start, |
211 | void *data, | 222 | void *data, |
212 | int (*fn)(struct device *dev, void *data)); | 223 | int (*fn)(struct device *dev, void *data)); |
@@ -239,9 +250,19 @@ struct class_interface { | |||
239 | extern int __must_check class_interface_register(struct class_interface *); | 250 | extern int __must_check class_interface_register(struct class_interface *); |
240 | extern void class_interface_unregister(struct class_interface *); | 251 | extern void class_interface_unregister(struct class_interface *); |
241 | 252 | ||
242 | extern struct class *class_create(struct module *owner, const char *name); | 253 | extern struct class * __must_check __class_create(struct module *owner, |
254 | const char *name, | ||
255 | struct lock_class_key *key); | ||
243 | extern void class_destroy(struct class *cls); | 256 | extern void class_destroy(struct class *cls); |
244 | 257 | ||
258 | /* This is a #define to keep the compiler from merging different | ||
259 | * instances of the __key variable */ | ||
260 | #define class_create(owner, name) \ | ||
261 | ({ \ | ||
262 | static struct lock_class_key __key; \ | ||
263 | __class_create(owner, name, &__key); \ | ||
264 | }) | ||
265 | |||
245 | /* | 266 | /* |
246 | * The type of device, "struct device" is embedded in. A class | 267 | * The type of device, "struct device" is embedded in. A class |
247 | * or bus can contain devices of different types | 268 | * or bus can contain devices of different types |