aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/bus.c
diff options
context:
space:
mode:
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 c3fac7fd555e..2c64b792d074 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);