X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=drivers%2Fbase%2Fdriver.c;h=291c5954a3af58afd353a8a6369850a5bf19e483;hb=c1b054d03f5b31c33eaa0b267c629b118eaf3790;hp=1b645886e9eba14046fbb0d62fd7051477ff43a5;hpb=a5324343955997d1439f26518ddac567cd5d134b;p=powerpc.git diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 1b645886e9..291c5954a3 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -55,6 +55,41 @@ int driver_for_each_device(struct device_driver * drv, struct device * start, EXPORT_SYMBOL_GPL(driver_for_each_device); +/** + * driver_find_device - device iterator for locating a particular device. + * @driver: The device's driver + * @start: Device to begin with + * @data: Data to pass to match function + * @match: Callback function to check device + * + * This is similar to the driver_for_each_device() function above, but + * it returns a reference to a device that is 'found' for later use, as + * determined by the @match callback. + * + * The callback should return 0 if the device doesn't match and non-zero + * if it does. If the callback returns non-zero, this function will + * return to the caller and not iterate over any more devices. + */ +struct device * driver_find_device(struct device_driver *drv, + struct device * start, void * data, + int (*match)(struct device *, void *)) +{ + struct klist_iter i; + struct device *dev; + + if (!drv) + return NULL; + + klist_iter_init_node(&drv->klist_devices, &i, + (start ? &start->knode_driver : NULL)); + while ((dev = next_device(&i))) + if (match(dev, data) && get_device(dev)) + break; + klist_iter_exit(&i); + return dev; +} +EXPORT_SYMBOL_GPL(driver_find_device); + /** * driver_create_file - create sysfs file for driver. * @drv: driver.