aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/bus.c
diff options
context:
space:
mode:
authorCornelia Huck <cohuck@de.ibm.com>2005-06-22 10:59:51 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2005-06-30 01:48:03 -0400
commit0edb586049e57c56e625536476931117a57671e9 (patch)
tree9d92bb9821d134d199d62de1ff3096ff2b73fdc7 /drivers/base/bus.c
parentfd782a4a99d2d3e818b9465c427b10f7f027d7da (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/bus.c')
-rw-r--r--drivers/base/bus.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index c3fac7fd555..2c64b792d07 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -177,6 +177,39 @@ int bus_for_each_dev(struct bus_type * bus, struct device * start,
177 return error; 177 return error;
178} 178}
179 179
180/**
181 * bus_find_device - device iterator for locating a particular device.
182 * @bus: bus type
183 * @start: Device to begin with
184 * @data: Data to pass to match function
185 * @match: Callback function to check device
186 *
187 * This is similar to the bus_for_each_dev() function above, but it
188 * returns a reference to a device that is 'found' for later use, as
189 * determined by the @match callback.
190 *
191 * The callback should return 0 if the device doesn't match and non-zero
192 * if it does. If the callback returns non-zero, this function will
193 * return to the caller and not iterate over any more devices.
194 */
195struct device * bus_find_device(struct bus_type *bus,
196 struct device *start, void *data,
197 int (*match)(struct device *, void *))
198{
199 struct klist_iter i;
200 struct device *dev;
201
202 if (!bus)
203 return NULL;
204
205 klist_iter_init_node(&bus->klist_devices, &i,
206 (start ? &start->knode_bus : NULL));
207 while ((dev = next_device(&i)))
208 if (match(dev, data) && get_device(dev))
209 break;
210 klist_iter_exit(&i);
211 return dev;
212}
180 213
181 214
182static struct device_driver * next_driver(struct klist_iter * i) 215static struct device_driver * next_driver(struct klist_iter * i)
@@ -557,6 +590,7 @@ int __init buses_init(void)
557 590
558 591
559EXPORT_SYMBOL_GPL(bus_for_each_dev); 592EXPORT_SYMBOL_GPL(bus_for_each_dev);
593EXPORT_SYMBOL_GPL(bus_find_device);
560EXPORT_SYMBOL_GPL(bus_for_each_drv); 594EXPORT_SYMBOL_GPL(bus_for_each_drv);
561 595
562EXPORT_SYMBOL_GPL(bus_add_device); 596EXPORT_SYMBOL_GPL(bus_add_device);