]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
drivers: Add generic helper to match any device
authorSuzuki K Poulose <suzuki.poulose@arm.com>
Tue, 23 Jul 2019 22:18:37 +0000 (23:18 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 30 Jul 2019 11:07:42 +0000 (13:07 +0200)
Add a generic helper to match any/all devices. Using this
introduce new wrappers {bus/driver/class}_find_next_device().

Cc: Elie Morisse <syniurge@gmail.com>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Nehal Shah <nehal-bakulchandra.shah@amd.com>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Cc: Shyam Sundar S K <shyam-sundar.s-k@amd.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com> # PCI
Link: https://lore.kernel.org/r/20190723221838.12024-7-suzuki.poulose@arm.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/core.c
drivers/i2c/busses/i2c-amd-mp2-pci.c
drivers/pci/probe.c
drivers/s390/cio/ccwgroup.c
drivers/scsi/scsi_proc.c
include/linux/device.h

index 57d71bc2c55973cc20afe98d7bc126d087bda23d..e22e29b3dc970ba73dbb7f8f9e423ed6a6910022 100644 (file)
@@ -3379,3 +3379,9 @@ int device_match_acpi_dev(struct device *dev, const void *adev)
        return ACPI_COMPANION(dev) == adev;
 }
 EXPORT_SYMBOL(device_match_acpi_dev);
+
+int device_match_any(struct device *dev, const void *unused)
+{
+       return 1;
+}
+EXPORT_SYMBOL_GPL(device_match_any);
index c7fe3b44a860174a936665fbf0e1dfc628f4466a..5e4800d72e00bc5a4c7a5b98294d22f99a093168 100644 (file)
@@ -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;
 
index a3c7338fad86413374f0f40c19df6974f82acd46..dbeeb385fb9fc4cf2d9d4aceaa26c30fb6d20f47 100644 (file)
@@ -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;
index d843e362c167c76ecaf1885989195ebf33bdf731..0005ec9285aa833a8d74c3828e65c9397e1d8b7a 100644 (file)
@@ -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);
index c074631086a4db3e38c03d6a1425607472afd69c..5b313226f11c614cf84aa8cc55d037f9f34332a0 100644 (file)
@@ -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;
 }
index 7514ef3d3f1a09f859f969856749e52c697e73d3..8ae3f4b472934270e99b3eff7c4d1a2fe7636639 100644 (file)
@@ -169,6 +169,7 @@ int device_match_of_node(struct device *dev, const void *np);
 int device_match_fwnode(struct device *dev, const void *fwnode);
 int device_match_devt(struct device *dev, const void *pdevt);
 int device_match_acpi_dev(struct device *dev, const void *adev);
+int device_match_any(struct device *dev, const void *unused);
 
 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
                     int (*fn)(struct device *dev, void *data));
@@ -225,6 +226,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);
+}
+
 #ifdef CONFIG_ACPI
 struct acpi_device;
 
@@ -465,6 +476,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);
+}
+
 #ifdef CONFIG_ACPI
 /**
  * driver_find_device_by_acpi_dev : device iterator for locating a particular