Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=1f9ffc049d7a88c8489b883b6fc0a25185062002
Commit:     1f9ffc049d7a88c8489b883b6fc0a25185062002
Parent:     123ca9575b1f5342c05a4b84d6af8ba7587c2981
Author:     Greg Kroah-Hartman <[EMAIL PROTECTED]>
AuthorDate: Sun Jan 27 10:29:20 2008 -0800
Committer:  Greg Kroah-Hartman <[EMAIL PROTECTED]>
CommitDate: Sun Jan 27 15:01:39 2008 -0800

    Driver core: add bus_find_device_by_name function
    
    The driver core, and some other parts of the kernel just want to find a
    device based on a name for a specific bus.  Give them a simple wrapper
    to prevent them from having to always roll their own.
    
    This will be used in the PPC patch later in this series.
    
    Cc: Paul Mackerras <[EMAIL PROTECTED]>
    Signed-off-by: Greg Kroah-Hartman <[EMAIL PROTECTED]>
---
 drivers/base/bus.c     |   41 +++++++++++++++++++++++++++++------------
 include/linux/device.h |    3 +++
 2 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index f484495..055989e 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -163,15 +163,6 @@ static struct kset *bus_kset;
 
 #ifdef CONFIG_HOTPLUG
 /* Manually detach a device from its associated driver. */
-static int driver_helper(struct device *dev, void *data)
-{
-       const char *name = data;
-
-       if (strcmp(name, dev->bus_id) == 0)
-               return 1;
-       return 0;
-}
-
 static ssize_t driver_unbind(struct device_driver *drv,
                             const char *buf, size_t count)
 {
@@ -179,7 +170,7 @@ static ssize_t driver_unbind(struct device_driver *drv,
        struct device *dev;
        int err = -ENODEV;
 
-       dev = bus_find_device(bus, NULL, (void *)buf, driver_helper);
+       dev = bus_find_device_by_name(bus, NULL, buf);
        if (dev && dev->driver == drv) {
                if (dev->parent)        /* Needed for USB */
                        down(&dev->parent->sem);
@@ -206,7 +197,7 @@ static ssize_t driver_bind(struct device_driver *drv,
        struct device *dev;
        int err = -ENODEV;
 
-       dev = bus_find_device(bus, NULL, (void *)buf, driver_helper);
+       dev = bus_find_device_by_name(bus, NULL, buf);
        if (dev && dev->driver == NULL) {
                if (dev->parent)        /* Needed for USB */
                        down(&dev->parent->sem);
@@ -250,7 +241,7 @@ static ssize_t store_drivers_probe(struct bus_type *bus,
 {
        struct device *dev;
 
-       dev = bus_find_device(bus, NULL, (void *)buf, driver_helper);
+       dev = bus_find_device_by_name(bus, NULL, buf);
        if (!dev)
                return -ENODEV;
        if (bus_rescan_devices_helper(dev, NULL) != 0)
@@ -338,6 +329,32 @@ struct device *bus_find_device(struct bus_type *bus,
 }
 EXPORT_SYMBOL_GPL(bus_find_device);
 
+static int match_name(struct device *dev, void *data)
+{
+       const char *name = data;
+
+       if (strcmp(name, dev->bus_id) == 0)
+               return 1;
+       return 0;
+}
+
+/**
+ * bus_find_device_by_name - device iterator for locating a particular device 
of a specific name
+ * @bus: bus type
+ * @start: Device to begin with
+ * @name: name of the device to match
+ *
+ * This is similar to the bus_find_device() function above, but it handles
+ * searching by a name automatically, no need to write another strcmp matching
+ * function.
+ */
+struct device *bus_find_device_by_name(struct bus_type *bus,
+                                      struct device *start, const char *name)
+{
+       return bus_find_device(bus, start, (void *)name, match_name);
+}
+EXPORT_SYMBOL_GPL(bus_find_device_by_name);
+
 static struct device_driver *next_driver(struct klist_iter *i)
 {
        struct klist_node *n = klist_next(i);
diff --git a/include/linux/device.h b/include/linux/device.h
index 1880208..db375be 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -84,6 +84,9 @@ int bus_for_each_dev(struct bus_type *bus, struct device 
*start, void *data,
 struct device *bus_find_device(struct bus_type *bus, struct device *start,
                               void *data,
                               int (*match)(struct device *dev, void *data));
+struct device *bus_find_device_by_name(struct bus_type *bus,
+                                      struct device *start,
+                                      const char *name);
 
 int __must_check bus_for_each_drv(struct bus_type *bus,
                                  struct device_driver *start, void *data,
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to