Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drivers: Add generic helper to match any device

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>

authored by

Suzuki K Poulose and committed by
Greg Kroah-Hartman
6bf85ba9 00500147

+28 -27
+6
drivers/base/core.c
··· 3379 3379 return ACPI_COMPANION(dev) == adev; 3380 3380 } 3381 3381 EXPORT_SYMBOL(device_match_acpi_dev); 3382 + 3383 + int device_match_any(struct device *dev, const void *unused) 3384 + { 3385 + return 1; 3386 + } 3387 + EXPORT_SYMBOL_GPL(device_match_any);
+1 -7
drivers/i2c/busses/i2c-amd-mp2-pci.c
··· 457 457 }; 458 458 module_pci_driver(amd_mp2_pci_driver); 459 459 460 - static int amd_mp2_device_match(struct device *dev, const void *data) 461 - { 462 - return 1; 463 - } 464 - 465 460 struct amd_mp2_dev *amd_mp2_find_device(void) 466 461 { 467 462 struct device *dev; 468 463 struct pci_dev *pci_dev; 469 464 470 - dev = driver_find_device(&amd_mp2_pci_driver.driver, NULL, NULL, 471 - amd_mp2_device_match); 465 + dev = driver_find_next_device(&amd_mp2_pci_driver.driver, NULL); 472 466 if (!dev) 473 467 return NULL; 474 468
+1 -6
drivers/pci/probe.c
··· 64 64 return &r->res; 65 65 } 66 66 67 - static int find_anything(struct device *dev, const void *data) 68 - { 69 - return 1; 70 - } 71 - 72 67 /* 73 68 * Some device drivers need know if PCI is initiated. 74 69 * Basically, we think PCI is not initiated when there ··· 74 79 struct device *dev; 75 80 int no_devices; 76 81 77 - dev = bus_find_device(&pci_bus_type, NULL, NULL, find_anything); 82 + dev = bus_find_next_device(&pci_bus_type, NULL); 78 83 no_devices = (dev == NULL); 79 84 put_device(dev); 80 85 return no_devices;
+1 -7
drivers/s390/cio/ccwgroup.c
··· 581 581 } 582 582 EXPORT_SYMBOL(ccwgroup_driver_register); 583 583 584 - static int __ccwgroup_match_all(struct device *dev, const void *data) 585 - { 586 - return 1; 587 - } 588 - 589 584 /** 590 585 * ccwgroup_driver_unregister() - deregister a ccw group driver 591 586 * @cdriver: driver to be deregistered ··· 592 597 struct device *dev; 593 598 594 599 /* We don't want ccwgroup devices to live longer than their driver. */ 595 - while ((dev = driver_find_device(&cdriver->driver, NULL, NULL, 596 - __ccwgroup_match_all))) { 600 + while ((dev = driver_find_next_device(&cdriver->driver, NULL))) { 597 601 struct ccwgroup_device *gdev = to_ccwgroupdev(dev); 598 602 599 603 ccwgroup_ungroup(gdev);
+2 -7
drivers/scsi/scsi_proc.c
··· 372 372 return err; 373 373 } 374 374 375 - static int always_match(struct device *dev, const void *data) 376 - { 377 - return 1; 378 - } 379 - 380 375 static inline struct device *next_scsi_device(struct device *start) 381 376 { 382 - struct device *next = bus_find_device(&scsi_bus_type, start, NULL, 383 - always_match); 377 + struct device *next = bus_find_next_device(&scsi_bus_type, start); 378 + 384 379 put_device(start); 385 380 return next; 386 381 }
+17
include/linux/device.h
··· 169 169 int device_match_fwnode(struct device *dev, const void *fwnode); 170 170 int device_match_devt(struct device *dev, const void *pdevt); 171 171 int device_match_acpi_dev(struct device *dev, const void *adev); 172 + int device_match_any(struct device *dev, const void *unused); 172 173 173 174 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, 174 175 int (*fn)(struct device *dev, void *data)); ··· 224 223 dev_t devt) 225 224 { 226 225 return bus_find_device(bus, NULL, &devt, device_match_devt); 226 + } 227 + 228 + /** 229 + * bus_find_next_device - Find the next device after a given device in a 230 + * given bus. 231 + */ 232 + static inline struct device * 233 + bus_find_next_device(struct bus_type *bus,struct device *cur) 234 + { 235 + return bus_find_device(bus, cur, NULL, device_match_any); 227 236 } 228 237 229 238 #ifdef CONFIG_ACPI ··· 474 463 dev_t devt) 475 464 { 476 465 return driver_find_device(drv, NULL, &devt, device_match_devt); 466 + } 467 + 468 + static inline struct device *driver_find_next_device(struct device_driver *drv, 469 + struct device *start) 470 + { 471 + return driver_find_device(drv, start, NULL, device_match_any); 477 472 } 478 473 479 474 #ifdef CONFIG_ACPI