[PATCH v2 26/28] drivers: Introduce driver_find_next_device() helper

From: Suzuki K Poulose
Date: Fri Jun 14 2019 - 14:00:20 EST


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

Cc: Elie Morisse <syniurge@xxxxxxxxx>
Cc: Nehal Shah <nehal-bakulchandra.shah@xxxxxxx>
Cc: Shyam Sundar S K <shyam-sundar.s-k@xxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
Cc: "Rafael J. Wysocki" <rafael@xxxxxxxxxx>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@xxxxxxx>
---
drivers/i2c/busses/i2c-amd-mp2-pci.c | 8 +-------
drivers/s390/cio/ccwgroup.c | 8 +-------
include/linux/device.h | 6 ++++++
3 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/drivers/i2c/busses/i2c-amd-mp2-pci.c b/drivers/i2c/busses/i2c-amd-mp2-pci.c
index c7fe3b4..5e4800d 100644
--- a/drivers/i2c/busses/i2c-amd-mp2-pci.c
+++ b/drivers/i2c/busses/i2c-amd-mp2-pci.c
@@ -457,18 +457,12 @@ static struct pci_driver amd_mp2_pci_driver = {
};
module_pci_driver(amd_mp2_pci_driver);

-static int amd_mp2_device_match(struct device *dev, const void *data)
-{
- return 1;
-}
-
struct amd_mp2_dev *amd_mp2_find_device(void)
{
struct device *dev;
struct pci_dev *pci_dev;

- dev = driver_find_device(&amd_mp2_pci_driver.driver, NULL, NULL,
- amd_mp2_device_match);
+ dev = driver_find_next_device(&amd_mp2_pci_driver.driver, NULL);
if (!dev)
return NULL;

diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
index d843e36..0005ec9 100644
--- a/drivers/s390/cio/ccwgroup.c
+++ b/drivers/s390/cio/ccwgroup.c
@@ -581,11 +581,6 @@ int ccwgroup_driver_register(struct ccwgroup_driver *cdriver)
}
EXPORT_SYMBOL(ccwgroup_driver_register);

-static int __ccwgroup_match_all(struct device *dev, const void *data)
-{
- return 1;
-}
-
/**
* ccwgroup_driver_unregister() - deregister a ccw group driver
* @cdriver: driver to be deregistered
@@ -597,8 +592,7 @@ void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver)
struct device *dev;

/* We don't want ccwgroup devices to live longer than their driver. */
- while ((dev = driver_find_device(&cdriver->driver, NULL, NULL,
- __ccwgroup_match_all))) {
+ while ((dev = driver_find_next_device(&cdriver->driver, NULL))) {
struct ccwgroup_device *gdev = to_ccwgroupdev(dev);

ccwgroup_ungroup(gdev);
diff --git a/include/linux/device.h b/include/linux/device.h
index f7f6a43..77f817d 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -475,6 +475,12 @@ static inline struct device *driver_find_device_by_devt(struct device_driver *dr
return driver_find_device(drv, NULL, &devt, device_match_devt);
}

+static inline struct device *driver_find_next_device(struct device_driver *drv,
+ struct device *start)
+{
+ return driver_find_device(drv, start, NULL, device_match_any);
+}
+
void driver_deferred_probe_add(struct device *dev);
int driver_deferred_probe_check_state(struct device *dev);

--
2.7.4