aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/core.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2008-08-25 13:50:19 -0400
committerJens Axboe <jens.axboe@oracle.com>2008-10-09 02:56:04 -0400
commit5a3ceb861663040f9ef0176df4aaa494bba5e352 (patch)
tree035472164252c3b54071f044c161b312b6bc8b44 /drivers/base/core.c
parenta1ed5b0cffe4b16a93a6a3390e8cee0fbef94f86 (diff)
driver-core: use klist for class device list and implement iterator
Iterating over entries using callback usually isn't too fun especially when the entry being iterated over can't be manipulated freely. This patch converts class->p->class_devices to klist and implements class device iterator so that the users can freely build their own control structure. The users are also free to call back into class code without worrying about locking. class_for_each_device() and class_find_device() are converted to use the new iterators, so their users don't have to worry about locking anymore either. Note: This depends on klist-dont-iterate-over-deleted-entries patch because class_intf->add/remove_dev() depends on proper synchronization with device removal. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Greg Kroah-Hartman <gregkh@suse.de> Cc: Jens Axboe <jens.axboe@oracle.com> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'drivers/base/core.c')
-rw-r--r--drivers/base/core.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c
index d021c98605b3..b98cb1416a2d 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -536,7 +536,6 @@ void device_initialize(struct device *dev)
536 klist_init(&dev->klist_children, klist_children_get, 536 klist_init(&dev->klist_children, klist_children_get,
537 klist_children_put); 537 klist_children_put);
538 INIT_LIST_HEAD(&dev->dma_pools); 538 INIT_LIST_HEAD(&dev->dma_pools);
539 INIT_LIST_HEAD(&dev->node);
540 init_MUTEX(&dev->sem); 539 init_MUTEX(&dev->sem);
541 spin_lock_init(&dev->devres_lock); 540 spin_lock_init(&dev->devres_lock);
542 INIT_LIST_HEAD(&dev->devres_head); 541 INIT_LIST_HEAD(&dev->devres_head);
@@ -916,7 +915,8 @@ int device_add(struct device *dev)
916 if (dev->class) { 915 if (dev->class) {
917 mutex_lock(&dev->class->p->class_mutex); 916 mutex_lock(&dev->class->p->class_mutex);
918 /* tie the class to the device */ 917 /* tie the class to the device */
919 list_add_tail(&dev->node, &dev->class->p->class_devices); 918 klist_add_tail(&dev->knode_class,
919 &dev->class->p->class_devices);
920 920
921 /* notify any interfaces that the device is here */ 921 /* notify any interfaces that the device is here */
922 list_for_each_entry(class_intf, 922 list_for_each_entry(class_intf,
@@ -1032,7 +1032,7 @@ void device_del(struct device *dev)
1032 if (class_intf->remove_dev) 1032 if (class_intf->remove_dev)
1033 class_intf->remove_dev(dev, class_intf); 1033 class_intf->remove_dev(dev, class_intf);
1034 /* remove the device from the class list */ 1034 /* remove the device from the class list */
1035 list_del_init(&dev->node); 1035 klist_del(&dev->knode_class);
1036 mutex_unlock(&dev->class->p->class_mutex); 1036 mutex_unlock(&dev->class->p->class_mutex);
1037 } 1037 }
1038 device_remove_file(dev, &uevent_attr); 1038 device_remove_file(dev, &uevent_attr);