aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/base/core.c30
-rw-r--r--include/linux/device.h10
2 files changed, 17 insertions, 23 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
370static 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 */
387int device_for_each_child(struct device * dev, void * data, 388int 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
diff --git a/include/linux/device.h b/include/linux/device.h
index d2434934d091..43249260cd1c 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -262,8 +262,8 @@ extern void class_device_destroy(struct class *cls, dev_t devt);
262 262
263 263
264struct device { 264struct device {
265 struct list_head node; /* node in sibling list */ 265 struct klist klist_children;
266 struct list_head children; 266 struct klist_node knode_parent; /* node in sibling list */
267 struct klist_node knode_driver; 267 struct klist_node knode_driver;
268 struct klist_node knode_bus; 268 struct klist_node knode_bus;
269 struct device * parent; 269 struct device * parent;
@@ -298,12 +298,6 @@ struct device {
298 void (*release)(struct device * dev); 298 void (*release)(struct device * dev);
299}; 299};
300 300
301static inline struct device *
302list_to_dev(struct list_head *node)
303{
304 return list_entry(node, struct device, node);
305}
306
307static inline void * 301static inline void *
308dev_get_drvdata (struct device *dev) 302dev_get_drvdata (struct device *dev)
309{ 303{