1
0
Fork 0

[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>
hifive-unleashed-5.1
mochel@digitalimplant.org 2005-03-24 19:08:30 -08:00 committed by Greg Kroah-Hartman
parent 9a881f166f
commit 36239577cf
2 changed files with 17 additions and 23 deletions

View File

@ -207,8 +207,7 @@ void device_initialize(struct device *dev)
{ {
kobj_set_kset_s(dev, devices_subsys); kobj_set_kset_s(dev, devices_subsys);
kobject_init(&dev->kobj); kobject_init(&dev->kobj);
INIT_LIST_HEAD(&dev->node); klist_init(&dev->klist_children);
INIT_LIST_HEAD(&dev->children);
INIT_LIST_HEAD(&dev->dma_pools); INIT_LIST_HEAD(&dev->dma_pools);
init_MUTEX(&dev->sem); init_MUTEX(&dev->sem);
} }
@ -249,10 +248,8 @@ int device_add(struct device *dev)
goto PMError; goto PMError;
if ((error = bus_add_device(dev))) if ((error = bus_add_device(dev)))
goto BusError; goto BusError;
down_write(&devices_subsys.rwsem);
if (parent) if (parent)
list_add_tail(&dev->node, &parent->children); klist_add_tail(&parent->klist_children, &dev->knode_parent);
up_write(&devices_subsys.rwsem);
/* notify platform of device entry */ /* notify platform of device entry */
if (platform_notify) if (platform_notify)
@ -335,10 +332,8 @@ void device_del(struct device * dev)
{ {
struct device * parent = dev->parent; struct device * parent = dev->parent;
down_write(&devices_subsys.rwsem);
if (parent) if (parent)
list_del_init(&dev->node); klist_remove(&dev->knode_parent);
up_write(&devices_subsys.rwsem);
/* Notify the platform of the removal, in case they /* Notify the platform of the removal, in case they
* need to do anything... * need to do anything...
@ -372,6 +367,12 @@ void device_unregister(struct device * dev)
} }
static struct device * next_device(struct klist_iter * i)
{
struct klist_node * n = klist_next(i);
return n ? container_of(n, struct device, knode_parent) : NULL;
}
/** /**
* device_for_each_child - device child iterator. * device_for_each_child - device child iterator.
* @dev: parent struct device. * @dev: parent struct device.
@ -384,18 +385,17 @@ void device_unregister(struct device * dev)
* We check the return of @fn each time. If it returns anything * We check the return of @fn each time. If it returns anything
* other than 0, we break out and return that value. * other than 0, we break out and return that value.
*/ */
int device_for_each_child(struct device * dev, void * data, int device_for_each_child(struct device * parent, void * data,
int (*fn)(struct device *, void *)) int (*fn)(struct device *, void *))
{ {
struct klist_iter i;
struct device * child; struct device * child;
int error = 0; int error = 0;
down_read(&devices_subsys.rwsem); klist_iter_init(&parent->klist_children, &i);
list_for_each_entry(child, &dev->children, node) { while ((child = next_device(&i)) && !error)
if((error = fn(child, data))) error = fn(child, data);
break; klist_iter_exit(&i);
}
up_read(&devices_subsys.rwsem);
return error; return error;
} }

View File

@ -262,8 +262,8 @@ extern void class_device_destroy(struct class *cls, dev_t devt);
struct device { struct device {
struct list_head node; /* node in sibling list */ struct klist klist_children;
struct list_head children; struct klist_node knode_parent; /* node in sibling list */
struct klist_node knode_driver; struct klist_node knode_driver;
struct klist_node knode_bus; struct klist_node knode_bus;
struct device * parent; struct device * parent;
@ -298,12 +298,6 @@ struct device {
void (*release)(struct device * dev); void (*release)(struct device * dev);
}; };
static inline struct device *
list_to_dev(struct list_head *node)
{
return list_entry(node, struct device, node);
}
static inline void * static inline void *
dev_get_drvdata (struct device *dev) dev_get_drvdata (struct device *dev)
{ {