Add a wrapper to driver_find_device() to search for a device
by name, similar to the other iterators, reusing the generic
match function. Also convert the existing users to make use of
the new helper.

Cc: Lee Jones <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Heiko Carstens <[email protected]>
Cc: Peter Oberparleiter <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: "Rafael J. Wysocki" <[email protected]>
Signed-off-by: Suzuki K Poulose <[email protected]>
---
 drivers/s390/cio/ccwgroup.c | 10 +---------
 drivers/s390/cio/device.c   | 17 +----------------
 include/linux/device.h      | 12 ++++++++++++
 3 files changed, 14 insertions(+), 25 deletions(-)

diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
index ea176157..d843e36 100644
--- a/drivers/s390/cio/ccwgroup.c
+++ b/drivers/s390/cio/ccwgroup.c
@@ -608,13 +608,6 @@ void ccwgroup_driver_unregister(struct ccwgroup_driver 
*cdriver)
 }
 EXPORT_SYMBOL(ccwgroup_driver_unregister);
 
-static int __ccwgroupdev_check_busid(struct device *dev, const void *id)
-{
-       char *bus_id = id;
-
-       return (strcmp(bus_id, dev_name(dev)) == 0);
-}
-
 /**
  * get_ccwgroupdev_by_busid() - obtain device from a bus id
  * @gdrv: driver the device is owned by
@@ -631,8 +624,7 @@ struct ccwgroup_device *get_ccwgroupdev_by_busid(struct 
ccwgroup_driver *gdrv,
 {
        struct device *dev;
 
-       dev = driver_find_device(&gdrv->driver, NULL, bus_id,
-                                __ccwgroupdev_check_busid);
+       dev = driver_find_device_by_name(&gdrv->driver, bus_id);
 
        return dev ? to_ccwgroupdev(dev) : NULL;
 }
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index f27536b..df29d7e 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -1649,20 +1649,6 @@ int ccw_device_force_console(struct ccw_device *cdev)
 EXPORT_SYMBOL_GPL(ccw_device_force_console);
 #endif
 
-/*
- * get ccw_device matching the busid, but only if owned by cdrv
- */
-static int
-__ccwdev_check_busid(struct device *dev, const void *id)
-{
-       char *bus_id;
-
-       bus_id = id;
-
-       return (strcmp(bus_id, dev_name(dev)) == 0);
-}
-
-
 /**
  * get_ccwdev_by_busid() - obtain device from a bus id
  * @cdrv: driver the device is owned by
@@ -1679,8 +1665,7 @@ struct ccw_device *get_ccwdev_by_busid(struct ccw_driver 
*cdrv,
 {
        struct device *dev;
 
-       dev = driver_find_device(&cdrv->driver, NULL, (void *)bus_id,
-                                __ccwdev_check_busid);
+       dev = driver_find_device_by_name(&cdrv->driver, bus_id);
 
        return dev ? to_ccwdev(dev) : NULL;
 }
diff --git a/include/linux/device.h b/include/linux/device.h
index 6768e2b..0d3958e 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -425,6 +425,18 @@ struct device *driver_find_device(struct device_driver 
*drv,
                                  struct device *start, const void *data,
                                  int (*match)(struct device *dev, const void 
*data));
 
+/**
+ * driver_find_device_by_name - device iterator for locating a particular 
device
+ * of a specific name.
+ * @driver: the driver we're iterating
+ * @name: name of the device to match
+ */
+static inline struct device *driver_find_device_by_name(struct device_driver 
*drv,
+                                                       const char *name)
+{
+       return driver_find_device(drv, NULL, name, device_match_name);
+}
+
 void driver_deferred_probe_add(struct device *dev);
 int driver_deferred_probe_check_state(struct device *dev);
 
-- 
2.7.4

Reply via email to