]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/base/driver.c
[PATCH] klist: fix klist to have the same klist_add semantics as list_head
[linux-2.6-omap-h63xx.git] / drivers / base / driver.c
index 1b645886e9eba14046fbb0d62fd7051477ff43a5..291c5954a3af58afd353a8a6369850a5bf19e483 100644 (file)
@@ -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.