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

bus_find_device: Unify the match callback with class_find_device

There is an arbitrary difference between the prototypes of
bus_find_device() and class_find_device() preventing their callers
from passing the same pair of data and match() arguments to both of
them, which is the const qualifier used in the prototype of
class_find_device(). If that qualifier is also used in the
bus_find_device() prototype, it will be possible to pass the same
match() callback function to both bus_find_device() and
class_find_device(), which will allow some optimizations to be made in
order to avoid code duplication going forward. Also with that, constify
the "data" parameter as it is passed as a const to the match function.

For this reason, change the prototype of bus_find_device() to match
the prototype of class_find_device() and adjust its callers to use the
const qualifier in accordance with the new prototype of it.

Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Andreas Noever <andreas.noever@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Corey Minyard <minyard@acm.org>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: David Kershner <david.kershner@unisys.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: David Airlie <airlied@linux.ie>
Cc: Felipe Balbi <balbi@kernel.org>
Cc: Frank Rowand <frowand.list@gmail.com>
Cc: Grygorii Strashko <grygorii.strashko@ti.com>
Cc: Harald Freudenberger <freude@linux.ibm.com>
Cc: Hartmut Knaack <knaack.h@gmx.de>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: Len Brown <lenb@kernel.org>
Cc: Mark Brown <broonie@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michael Jamet <michael.jamet@intel.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Peter Oberparleiter <oberpar@linux.ibm.com>
Cc: Sebastian Ott <sebott@linux.ibm.com>
Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Yehezkel Bernat <YehezkelShB@gmail.com>
Cc: rafael@kernel.org
Acked-by: Corey Minyard <minyard@acm.org>
Acked-by: David Kershner <david.kershner@unisys.com>
Acked-by: Mark Brown <broonie@kernel.org>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Acked-by: Wolfram Sang <wsa@the-dreams.de> # for the I2C parts
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Suzuki K Poulose and committed by
Greg Kroah-Hartman
418e3ea1 e6374f6b

+67 -68
+2 -2
arch/powerpc/platforms/pseries/ibmebus.c
··· 147 147 .unmap_page = ibmebus_unmap_page, 148 148 }; 149 149 150 - static int ibmebus_match_path(struct device *dev, void *data) 150 + static int ibmebus_match_path(struct device *dev, const void *data) 151 151 { 152 152 struct device_node *dn = to_platform_device(dev)->dev.of_node; 153 153 return (of_find_node_by_path(data) == dn); 154 154 } 155 155 156 - static int ibmebus_match_node(struct device *dev, void *data) 156 + static int ibmebus_match_node(struct device *dev, const void *data) 157 157 { 158 158 return to_platform_device(dev)->dev.of_node == data; 159 159 }
+2 -2
drivers/acpi/acpi_lpss.c
··· 511 511 const char *uid; 512 512 }; 513 513 514 - static int match_hid_uid(struct device *dev, void *data) 514 + static int match_hid_uid(struct device *dev, const void *data) 515 515 { 516 516 struct acpi_device *adev = ACPI_COMPANION(dev); 517 - struct hid_uid *id = data; 517 + const struct hid_uid *id = data; 518 518 519 519 if (!adev) 520 520 return 0;
+1 -1
drivers/acpi/sleep.c
··· 454 454 return error; 455 455 } 456 456 457 - static int find_powerf_dev(struct device *dev, void *data) 457 + static int find_powerf_dev(struct device *dev, const void *data) 458 458 { 459 459 struct acpi_device *device = to_acpi_device(dev); 460 460 const char *hid = acpi_device_hid(device);
+2 -2
drivers/acpi/utils.c
··· 730 730 s64 hrv; 731 731 }; 732 732 733 - static int acpi_dev_match_cb(struct device *dev, void *data) 733 + static int acpi_dev_match_cb(struct device *dev, const void *data) 734 734 { 735 735 struct acpi_device *adev = to_acpi_device(dev); 736 - struct acpi_dev_match_info *match = data; 736 + const struct acpi_dev_match_info *match = data; 737 737 unsigned long long hrv; 738 738 acpi_status status; 739 739
+3 -3
drivers/base/bus.c
··· 323 323 * return to the caller and not iterate over any more devices. 324 324 */ 325 325 struct device *bus_find_device(struct bus_type *bus, 326 - struct device *start, void *data, 327 - int (*match)(struct device *dev, void *data)) 326 + struct device *start, const void *data, 327 + int (*match)(struct device *dev, const void *data)) 328 328 { 329 329 struct klist_iter i; 330 330 struct device *dev; ··· 342 342 } 343 343 EXPORT_SYMBOL_GPL(bus_find_device); 344 344 345 - static int match_name(struct device *dev, void *data) 345 + static int match_name(struct device *dev, const void *data) 346 346 { 347 347 const char *name = data; 348 348
+1 -1
drivers/base/devcon.c
··· 107 107 NULL, 108 108 }; 109 109 110 - static int device_fwnode_match(struct device *dev, void *fwnode) 110 + static int device_fwnode_match(struct device *dev, const void *fwnode) 111 111 { 112 112 return dev_fwnode(dev) == fwnode; 113 113 }
+1 -1
drivers/char/ipmi/ipmi_si_platform.c
··· 426 426 return ipmi_si_remove_by_dev(&pdev->dev); 427 427 } 428 428 429 - static int pdev_match_name(struct device *dev, void *data) 429 + static int pdev_match_name(struct device *dev, const void *data) 430 430 { 431 431 struct platform_device *pdev = to_platform_device(dev); 432 432 const char *name = data;
+2 -2
drivers/firmware/efi/dev-path-parser.c
··· 17 17 char uid[11]; /* UINT_MAX + null byte */ 18 18 }; 19 19 20 - static int __init match_acpi_dev(struct device *dev, void *data) 20 + static int __init match_acpi_dev(struct device *dev, const void *data) 21 21 { 22 - struct acpi_hid_uid hid_uid = *(struct acpi_hid_uid *)data; 22 + struct acpi_hid_uid hid_uid = *(const struct acpi_hid_uid *)data; 23 23 struct acpi_device *adev = to_acpi_device(dev); 24 24 25 25 if (acpi_match_device_ids(adev, hid_uid.hid))
+1 -1
drivers/gpu/drm/drm_mipi_dsi.c
··· 93 93 .pm = &mipi_dsi_device_pm_ops, 94 94 }; 95 95 96 - static int of_device_match(struct device *dev, void *data) 96 + static int of_device_match(struct device *dev, const void *data) 97 97 { 98 98 return dev->of_node == data; 99 99 }
+3 -3
drivers/hwtracing/coresight/coresight.c
··· 498 498 return csdev; 499 499 } 500 500 501 - static int coresight_enabled_sink(struct device *dev, void *data) 501 + static int coresight_enabled_sink(struct device *dev, const void *data) 502 502 { 503 - bool *reset = data; 503 + const bool *reset = data; 504 504 struct coresight_device *csdev = to_coresight_device(dev); 505 505 506 506 if ((csdev->type == CORESIGHT_DEV_TYPE_SINK || ··· 544 544 return dev ? to_coresight_device(dev) : NULL; 545 545 } 546 546 547 - static int coresight_sink_by_id(struct device *dev, void *data) 547 + static int coresight_sink_by_id(struct device *dev, const void *data) 548 548 { 549 549 struct coresight_device *csdev = to_coresight_device(dev); 550 550 unsigned long hash;
+1 -1
drivers/hwtracing/coresight/of_coresight.c
··· 18 18 #include <asm/smp_plat.h> 19 19 20 20 21 - static int of_dev_node_match(struct device *dev, void *data) 21 + static int of_dev_node_match(struct device *dev, const void *data) 22 22 { 23 23 return dev->of_node == data; 24 24 }
+2 -3
drivers/hwtracing/intel_th/core.c
··· 789 789 return 0; 790 790 } 791 791 792 - static int match_devt(struct device *dev, void *data) 792 + static int match_devt(struct device *dev, const void *data) 793 793 { 794 - dev_t devt = (dev_t)(unsigned long)data; 795 - 794 + dev_t devt = (dev_t)(unsigned long)(void *)data; 796 795 return dev->devt == devt; 797 796 } 798 797
+2 -2
drivers/i2c/i2c-core-acpi.c
··· 318 318 } 319 319 EXPORT_SYMBOL_GPL(i2c_acpi_find_bus_speed); 320 320 321 - static int i2c_acpi_find_match_adapter(struct device *dev, void *data) 321 + static int i2c_acpi_find_match_adapter(struct device *dev, const void *data) 322 322 { 323 323 struct i2c_adapter *adapter = i2c_verify_adapter(dev); 324 324 ··· 328 328 return ACPI_HANDLE(dev) == (acpi_handle)data; 329 329 } 330 330 331 - static int i2c_acpi_find_match_device(struct device *dev, void *data) 331 + static int i2c_acpi_find_match_device(struct device *dev, const void *data) 332 332 { 333 333 return ACPI_COMPANION(dev) == data; 334 334 }
+2 -2
drivers/i2c/i2c-core-of.c
··· 112 112 of_node_put(bus); 113 113 } 114 114 115 - static int of_dev_node_match(struct device *dev, void *data) 115 + static int of_dev_node_match(struct device *dev, const void *data) 116 116 { 117 117 return dev->of_node == data; 118 118 } 119 119 120 - static int of_dev_or_parent_node_match(struct device *dev, void *data) 120 + static int of_dev_or_parent_node_match(struct device *dev, const void *data) 121 121 { 122 122 if (dev->of_node == data) 123 123 return 1;
+1 -1
drivers/iio/inkern.c
··· 93 93 94 94 #ifdef CONFIG_OF 95 95 96 - static int iio_dev_node_match(struct device *dev, void *data) 96 + static int iio_dev_node_match(struct device *dev, const void *data) 97 97 { 98 98 return dev->of_node == data && dev->type == &iio_device_type; 99 99 }
+1 -1
drivers/infiniband/hw/hns/hns_roce_hw_v1.c
··· 4497 4497 }; 4498 4498 MODULE_DEVICE_TABLE(acpi, hns_roce_acpi_match); 4499 4499 4500 - static int hns_roce_node_match(struct device *dev, void *fwnode) 4500 + static int hns_roce_node_match(struct device *dev, const void *fwnode) 4501 4501 { 4502 4502 return dev->fwnode == fwnode; 4503 4503 }
+1 -1
drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
··· 754 754 return (void *)misc_op; 755 755 } 756 756 757 - static int hns_dsaf_dev_match(struct device *dev, void *fwnode) 757 + static int hns_dsaf_dev_match(struct device *dev, const void *fwnode) 758 758 { 759 759 return dev->fwnode == fwnode; 760 760 }
+2 -2
drivers/net/ethernet/ti/cpsw-phy-sel.c
··· 151 151 } 152 152 153 153 static struct platform_driver cpsw_phy_sel_driver; 154 - static int match(struct device *dev, void *data) 154 + static int match(struct device *dev, const void *data) 155 155 { 156 - struct device_node *node = (struct device_node *)data; 156 + const struct device_node *node = (const struct device_node *)data; 157 157 return dev->of_node == node && 158 158 dev->driver == &cpsw_phy_sel_driver.driver; 159 159 }
+1 -1
drivers/net/ethernet/ti/davinci_emac.c
··· 1371 1371 return -EOPNOTSUPP; 1372 1372 } 1373 1373 1374 - static int match_first_device(struct device *dev, void *data) 1374 + static int match_first_device(struct device *dev, const void *data) 1375 1375 { 1376 1376 if (dev->parent && dev->parent->of_node) 1377 1377 return of_device_is_compatible(dev->parent->of_node,
+2 -2
drivers/net/ethernet/toshiba/tc35815.c
··· 694 694 * should provide a "tc35815-mac" device with a MAC address in its 695 695 * platform_data. 696 696 */ 697 - static int tc35815_mac_match(struct device *dev, void *data) 697 + static int tc35815_mac_match(struct device *dev, const void *data) 698 698 { 699 699 struct platform_device *plat_dev = to_platform_device(dev); 700 - struct pci_dev *pci_dev = data; 700 + const struct pci_dev *pci_dev = data; 701 701 unsigned int id = pci_dev->irq; 702 702 return !strcmp(plat_dev->name, "tc35815-mac") && plat_dev->id == id; 703 703 }
+1 -1
drivers/nvmem/core.c
··· 76 76 .name = "nvmem", 77 77 }; 78 78 79 - static int of_nvmem_match(struct device *dev, void *nvmem_np) 79 + static int of_nvmem_match(struct device *dev, const void *nvmem_np) 80 80 { 81 81 return dev->of_node == nvmem_np; 82 82 }
+1 -1
drivers/of/of_mdio.c
··· 282 282 EXPORT_SYMBOL(of_mdiobus_register); 283 283 284 284 /* Helper function for of_phy_find_device */ 285 - static int of_phy_match(struct device *dev, void *phy_np) 285 + static int of_phy_match(struct device *dev, const void *phy_np) 286 286 { 287 287 return dev->of_node == phy_np; 288 288 }
+1 -1
drivers/of/platform.c
··· 37 37 {} /* Empty terminated list */ 38 38 }; 39 39 40 - static int of_dev_node_match(struct device *dev, void *data) 40 + static int of_dev_node_match(struct device *dev, const void *data) 41 41 { 42 42 return dev->of_node == data; 43 43 }
+1 -1
drivers/pci/probe.c
··· 64 64 return &r->res; 65 65 } 66 66 67 - static int find_anything(struct device *dev, void *data) 67 + static int find_anything(struct device *dev, const void *data) 68 68 { 69 69 return 1; 70 70 }
+2 -2
drivers/pci/search.c
··· 236 236 } 237 237 EXPORT_SYMBOL(pci_get_domain_bus_and_slot); 238 238 239 - static int match_pci_dev_by_id(struct device *dev, void *data) 239 + static int match_pci_dev_by_id(struct device *dev, const void *data) 240 240 { 241 241 struct pci_dev *pdev = to_pci_dev(dev); 242 - struct pci_device_id *id = data; 242 + const struct pci_device_id *id = data; 243 243 244 244 if (pci_match_one_device(id, pdev)) 245 245 return 1;
+2 -2
drivers/s390/cio/css.c
··· 434 434 } 435 435 436 436 static int 437 - check_subchannel(struct device * dev, void * data) 437 + check_subchannel(struct device *dev, const void *data) 438 438 { 439 439 struct subchannel *sch; 440 - struct subchannel_id *schid = data; 440 + struct subchannel_id *schid = (void *)data; 441 441 442 442 sch = to_subchannel(dev); 443 443 return schid_equal(&sch->schid, schid);
+2 -2
drivers/s390/cio/device.c
··· 642 642 return device_add(dev); 643 643 } 644 644 645 - static int match_dev_id(struct device *dev, void *data) 645 + static int match_dev_id(struct device *dev, const void *data) 646 646 { 647 647 struct ccw_device *cdev = to_ccwdev(dev); 648 - struct ccw_dev_id *dev_id = data; 648 + struct ccw_dev_id *dev_id = (void *)data; 649 649 650 650 return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id); 651 651 }
+2 -2
drivers/s390/cio/scm.c
··· 174 174 kobject_uevent(&scmdev->dev.kobj, KOBJ_CHANGE); 175 175 } 176 176 177 - static int check_address(struct device *dev, void *data) 177 + static int check_address(struct device *dev, const void *data) 178 178 { 179 179 struct scm_device *scmdev = to_scm_dev(dev); 180 - struct sale *sale = data; 180 + const struct sale *sale = data; 181 181 182 182 return scmdev->address == sale->sa; 183 183 }
+4 -4
drivers/s390/crypto/ap_bus.c
··· 1356 1356 * Helper function to be used with bus_find_dev 1357 1357 * matches for the card device with the given id 1358 1358 */ 1359 - static int __match_card_device_with_id(struct device *dev, void *data) 1359 + static int __match_card_device_with_id(struct device *dev, const void *data) 1360 1360 { 1361 - return is_card_dev(dev) && to_ap_card(dev)->id == (int)(long) data; 1361 + return is_card_dev(dev) && to_ap_card(dev)->id == (int)(long)(void *) data; 1362 1362 } 1363 1363 1364 1364 /* 1365 1365 * Helper function to be used with bus_find_dev 1366 1366 * matches for the queue device with a given qid 1367 1367 */ 1368 - static int __match_queue_device_with_qid(struct device *dev, void *data) 1368 + static int __match_queue_device_with_qid(struct device *dev, const void *data) 1369 1369 { 1370 1370 return is_queue_dev(dev) && to_ap_queue(dev)->qid == (int)(long) data; 1371 1371 } ··· 1374 1374 * Helper function to be used with bus_find_dev 1375 1375 * matches any queue device with given queue id 1376 1376 */ 1377 - static int __match_queue_device_with_queue_id(struct device *dev, void *data) 1377 + static int __match_queue_device_with_queue_id(struct device *dev, const void *data) 1378 1378 { 1379 1379 return is_queue_dev(dev) 1380 1380 && AP_QID_QUEUE(to_ap_queue(dev)->qid) == (int)(long) data;
+1 -1
drivers/scsi/scsi_proc.c
··· 372 372 return err; 373 373 } 374 374 375 - static int always_match(struct device *dev, void *data) 375 + static int always_match(struct device *dev, const void *data) 376 376 { 377 377 return 1; 378 378 }
+2 -2
drivers/spi/spi.c
··· 3538 3538 /*-------------------------------------------------------------------------*/ 3539 3539 3540 3540 #if IS_ENABLED(CONFIG_OF) 3541 - static int __spi_of_device_match(struct device *dev, void *data) 3541 + static int __spi_of_device_match(struct device *dev, const void *data) 3542 3542 { 3543 3543 return dev->of_node == data; 3544 3544 } ··· 3639 3639 return ACPI_COMPANION(dev->parent) == data; 3640 3640 } 3641 3641 3642 - static int spi_acpi_device_match(struct device *dev, void *data) 3642 + static int spi_acpi_device_match(struct device *dev, const void *data) 3643 3643 { 3644 3644 return ACPI_COMPANION(dev) == data; 3645 3645 }
+2 -2
drivers/thunderbolt/switch.c
··· 1946 1946 u64 route; 1947 1947 }; 1948 1948 1949 - static int tb_switch_match(struct device *dev, void *data) 1949 + static int tb_switch_match(struct device *dev, const void *data) 1950 1950 { 1951 1951 struct tb_switch *sw = tb_to_switch(dev); 1952 - struct tb_sw_lookup *lookup = data; 1952 + const struct tb_sw_lookup *lookup = data; 1953 1953 1954 1954 if (!sw) 1955 1955 return 0;
+2 -2
drivers/usb/core/devio.c
··· 947 947 return ret; 948 948 } 949 949 950 - static int match_devt(struct device *dev, void *data) 950 + static int match_devt(struct device *dev, const void *data) 951 951 { 952 - return dev->devt == (dev_t) (unsigned long) data; 952 + return dev->devt == (dev_t)(unsigned long)(void *)data; 953 953 } 954 954 955 955 static struct usb_device *usbdev_lookup_by_devt(dev_t devt)
+2 -2
drivers/usb/core/usb.c
··· 325 325 struct device_driver *drv; 326 326 }; 327 327 328 - static int __find_interface(struct device *dev, void *data) 328 + static int __find_interface(struct device *dev, const void *data) 329 329 { 330 - struct find_interface_arg *arg = data; 330 + const struct find_interface_arg *arg = data; 331 331 struct usb_interface *intf; 332 332 333 333 if (!is_usb_interface(dev))
+2 -2
drivers/usb/phy/phy-am335x-control.c
··· 118 118 MODULE_DEVICE_TABLE(of, omap_control_usb_id_table); 119 119 120 120 static struct platform_driver am335x_control_driver; 121 - static int match(struct device *dev, void *data) 121 + static int match(struct device *dev, const void *data) 122 122 { 123 - struct device_node *node = (struct device_node *)data; 123 + const struct device_node *node = (const struct device_node *)data; 124 124 return dev->of_node == node && 125 125 dev->driver == &am335x_control_driver.driver; 126 126 }
+2 -2
drivers/usb/phy/phy-isp1301.c
··· 142 142 143 143 module_i2c_driver(isp1301_driver); 144 144 145 - static int match(struct device *dev, void *data) 145 + static int match(struct device *dev, const void *data) 146 146 { 147 - struct device_node *node = (struct device_node *)data; 147 + const struct device_node *node = (const struct device_node *)data; 148 148 return (dev->of_node == node) && 149 149 (dev->driver == &isp1301_driver.driver); 150 150 }
+2 -2
drivers/visorbus/visorbus_main.c
··· 171 171 u32 dev_no; 172 172 }; 173 173 174 - static int match_visorbus_dev_by_id(struct device *dev, void *data) 174 + static int match_visorbus_dev_by_id(struct device *dev, const void *data) 175 175 { 176 176 struct visor_device *vdev = to_visor_device(dev); 177 - struct visor_busdev *id = data; 177 + const struct visor_busdev *id = data; 178 178 179 179 if (vdev->chipset_bus_no == id->bus_no && 180 180 vdev->chipset_dev_no == id->dev_no)
+2 -2
include/linux/device.h
··· 166 166 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, 167 167 int (*fn)(struct device *dev, void *data)); 168 168 struct device *bus_find_device(struct bus_type *bus, struct device *start, 169 - void *data, 170 - int (*match)(struct device *dev, void *data)); 169 + const void *data, 170 + int (*match)(struct device *dev, const void *data)); 171 171 struct device *bus_find_device_by_name(struct bus_type *bus, 172 172 struct device *start, 173 173 const char *name);
+1 -1
sound/soc/rockchip/rk3399_gru_sound.c
··· 405 405 }, 406 406 }; 407 407 408 - static int of_dev_node_match(struct device *dev, void *data) 408 + static int of_dev_node_match(struct device *dev, const void *data) 409 409 { 410 410 return dev->of_node == data; 411 411 }