Add a wrapper for bus_find_device() to find the next devices
on the given bus from the "start" device. Also convert the existing
users to make use of the new helper.

Cc: Bjorn Helgaas <[email protected]>
Cc: "James E.J. Bottomley" <[email protected]>
Cc: "Martin K. Petersen" <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: "Rafael J. Wysocki" <[email protected]>
Signed-off-by: Suzuki K Poulose <[email protected]>
---
 drivers/pci/probe.c      |  7 +------
 drivers/scsi/scsi_proc.c |  9 ++-------
 include/linux/device.h   | 10 ++++++++++
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index f9ef7ad..3504695 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -64,11 +64,6 @@ static struct resource *get_pci_domain_busn_res(int 
domain_nr)
        return &r->res;
 }
 
-static int find_anything(struct device *dev, const void *data)
-{
-       return 1;
-}
-
 /*
  * Some device drivers need know if PCI is initiated.
  * Basically, we think PCI is not initiated when there
@@ -79,7 +74,7 @@ int no_pci_devices(void)
        struct device *dev;
        int no_devices;
 
-       dev = bus_find_device(&pci_bus_type, NULL, NULL, find_anything);
+       dev = bus_find_next_device(&pci_bus_type, NULL);
        no_devices = (dev == NULL);
        put_device(dev);
        return no_devices;
diff --git a/drivers/scsi/scsi_proc.c b/drivers/scsi/scsi_proc.c
index c074631..5b31322 100644
--- a/drivers/scsi/scsi_proc.c
+++ b/drivers/scsi/scsi_proc.c
@@ -372,15 +372,10 @@ static ssize_t proc_scsi_write(struct file *file, const 
char __user *buf,
        return err;
 }
 
-static int always_match(struct device *dev, const void *data)
-{
-       return 1;
-}
-
 static inline struct device *next_scsi_device(struct device *start)
 {
-       struct device *next = bus_find_device(&scsi_bus_type, start, NULL,
-                                             always_match);
+       struct device *next = bus_find_next_device(&scsi_bus_type, start);
+
        put_device(start);
        return next;
 }
diff --git a/include/linux/device.h b/include/linux/device.h
index 3c244ac..1c137ab 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -225,6 +225,16 @@ static inline struct device 
*bus_find_device_by_devt(struct bus_type *bus,
        return bus_find_device(bus, NULL, &devt, device_match_devt);
 }
 
+/**
+ * bus_find_next_device - Find the next device after a given device in a
+ * given bus.
+ */
+static inline struct device *
+bus_find_next_device(struct bus_type *bus,struct device *cur)
+{
+       return bus_find_device(bus, cur, NULL, device_match_any);
+}
+
 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
                                        struct device *hint);
 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
-- 
2.7.4

Reply via email to