diff options
author | mochel@digitalimplant.org <mochel@digitalimplant.org> | 2005-03-24 22:08:30 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-06-20 18:15:23 -0400 |
commit | 36239577cfb6b9a7c111209536b54200b0252ebf (patch) | |
tree | f8fa5034fbb31d273d0889119cbc20e4c4b0c983 /drivers | |
parent | 9a881f166f473373589ce6f3fdc47b44a1450e2d (diff) |
[PATCH] Use a klist for device child lists.
- Use klist iterator in device_for_each_child(), making it safe to use for
removing devices.
- Remove unused list_to_dev() function.
- Kills all usage of devices_subsys.rwsem.
Signed-off-by: Patrick Mochel <mochel@digitalimplant.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/base/core.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c index bfa4268289ea..1d8c7790b55a 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -207,8 +207,7 @@ void device_initialize(struct device *dev) | |||
207 | { | 207 | { |
208 | kobj_set_kset_s(dev, devices_subsys); | 208 | kobj_set_kset_s(dev, devices_subsys); |
209 | kobject_init(&dev->kobj); | 209 | kobject_init(&dev->kobj); |
210 | INIT_LIST_HEAD(&dev->node); | 210 | klist_init(&dev->klist_children); |
211 | INIT_LIST_HEAD(&dev->children); | ||
212 | INIT_LIST_HEAD(&dev->dma_pools); | 211 | INIT_LIST_HEAD(&dev->dma_pools); |
213 | init_MUTEX(&dev->sem); | 212 | init_MUTEX(&dev->sem); |
214 | } | 213 | } |
@@ -249,10 +248,8 @@ int device_add(struct device *dev) | |||
249 | goto PMError; | 248 | goto PMError; |
250 | if ((error = bus_add_device(dev))) | 249 | if ((error = bus_add_device(dev))) |
251 | goto BusError; | 250 | goto BusError; |
252 | down_write(&devices_subsys.rwsem); | ||
253 | if (parent) | 251 | if (parent) |
254 | list_add_tail(&dev->node, &parent->children); | 252 | klist_add_tail(&parent->klist_children, &dev->knode_parent); |
255 | up_write(&devices_subsys.rwsem); | ||
256 | 253 | ||
257 | /* notify platform of device entry */ | 254 | /* notify platform of device entry */ |
258 | if (platform_notify) | 255 | if (platform_notify) |
@@ -335,10 +332,8 @@ void device_del(struct device * dev) | |||
335 | { | 332 | { |
336 | struct device * parent = dev->parent; | 333 | struct device * parent = dev->parent; |
337 | 334 | ||
338 | down_write(&devices_subsys.rwsem); | ||
339 | if (parent) | 335 | if (parent) |
340 | list_del_init(&dev->node); | 336 | klist_remove(&dev->knode_parent); |
341 | up_write(&devices_subsys.rwsem); | ||
342 | 337 | ||
343 | /* Notify the platform of the removal, in case they | 338 | /* Notify the platform of the removal, in case they |
344 | * need to do anything... | 339 | * need to do anything... |
@@ -372,6 +367,12 @@ void device_unregister(struct device * dev) | |||
372 | } | 367 | } |
373 | 368 | ||
374 | 369 | ||
370 | static struct device * next_device(struct klist_iter * i) | ||
371 | { | ||
372 | struct klist_node * n = klist_next(i); | ||
373 | return n ? container_of(n, struct device, knode_parent) : NULL; | ||
374 | } | ||
375 | |||
375 | /** | 376 | /** |
376 | * device_for_each_child - device child iterator. | 377 | * device_for_each_child - device child iterator. |
377 | * @dev: parent struct device. | 378 | * @dev: parent struct device. |
@@ -384,18 +385,17 @@ void device_unregister(struct device * dev) | |||
384 | * We check the return of @fn each time. If it returns anything | 385 | * We check the return of @fn each time. If it returns anything |
385 | * other than 0, we break out and return that value. | 386 | * other than 0, we break out and return that value. |
386 | */ | 387 | */ |
387 | int device_for_each_child(struct device * dev, void * data, | 388 | int device_for_each_child(struct device * parent, void * data, |
388 | int (*fn)(struct device *, void *)) | 389 | int (*fn)(struct device *, void *)) |
389 | { | 390 | { |
391 | struct klist_iter i; | ||
390 | struct device * child; | 392 | struct device * child; |
391 | int error = 0; | 393 | int error = 0; |
392 | 394 | ||
393 | down_read(&devices_subsys.rwsem); | 395 | klist_iter_init(&parent->klist_children, &i); |
394 | list_for_each_entry(child, &dev->children, node) { | 396 | while ((child = next_device(&i)) && !error) |
395 | if((error = fn(child, data))) | 397 | error = fn(child, data); |
396 | break; | 398 | klist_iter_exit(&i); |
397 | } | ||
398 | up_read(&devices_subsys.rwsem); | ||
399 | return error; | 399 | return error; |
400 | } | 400 | } |
401 | 401 | ||