diff options
author | Cornelia Huck <cohuck@de.ibm.com> | 2005-06-22 10:59:51 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-06-30 01:48:03 -0400 |
commit | 0edb586049e57c56e625536476931117a57671e9 (patch) | |
tree | 9d92bb9821d134d199d62de1ff3096ff2b73fdc7 /drivers/base/driver.c | |
parent | fd782a4a99d2d3e818b9465c427b10f7f027d7da (diff) |
[PATCH] driver core: add bus_find_device & driver_find_device functions
Add bus_find_device() and driver_find_device() which allow searching for a
device in the bus's resp. the driver's klist and obtain a reference on it.
Signed-off-by: Cornelia Huck <cohuck@de.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base/driver.c')
-rw-r--r-- | drivers/base/driver.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 1b645886e9eb..291c5954a3af 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c | |||
@@ -56,6 +56,41 @@ EXPORT_SYMBOL_GPL(driver_for_each_device); | |||
56 | 56 | ||
57 | 57 | ||
58 | /** | 58 | /** |
59 | * driver_find_device - device iterator for locating a particular device. | ||
60 | * @driver: The device's driver | ||
61 | * @start: Device to begin with | ||
62 | * @data: Data to pass to match function | ||
63 | * @match: Callback function to check device | ||
64 | * | ||
65 | * This is similar to the driver_for_each_device() function above, but | ||
66 | * it returns a reference to a device that is 'found' for later use, as | ||
67 | * determined by the @match callback. | ||
68 | * | ||
69 | * The callback should return 0 if the device doesn't match and non-zero | ||
70 | * if it does. If the callback returns non-zero, this function will | ||
71 | * return to the caller and not iterate over any more devices. | ||
72 | */ | ||
73 | struct device * driver_find_device(struct device_driver *drv, | ||
74 | struct device * start, void * data, | ||
75 | int (*match)(struct device *, void *)) | ||
76 | { | ||
77 | struct klist_iter i; | ||
78 | struct device *dev; | ||
79 | |||
80 | if (!drv) | ||
81 | return NULL; | ||
82 | |||
83 | klist_iter_init_node(&drv->klist_devices, &i, | ||
84 | (start ? &start->knode_driver : NULL)); | ||
85 | while ((dev = next_device(&i))) | ||
86 | if (match(dev, data) && get_device(dev)) | ||
87 | break; | ||
88 | klist_iter_exit(&i); | ||
89 | return dev; | ||
90 | } | ||
91 | EXPORT_SYMBOL_GPL(driver_find_device); | ||
92 | |||
93 | /** | ||
59 | * driver_create_file - create sysfs file for driver. | 94 | * driver_create_file - create sysfs file for driver. |
60 | * @drv: driver. | 95 | * @drv: driver. |
61 | * @attr: driver attribute descriptor. | 96 | * @attr: driver attribute descriptor. |