Commit ace11a78 authored by Patrick Mochel's avatar Patrick Mochel

[driver model] Add device_for_each_child iterator.

From Mike Anderson: 

I have been using it on an outstanding patch for scsi_set_host_offline. It
appears to work fine in my testing.
parent 29b9acf6
......@@ -343,11 +343,40 @@ void device_unregister(struct device * dev)
put_device(dev);
}
/**
* device_for_each_child - device child iterator.
* @dev: parent struct device.
* @data: data for the callback.
* @fn: function to be called for each device.
*
* Iterate over @dev's child devices, and call @fn for each,
* passing it @data.
*
* We check the return of @fn each time. If it returns anything
* other than 0, we break out and return that value.
*/
int device_for_each_child(struct device * dev, void * data,
int (*fn)(struct device *, void *))
{
struct device * child;
int error = 0;
down_read(&devices_subsys.rwsem);
list_for_each_entry(child,&dev->children,node) {
if((error = fn(child,data)))
break;
}
up_read(&devices_subsys.rwsem);
return error;
}
int __init devices_init(void)
{
return subsystem_register(&devices_subsys);
}
EXPORT_SYMBOL(device_for_each_child);
EXPORT_SYMBOL(device_initialize);
EXPORT_SYMBOL(device_add);
EXPORT_SYMBOL(device_register);
......
......@@ -303,6 +303,8 @@ extern void device_unregister(struct device * dev);
extern void device_initialize(struct device * dev);
extern int device_add(struct device * dev);
extern void device_del(struct device * dev);
extern int device_for_each_child(struct device *, void *,
int (*fn)(struct device *, void *));
/*
* Manual binding of a device to driver. See drivers/base/bus.c
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment