diff options
author | Dave Young <hidave.darkstar@gmail.com> | 2008-05-28 12:28:39 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2008-07-22 00:54:52 -0400 |
commit | f75b1c60fc1e53c4004a79ea0be071aa3318cdcc (patch) | |
tree | 75728a6393f2e7568cd17ffd749fd3c4a4e1d95f /drivers/base/class.c | |
parent | d2a3b9146e4f40c2e872d7567c996ef95083d802 (diff) |
class: change internal semaphore to a mutex
Now that the lockdep infrastructure in the class core is in place, we
should be able to properly change the internal class semaphore to be a
mutex.
David wrote the original patch, and Greg fixed it up to apply properly
due to all of the recent changes in this area.
From: Dave Young <hidave.darkstar@gmail.com>
Cc: Matthew Wilcox <matthew@wil.cx>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base/class.c')
-rw-r--r-- | drivers/base/class.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/drivers/base/class.c b/drivers/base/class.c index 89000566690c..839d27cecb36 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/err.h> | 18 | #include <linux/err.h> |
19 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
20 | #include <linux/genhd.h> | 20 | #include <linux/genhd.h> |
21 | #include <linux/mutex.h> | ||
21 | #include "base.h" | 22 | #include "base.h" |
22 | 23 | ||
23 | #define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr) | 24 | #define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr) |
@@ -147,7 +148,7 @@ int __class_register(struct class *cls, struct lock_class_key *key) | |||
147 | INIT_LIST_HEAD(&cp->class_devices); | 148 | INIT_LIST_HEAD(&cp->class_devices); |
148 | INIT_LIST_HEAD(&cp->class_interfaces); | 149 | INIT_LIST_HEAD(&cp->class_interfaces); |
149 | kset_init(&cp->class_dirs); | 150 | kset_init(&cp->class_dirs); |
150 | init_MUTEX(&cp->class_sem); | 151 | __mutex_init(&cp->class_mutex, "struct class mutex", key); |
151 | error = kobject_set_name(&cp->class_subsys.kobj, "%s", cls->name); | 152 | error = kobject_set_name(&cp->class_subsys.kobj, "%s", cls->name); |
152 | if (error) { | 153 | if (error) { |
153 | kfree(cp); | 154 | kfree(cp); |
@@ -281,7 +282,7 @@ char *make_class_name(const char *name, struct kobject *kobj) | |||
281 | * We check the return of @fn each time. If it returns anything | 282 | * We check the return of @fn each time. If it returns anything |
282 | * other than 0, we break out and return that value. | 283 | * other than 0, we break out and return that value. |
283 | * | 284 | * |
284 | * Note, we hold class->class_sem in this function, so it can not be | 285 | * Note, we hold class->class_mutex in this function, so it can not be |
285 | * re-acquired in @fn, otherwise it will self-deadlocking. For | 286 | * re-acquired in @fn, otherwise it will self-deadlocking. For |
286 | * example, calls to add or remove class members would be verboten. | 287 | * example, calls to add or remove class members would be verboten. |
287 | */ | 288 | */ |
@@ -293,7 +294,7 @@ int class_for_each_device(struct class *class, struct device *start, | |||
293 | 294 | ||
294 | if (!class) | 295 | if (!class) |
295 | return -EINVAL; | 296 | return -EINVAL; |
296 | down(&class->p->class_sem); | 297 | mutex_lock(&class->p->class_mutex); |
297 | list_for_each_entry(dev, &class->p->class_devices, node) { | 298 | list_for_each_entry(dev, &class->p->class_devices, node) { |
298 | if (start) { | 299 | if (start) { |
299 | if (start == dev) | 300 | if (start == dev) |
@@ -306,7 +307,7 @@ int class_for_each_device(struct class *class, struct device *start, | |||
306 | if (error) | 307 | if (error) |
307 | break; | 308 | break; |
308 | } | 309 | } |
309 | up(&class->p->class_sem); | 310 | mutex_unlock(&class->p->class_mutex); |
310 | 311 | ||
311 | return error; | 312 | return error; |
312 | } | 313 | } |
@@ -329,7 +330,7 @@ EXPORT_SYMBOL_GPL(class_for_each_device); | |||
329 | * | 330 | * |
330 | * Note, you will need to drop the reference with put_device() after use. | 331 | * Note, you will need to drop the reference with put_device() after use. |
331 | * | 332 | * |
332 | * We hold class->class_sem in this function, so it can not be | 333 | * We hold class->class_mutex in this function, so it can not be |
333 | * re-acquired in @match, otherwise it will self-deadlocking. For | 334 | * re-acquired in @match, otherwise it will self-deadlocking. For |
334 | * example, calls to add or remove class members would be verboten. | 335 | * example, calls to add or remove class members would be verboten. |
335 | */ | 336 | */ |
@@ -343,7 +344,7 @@ struct device *class_find_device(struct class *class, struct device *start, | |||
343 | if (!class) | 344 | if (!class) |
344 | return NULL; | 345 | return NULL; |
345 | 346 | ||
346 | down(&class->p->class_sem); | 347 | mutex_lock(&class->p->class_mutex); |
347 | list_for_each_entry(dev, &class->p->class_devices, node) { | 348 | list_for_each_entry(dev, &class->p->class_devices, node) { |
348 | if (start) { | 349 | if (start) { |
349 | if (start == dev) | 350 | if (start == dev) |
@@ -357,7 +358,7 @@ struct device *class_find_device(struct class *class, struct device *start, | |||
357 | } else | 358 | } else |
358 | put_device(dev); | 359 | put_device(dev); |
359 | } | 360 | } |
360 | up(&class->p->class_sem); | 361 | mutex_unlock(&class->p->class_mutex); |
361 | 362 | ||
362 | return found ? dev : NULL; | 363 | return found ? dev : NULL; |
363 | } | 364 | } |
@@ -375,13 +376,13 @@ int class_interface_register(struct class_interface *class_intf) | |||
375 | if (!parent) | 376 | if (!parent) |
376 | return -EINVAL; | 377 | return -EINVAL; |
377 | 378 | ||
378 | down(&parent->p->class_sem); | 379 | mutex_lock(&parent->p->class_mutex); |
379 | list_add_tail(&class_intf->node, &parent->p->class_interfaces); | 380 | list_add_tail(&class_intf->node, &parent->p->class_interfaces); |
380 | if (class_intf->add_dev) { | 381 | if (class_intf->add_dev) { |
381 | list_for_each_entry(dev, &parent->p->class_devices, node) | 382 | list_for_each_entry(dev, &parent->p->class_devices, node) |
382 | class_intf->add_dev(dev, class_intf); | 383 | class_intf->add_dev(dev, class_intf); |
383 | } | 384 | } |
384 | up(&parent->p->class_sem); | 385 | mutex_unlock(&parent->p->class_mutex); |
385 | 386 | ||
386 | return 0; | 387 | return 0; |
387 | } | 388 | } |
@@ -394,13 +395,13 @@ void class_interface_unregister(struct class_interface *class_intf) | |||
394 | if (!parent) | 395 | if (!parent) |
395 | return; | 396 | return; |
396 | 397 | ||
397 | down(&parent->p->class_sem); | 398 | mutex_lock(&parent->p->class_mutex); |
398 | list_del_init(&class_intf->node); | 399 | list_del_init(&class_intf->node); |
399 | if (class_intf->remove_dev) { | 400 | if (class_intf->remove_dev) { |
400 | list_for_each_entry(dev, &parent->p->class_devices, node) | 401 | list_for_each_entry(dev, &parent->p->class_devices, node) |
401 | class_intf->remove_dev(dev, class_intf); | 402 | class_intf->remove_dev(dev, class_intf); |
402 | } | 403 | } |
403 | up(&parent->p->class_sem); | 404 | mutex_unlock(&parent->p->class_mutex); |
404 | 405 | ||
405 | class_put(parent); | 406 | class_put(parent); |
406 | } | 407 | } |