Commit a1ee9a35 authored by Patrick Mochel's avatar Patrick Mochel

devicemode: Implement driver_for_each_dev

- iterate over all devices a driver has, with proper locking on driver and refcounting on devices
parent 95548e47
...@@ -8,6 +8,39 @@ ...@@ -8,6 +8,39 @@
#include <linux/errno.h> #include <linux/errno.h>
#include "base.h" #include "base.h"
int driver_for_each_dev(struct device_driver * drv, void * data, int (*callback)(struct device *, void * ))
{
struct device * next;
struct device * dev = NULL;
struct list_head * node;
int error = 0;
get_driver(drv);
read_lock(&drv->lock);
node = drv->devices.next;
while (node != &drv->devices) {
next = list_entry(node,struct device,driver_list);
get_device(next);
read_unlock(&drv->lock);
if (dev)
put_device(dev);
dev = next;
if ((error = callback(dev,data))) {
put_device(dev);
break;
}
read_lock(&drv->lock);
node = dev->driver_list.next;
}
read_unlock(&drv->lock);
if (dev)
put_device(dev);
put_driver(drv);
return error;
}
/** /**
* driver_make_dir - create a driverfs directory for a driver * driver_make_dir - create a driverfs directory for a driver
* @drv: driver in question * @drv: driver in question
...@@ -68,5 +101,6 @@ void put_driver(struct device_driver * drv) ...@@ -68,5 +101,6 @@ void put_driver(struct device_driver * drv)
drv->release(drv); drv->release(drv);
} }
EXPORT_SYMBOL(driver_for_each_dev);
EXPORT_SYMBOL(driver_register); EXPORT_SYMBOL(driver_register);
EXPORT_SYMBOL(put_driver); EXPORT_SYMBOL(put_driver);
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