Generic Device Lookup Helpers Persistent tag for others to pull this branch from Based on patch series from Suzuki K Poulose <suzuki.poulose@arm.com> with Subject: [PATCH v3 0/7] drivers: Add generic device lookup helpers Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> * tag 'generic_lookup_helpers': platform: Add platform_find_device_by_driver() helper drivers: Add generic helper to match any device drivers: Introduce device lookup variants by ACPI_COMPANION device drivers: Introduce device lookup variants by device type drivers: Introduce device lookup variants by fwnode drivers: Introduce device lookup variants by of_node drivers: Introduce device lookup variants by name
Unified · Split
| @@ -134,22 +134,13 @@ static inline void gizmo_writel(struct tegra_ahb *ahb, u32 value, u32 offset) · 133 unmodified lines | |||
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | #ifdef CONFIG_TEGRA_IOMMU_SMMU | 136 | #ifdef CONFIG_TEGRA_IOMMU_SMMU |
| 137 | static int tegra_ahb_match_by_smmu(struct device *dev, const void *data) | ||
| 138 | { | ||
| 139 | struct tegra_ahb *ahb = dev_get_drvdata(dev); | ||
| 140 | const struct device_node *dn = data; | ||
| 141 | |||
| 142 | return (ahb->dev->of_node == dn) ? 1 : 0; | ||
| 143 | } | ||
| 144 | |||
| 145 | int tegra_ahb_enable_smmu(struct device_node *dn) | 137 | int tegra_ahb_enable_smmu(struct device_node *dn) |
| 146 | { | 138 | { |
| 147 | struct device *dev; | 139 | struct device *dev; |
| 148 | u32 val; | 140 | u32 val; |
| 149 | struct tegra_ahb *ahb; | 141 | struct tegra_ahb *ahb; |
| 150 | 142 | ||
| 151 | dev = driver_find_device(&tegra_ahb_driver.driver, NULL, dn, | 143 | dev = driver_find_device_by_of_node(&tegra_ahb_driver.driver, dn); |
| 152 | tegra_ahb_match_by_smmu); | ||
| 153 | if (!dev) | 144 | if (!dev) |
| 154 | return -EPROBE_DEFER; | 145 | return -EPROBE_DEFER; |
| 155 | ahb = dev_get_drvdata(dev); | 146 | ahb = dev_get_drvdata(dev); |
| @@ -342,30 +342,6 @@ struct device *bus_find_device(struct bus_type *bus, · 341 unmodified lines | |||
| 342 | } | 342 | } |
| 343 | EXPORT_SYMBOL_GPL(bus_find_device); | 343 | EXPORT_SYMBOL_GPL(bus_find_device); |
| 344 | 344 | ||
| 345 | static int match_name(struct device *dev, const void *data) | ||
| 346 | { | ||
| 347 | const char *name = data; | ||
| 348 | |||
| 349 | return sysfs_streq(name, dev_name(dev)); | ||
| 350 | } | ||
| 351 | |||
| 352 | /** | ||
| 353 | * bus_find_device_by_name - device iterator for locating a particular device of a specific name | ||
| 354 | * @bus: bus type | ||
| 355 | * @start: Device to begin with | ||
| 356 | * @name: name of the device to match | ||
| 357 | * | ||
| 358 | * This is similar to the bus_find_device() function above, but it handles | ||
| 359 | * searching by a name automatically, no need to write another strcmp matching | ||
| 360 | * function. | ||
| 361 | */ | ||
| 362 | struct device *bus_find_device_by_name(struct bus_type *bus, | ||
| 363 | struct device *start, const char *name) | ||
| 364 | { | ||
| 365 | return bus_find_device(bus, start, (void *)name, match_name); | ||
| 366 | } | ||
| 367 | EXPORT_SYMBOL_GPL(bus_find_device_by_name); | ||
| 368 | |||
| 369 | /** | 345 | /** |
| 370 | * subsys_find_device_by_id - find a device with a specific enumeration number | 346 | * subsys_find_device_by_id - find a device with a specific enumeration number |
| 371 | * @subsys: subsystem | 347 | * @subsys: subsystem |
| @@ -2867,13 +2867,6 @@ struct device *device_create_with_groups(struct class *class, · 2866 unmodified lines | |||
| 2867 | } | 2867 | } |
| 2868 | EXPORT_SYMBOL_GPL(device_create_with_groups); | 2868 | EXPORT_SYMBOL_GPL(device_create_with_groups); |
| 2869 | 2869 | ||
| 2870 | static int __match_devt(struct device *dev, const void *data) | ||
| 2871 | { | ||
| 2872 | const dev_t *devt = data; | ||
| 2873 | |||
| 2874 | return dev->devt == *devt; | ||
| 2875 | } | ||
| 2876 | |||
| 2877 | /** | 2870 | /** |
| 2878 | * device_destroy - removes a device that was created with device_create() | 2871 | * device_destroy - removes a device that was created with device_create() |
| 2879 | * @class: pointer to the struct class that this device was registered with | 2872 | * @class: pointer to the struct class that this device was registered with |
| @@ -2886,7 +2879,7 @@ void device_destroy(struct class *class, dev_t devt) · 6 unmodified lines | |||
| 2886 | { | 2879 | { |
| 2887 | struct device *dev; | 2880 | struct device *dev; |
| 2888 | 2881 | ||
| 2889 | dev = class_find_device(class, NULL, &devt, __match_devt); | 2882 | dev = class_find_device_by_devt(class, devt); |
| 2890 | if (dev) { | 2883 | if (dev) { |
| 2891 | put_device(dev); | 2884 | put_device(dev); |
| 2892 | device_unregister(dev); | 2885 | device_unregister(dev); |
| @@ -3357,8 +3350,38 @@ void device_set_of_node_from_dev(struct device *dev, const struct device *dev2) · 464 unmodified lines | |||
| 3357 | } | 3350 | } |
| 3358 | EXPORT_SYMBOL_GPL(device_set_of_node_from_dev); | 3351 | EXPORT_SYMBOL_GPL(device_set_of_node_from_dev); |
| 3359 | 3352 | ||
| 3353 | int device_match_name(struct device *dev, const void *name) | ||
| 3354 | { | ||
| 3355 | return sysfs_streq(dev_name(dev), name); | ||
| 3356 | } | ||
| 3357 | EXPORT_SYMBOL_GPL(device_match_name); | ||
| 3358 | |||
| 3360 | int device_match_of_node(struct device *dev, const void *np) | 3359 | int device_match_of_node(struct device *dev, const void *np) |
| 3361 | { | 3360 | { |
| 3362 | return dev->of_node == np; | 3361 | return dev->of_node == np; |
| 3363 | } | 3362 | } |
| 3364 | EXPORT_SYMBOL_GPL(device_match_of_node); | 3363 | EXPORT_SYMBOL_GPL(device_match_of_node); |
| 3364 | |||
| 3365 | int device_match_fwnode(struct device *dev, const void *fwnode) | ||
| 3366 | { | ||
| 3367 | return dev_fwnode(dev) == fwnode; | ||
| 3368 | } | ||
| 3369 | EXPORT_SYMBOL_GPL(device_match_fwnode); | ||
| 3370 | |||
| 3371 | int device_match_devt(struct device *dev, const void *pdevt) | ||
| 3372 | { | ||
| 3373 | return dev->devt == *(dev_t *)pdevt; | ||
| 3374 | } | ||
| 3375 | EXPORT_SYMBOL_GPL(device_match_devt); | ||
| 3376 | |||
| 3377 | int device_match_acpi_dev(struct device *dev, const void *adev) | ||
| 3378 | { | ||
| 3379 | return ACPI_COMPANION(dev) == adev; | ||
| 3380 | } | ||
| 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); | ||
| @@ -133,19 +133,13 @@ static struct bus_type *generic_match_buses[] = { · 132 unmodified lines | |||
| 133 | NULL, | 133 | NULL, |
| 134 | }; | 134 | }; |
| 135 | 135 | ||
| 136 | static int device_fwnode_match(struct device *dev, const void *fwnode) | ||
| 137 | { | ||
| 138 | return dev_fwnode(dev) == fwnode; | ||
| 139 | } | ||
| 140 | |||
| 141 | static void *device_connection_fwnode_match(struct device_connection *con) | 136 | static void *device_connection_fwnode_match(struct device_connection *con) |
| 142 | { | 137 | { |
| 143 | struct bus_type *bus; | 138 | struct bus_type *bus; |
| 144 | struct device *dev; | 139 | struct device *dev; |
| 145 | 140 | ||
| 146 | for (bus = generic_match_buses[0]; bus; bus++) { | 141 | for (bus = generic_match_buses[0]; bus; bus++) { |
| 147 | dev = bus_find_device(bus, NULL, (void *)con->fwnode, | 142 | dev = bus_find_device_by_fwnode(bus, con->fwnode); |
| 148 | device_fwnode_match); | ||
| 149 | if (dev && !strncmp(dev_name(dev), con->id, strlen(con->id))) | 143 | if (dev && !strncmp(dev_name(dev), con->id, strlen(con->id))) |
| 150 | return dev; | 144 | return dev; |
| 151 | 145 | ||
| @@ -1197,6 +1197,20 @@ struct bus_type platform_bus_type = { · 1196 unmodified lines | |||
| 1197 | }; | 1197 | }; |
| 1198 | EXPORT_SYMBOL_GPL(platform_bus_type); | 1198 | EXPORT_SYMBOL_GPL(platform_bus_type); |
| 1199 | 1199 | ||
| 1200 | /** | ||
| 1201 | * platform_find_device_by_driver - Find a platform device with a given | ||
| 1202 | * driver. | ||
| 1203 | * @start: The device to start the search from. | ||
| 1204 | * @drv: The device driver to look for. | ||
| 1205 | */ | ||
| 1206 | struct device *platform_find_device_by_driver(struct device *start, | ||
| 1207 | const struct device_driver *drv) | ||
| 1208 | { | ||
| 1209 | return bus_find_device(&platform_bus_type, start, drv, | ||
| 1210 | (void *)platform_match); | ||
| 1211 | } | ||
| 1212 | EXPORT_SYMBOL_GPL(platform_find_device_by_driver); | ||
| 1213 | |||
| 1200 | int __init platform_bus_init(void) | 1214 | int __init platform_bus_init(void) |
| 1201 | { | 1215 | { |
| 1202 | int error; | 1216 | int error; |
| @@ -19,11 +19,6 @@ static struct class *fpga_bridge_class; · 18 unmodified lines | |||
| 19 | /* Lock for adding/removing bridges to linked lists*/ | 19 | /* Lock for adding/removing bridges to linked lists*/ |
| 20 | static spinlock_t bridge_list_lock; | 20 | static spinlock_t bridge_list_lock; |
| 21 | 21 | ||
| 22 | static int fpga_bridge_of_node_match(struct device *dev, const void *data) | ||
| 23 | { | ||
| 24 | return dev->of_node == data; | ||
| 25 | } | ||
| 26 | |||
| 27 | /** | 22 | /** |
| 28 | * fpga_bridge_enable - Enable transactions on the bridge | 23 | * fpga_bridge_enable - Enable transactions on the bridge |
| 29 | * | 24 | * |
| @@ -104,8 +99,7 @@ struct fpga_bridge *of_fpga_bridge_get(struct device_node *np, · 74 unmodified lines | |||
| 104 | { | 99 | { |
| 105 | struct device *dev; | 100 | struct device *dev; |
| 106 | 101 | ||
| 107 | dev = class_find_device(fpga_bridge_class, NULL, np, | 102 | dev = class_find_device_by_of_node(fpga_bridge_class, np); |
| 108 | fpga_bridge_of_node_match); | ||
| 109 | if (!dev) | 103 | if (!dev) |
| 110 | return ERR_PTR(-ENODEV); | 104 | return ERR_PTR(-ENODEV); |
| 111 | 105 | ||
| @@ -482,11 +482,6 @@ struct fpga_manager *fpga_mgr_get(struct device *dev) · 481 unmodified lines | |||
| 482 | } | 482 | } |
| 483 | EXPORT_SYMBOL_GPL(fpga_mgr_get); | 483 | EXPORT_SYMBOL_GPL(fpga_mgr_get); |
| 484 | 484 | ||
| 485 | static int fpga_mgr_of_node_match(struct device *dev, const void *data) | ||
| 486 | { | ||
| 487 | return dev->of_node == data; | ||
| 488 | } | ||
| 489 | |||
| 490 | /** | 485 | /** |
| 491 | * of_fpga_mgr_get - Given a device node, get a reference to a fpga mgr. | 486 | * of_fpga_mgr_get - Given a device node, get a reference to a fpga mgr. |
| 492 | * | 487 | * |
| @@ -498,8 +493,7 @@ struct fpga_manager *of_fpga_mgr_get(struct device_node *node) · 5 unmodified lines | |||
| 498 | { | 493 | { |
| 499 | struct device *dev; | 494 | struct device *dev; |
| 500 | 495 | ||
| 501 | dev = class_find_device(fpga_mgr_class, NULL, node, | 496 | dev = class_find_device_by_of_node(fpga_mgr_class, node); |
| 502 | fpga_mgr_of_node_match); | ||
| 503 | if (!dev) | 497 | if (!dev) |
| 504 | return ERR_PTR(-ENODEV); | 498 | return ERR_PTR(-ENODEV); |
| 505 | 499 | ||
| @@ -93,11 +93,6 @@ static struct bus_type mipi_dsi_bus_type = { · 92 unmodified lines | |||
| 93 | .pm = &mipi_dsi_device_pm_ops, | 93 | .pm = &mipi_dsi_device_pm_ops, |
| 94 | }; | 94 | }; |
| 95 | 95 | ||
| 96 | static int of_device_match(struct device *dev, const void *data) | ||
| 97 | { | ||
| 98 | return dev->of_node == data; | ||
| 99 | } | ||
| 100 | |||
| 101 | /** | 96 | /** |
| 102 | * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a | 97 | * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a |
| 103 | * device tree node | 98 | * device tree node |
| @@ -110,7 +105,7 @@ struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np) · 6 unmodified lines | |||
| 110 | { | 105 | { |
| 111 | struct device *dev; | 106 | struct device *dev; |
| 112 | 107 | ||
| 113 | dev = bus_find_device(&mipi_dsi_bus_type, NULL, np, of_device_match); | 108 | dev = bus_find_device_by_of_node(&mipi_dsi_bus_type, np); |
| 114 | 109 | ||
| 115 | return dev ? to_mipi_dsi_device(dev) : NULL; | 110 | return dev ? to_mipi_dsi_device(dev) : NULL; |
| 116 | } | 111 | } |
| @@ -242,9 +242,7 @@ static struct component_match *exynos_drm_match_add(struct device *dev) · 241 unmodified lines | |||
| 242 | if (!info->driver || !(info->flags & DRM_COMPONENT_DRIVER)) | 242 | if (!info->driver || !(info->flags & DRM_COMPONENT_DRIVER)) |
| 243 | continue; | 243 | continue; |
| 244 | 244 | ||
| 245 | while ((d = bus_find_device(&platform_bus_type, p, | 245 | while ((d = platform_find_device_by_driver(p, &info->driver->driver))) { |
| 246 | &info->driver->driver, | ||
| 247 | (void *)platform_bus_type.match))) { | ||
| 248 | put_device(p); | 246 | put_device(p); |
| 249 | 247 | ||
| 250 | if (!(info->flags & DRM_FIMC_DEVICE) || | 248 | if (!(info->flags & DRM_FIMC_DEVICE) || |
| @@ -412,9 +410,8 @@ static void exynos_drm_unregister_devices(void) · 161 unmodified lines | |||
| 412 | if (!info->driver || !(info->flags & DRM_VIRTUAL_DEVICE)) | 410 | if (!info->driver || !(info->flags & DRM_VIRTUAL_DEVICE)) |
| 413 | continue; | 411 | continue; |
| 414 | 412 | ||
| 415 | while ((dev = bus_find_device(&platform_bus_type, NULL, | 413 | while ((dev = platform_find_device_by_driver(NULL, |
| 416 | &info->driver->driver, | 414 | &info->driver->driver))) { |
| 417 | (void *)platform_bus_type.match))) { | ||
| 418 | put_device(dev); | 415 | put_device(dev); |
| 419 | platform_device_unregister(to_platform_device(dev)); | 416 | platform_device_unregister(to_platform_device(dev)); |
| 420 | } | 417 | } |
| @@ -477,8 +477,7 @@ static int mcde_probe(struct platform_device *pdev) · 476 unmodified lines | |||
| 477 | struct device_driver *drv = &mcde_component_drivers[i]->driver; | 477 | struct device_driver *drv = &mcde_component_drivers[i]->driver; |
| 478 | struct device *p = NULL, *d; | 478 | struct device *p = NULL, *d; |
| 479 | 479 | ||
| 480 | while ((d = bus_find_device(&platform_bus_type, p, drv, | 480 | while ((d = platform_find_device_by_driver(p, drv))) { |
| 481 | (void *)platform_bus_type.match))) { | ||
| 482 | put_device(p); | 481 | put_device(p); |
| 483 | component_match_add(dev, &match, mcde_compare_dev, d); | 482 | component_match_add(dev, &match, mcde_compare_dev, d); |
| 484 | p = d; | 483 | p = d; |
| @@ -330,8 +330,7 @@ static struct component_match *rockchip_drm_match_add(struct device *dev) · 329 unmodified lines | |||
| 330 | struct device *p = NULL, *d; | 330 | struct device *p = NULL, *d; |
| 331 | 331 | ||
| 332 | do { | 332 | do { |
| 333 | d = bus_find_device(&platform_bus_type, p, &drv->driver, | 333 | d = platform_find_device_by_driver(p, &drv->driver); |
| 334 | (void *)platform_bus_type.match); | ||
| 335 | put_device(p); | 334 | put_device(p); |
| 336 | p = d; | 335 | p = d; |
| 337 | 336 | ||
| @@ -237,8 +237,7 @@ static void vc4_match_add_drivers(struct device *dev, · 236 unmodified lines | |||
| 237 | struct device_driver *drv = &drivers[i]->driver; | 237 | struct device_driver *drv = &drivers[i]->driver; |
| 238 | struct device *p = NULL, *d; | 238 | struct device *p = NULL, *d; |
| 239 | 239 | ||
| 240 | while ((d = bus_find_device(&platform_bus_type, p, drv, | 240 | while ((d = platform_find_device_by_driver(p, drv))) { |
| 241 | (void *)platform_bus_type.match))) { | ||
| 242 | put_device(p); | 241 | put_device(p); |
| 243 | component_match_add(dev, match, compare_dev, d); | 242 | component_match_add(dev, match, compare_dev, d); |
| 244 | p = d; | 243 | p = d; |
| @@ -37,11 +37,6 @@ static int coresight_alloc_conns(struct device *dev, · 36 unmodified lines | |||
| 37 | return 0; | 37 | return 0; |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | int coresight_device_fwnode_match(struct device *dev, const void *fwnode) | ||
| 41 | { | ||
| 42 | return dev_fwnode(dev) == fwnode; | ||
| 43 | } | ||
| 44 | |||
| 45 | static struct device * | 40 | static struct device * |
| 46 | coresight_find_device_by_fwnode(struct fwnode_handle *fwnode) | 41 | coresight_find_device_by_fwnode(struct fwnode_handle *fwnode) |
| 47 | { | 42 | { |
| @@ -51,8 +46,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode) · 3 unmodified lines | |||
| 51 | * If we have a non-configurable replicator, it will be found on the | 46 | * If we have a non-configurable replicator, it will be found on the |
| 52 | * platform bus. | 47 | * platform bus. |
| 53 | */ | 48 | */ |
| 54 | dev = bus_find_device(&platform_bus_type, NULL, | 49 | dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode); |
| 55 | fwnode, coresight_device_fwnode_match); | ||
| 56 | if (dev) | 50 | if (dev) |
| 57 | return dev; | 51 | return dev; |
| 58 | 52 | ||
| @@ -60,8 +54,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode) · 1 unmodified line | |||
| 60 | * We have a configurable component - circle through the AMBA bus | 54 | * We have a configurable component - circle through the AMBA bus |
| 61 | * looking for the device that matches the endpoint node. | 55 | * looking for the device that matches the endpoint node. |
| 62 | */ | 56 | */ |
| 63 | return bus_find_device(&amba_bustype, NULL, | 57 | return bus_find_device_by_fwnode(&amba_bustype, fwnode); |
| 64 | fwnode, coresight_device_fwnode_match); | ||
| 65 | } | 58 | } |
| 66 | 59 | ||
| 67 | #ifdef CONFIG_OF | 60 | #ifdef CONFIG_OF |
| @@ -202,6 +202,4 @@ static inline void *coresight_get_uci_data(const struct amba_id *id) · 201 unmodified lines | |||
| 202 | 202 | ||
| 203 | void coresight_release_platform_data(struct coresight_platform_data *pdata); | 203 | void coresight_release_platform_data(struct coresight_platform_data *pdata); |
| 204 | 204 | ||
| 205 | int coresight_device_fwnode_match(struct device *dev, const void *fwnode); | ||
| 206 | |||
| 207 | #endif | 205 | #endif |
| @@ -1046,9 +1046,7 @@ static void coresight_fixup_device_conns(struct coresight_device *csdev) · 1045 unmodified lines | |||
| 1046 | struct coresight_connection *conn = &csdev->pdata->conns[i]; | 1046 | struct coresight_connection *conn = &csdev->pdata->conns[i]; |
| 1047 | struct device *dev = NULL; | 1047 | struct device *dev = NULL; |
| 1048 | 1048 | ||
| 1049 | dev = bus_find_device(&coresight_bustype, NULL, | 1049 | dev = bus_find_device_by_fwnode(&coresight_bustype, conn->child_fwnode); |
| 1050 | (void *)conn->child_fwnode, | ||
| 1051 | coresight_device_fwnode_match); | ||
| 1052 | if (dev) { | 1050 | if (dev) { |
| 1053 | conn->child_dev = to_coresight_device(dev); | 1051 | conn->child_dev = to_coresight_device(dev); |
| 1054 | /* and put reference from 'bus_find_device()' */ | 1052 | /* and put reference from 'bus_find_device()' */ |
| @@ -789,12 +789,6 @@ static int intel_th_populate(struct intel_th *th) · 788 unmodified lines | |||
| 789 | return 0; | 789 | return 0; |
| 790 | } | 790 | } |
| 791 | 791 | ||
| 792 | static int match_devt(struct device *dev, const void *data) | ||
| 793 | { | ||
| 794 | dev_t devt = (dev_t)(unsigned long)(void *)data; | ||
| 795 | return dev->devt == devt; | ||
| 796 | } | ||
| 797 | |||
| 798 | static int intel_th_output_open(struct inode *inode, struct file *file) | 792 | static int intel_th_output_open(struct inode *inode, struct file *file) |
| 799 | { | 793 | { |
| 800 | const struct file_operations *fops; | 794 | const struct file_operations *fops; |
| @@ -802,9 +796,7 @@ static int intel_th_output_open(struct inode *inode, struct file *file) · 1 unmodified line | |||
| 802 | struct device *dev; | 796 | struct device *dev; |
| 803 | int err; | 797 | int err; |
| 804 | 798 | ||
| 805 | dev = bus_find_device(&intel_th_bus, NULL, | 799 | dev = bus_find_device_by_devt(&intel_th_bus, inode->i_rdev); |
| 806 | (void *)(unsigned long)inode->i_rdev, | ||
| 807 | match_devt); | ||
| 808 | if (!dev || !dev->driver) | 800 | if (!dev || !dev->driver) |
| 809 | return -ENODEV; | 801 | return -ENODEV; |
| 810 | 802 | ||
| @@ -89,13 +89,6 @@ static struct class stm_class = { · 88 unmodified lines | |||
| 89 | .dev_groups = stm_groups, | 89 | .dev_groups = stm_groups, |
| 90 | }; | 90 | }; |
| 91 | 91 | ||
| 92 | static int stm_dev_match(struct device *dev, const void *data) | ||
| 93 | { | ||
| 94 | const char *name = data; | ||
| 95 | |||
| 96 | return sysfs_streq(name, dev_name(dev)); | ||
| 97 | } | ||
| 98 | |||
| 99 | /** | 92 | /** |
| 100 | * stm_find_device() - find stm device by name | 93 | * stm_find_device() - find stm device by name |
| 101 | * @buf: character buffer containing the name | 94 | * @buf: character buffer containing the name |
| @@ -116,7 +109,7 @@ struct stm_device *stm_find_device(const char *buf) · 14 unmodified lines | |||
| 116 | if (!stm_core_up) | 109 | if (!stm_core_up) |
| 117 | return NULL; | 110 | return NULL; |
| 118 | 111 | ||
| 119 | dev = class_find_device(&stm_class, NULL, buf, stm_dev_match); | 112 | dev = class_find_device_by_name(&stm_class, buf); |
| 120 | if (!dev) | 113 | if (!dev) |
| 121 | return NULL; | 114 | return NULL; |
| 122 | 115 | ||
| @@ -457,18 +457,12 @@ static struct pci_driver amd_mp2_pci_driver = { · 456 unmodified lines | |||
| 457 | }; | 457 | }; |
| 458 | module_pci_driver(amd_mp2_pci_driver); | 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 | struct amd_mp2_dev *amd_mp2_find_device(void) | 460 | struct amd_mp2_dev *amd_mp2_find_device(void) |
| 466 | { | 461 | { |
| 467 | struct device *dev; | 462 | struct device *dev; |
| 468 | struct pci_dev *pci_dev; | 463 | struct pci_dev *pci_dev; |
| 469 | 464 | ||
| 470 | dev = driver_find_device(&amd_mp2_pci_driver.driver, NULL, NULL, | 465 | dev = driver_find_next_device(&amd_mp2_pci_driver.driver, NULL); |
| 471 | amd_mp2_device_match); | ||
| 472 | if (!dev) | 466 | if (!dev) |
| 473 | return NULL; | 467 | return NULL; |
| 474 | 468 | ||
| @@ -354,17 +354,11 @@ static int i2c_acpi_find_match_adapter(struct device *dev, const void *data) · 353 unmodified lines | |||
| 354 | return ACPI_HANDLE(dev) == (acpi_handle)data; | 354 | return ACPI_HANDLE(dev) == (acpi_handle)data; |
| 355 | } | 355 | } |
| 356 | 356 | ||
| 357 | static int i2c_acpi_find_match_device(struct device *dev, const void *data) | ||
| 358 | { | ||
| 359 | return ACPI_COMPANION(dev) == data; | ||
| 360 | } | ||
| 361 | 357 | ||
| 362 | struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle) | 358 | struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle) |
| 363 | { | 359 | { |
| 364 | struct device *dev; | 360 | struct device *dev = bus_find_device_by_acpi_dev(&i2c_bus_type, handle); |
| 365 | 361 | ||
| 366 | dev = bus_find_device(&i2c_bus_type, NULL, handle, | ||
| 367 | i2c_acpi_find_match_adapter); | ||
| 368 | return dev ? i2c_verify_adapter(dev) : NULL; | 362 | return dev ? i2c_verify_adapter(dev) : NULL; |
| 369 | } | 363 | } |
| 370 | EXPORT_SYMBOL_GPL(i2c_acpi_find_adapter_by_handle); | 364 | EXPORT_SYMBOL_GPL(i2c_acpi_find_adapter_by_handle); |
| @@ -373,8 +367,7 @@ static struct i2c_client *i2c_acpi_find_client_by_adev(struct acpi_device *adev) · 2 unmodified lines | |||
| 373 | { | 367 | { |
| 374 | struct device *dev; | 368 | struct device *dev; |
| 375 | 369 | ||
| 376 | dev = bus_find_device(&i2c_bus_type, NULL, adev, | 370 | dev = bus_find_device_by_acpi_dev(&i2c_bus_type, adev); |
| 377 | i2c_acpi_find_match_device); | ||
| 378 | return dev ? i2c_verify_client(dev) : NULL; | 371 | return dev ? i2c_verify_client(dev) : NULL; |
| 379 | } | 372 | } |
| 380 | 373 | ||
| @@ -113,11 +113,6 @@ void of_i2c_register_devices(struct i2c_adapter *adap) · 112 unmodified lines | |||
| 113 | of_node_put(bus); | 113 | of_node_put(bus); |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | static int of_dev_node_match(struct device *dev, const void *data) | ||
| 117 | { | ||
| 118 | return dev->of_node == data; | ||
| 119 | } | ||
| 120 | |||
| 121 | static int of_dev_or_parent_node_match(struct device *dev, const void *data) | 116 | static int of_dev_or_parent_node_match(struct device *dev, const void *data) |
| 122 | { | 117 | { |
| 123 | if (dev->of_node == data) | 118 | if (dev->of_node == data) |
| @@ -135,7 +130,7 @@ struct i2c_client *of_find_i2c_device_by_node(struct device_node *node) · 11 unmodified lines | |||
| 135 | struct device *dev; | 130 | struct device *dev; |
| 136 | struct i2c_client *client; | 131 | struct i2c_client *client; |
| 137 | 132 | ||
| 138 | dev = bus_find_device(&i2c_bus_type, NULL, node, of_dev_node_match); | 133 | dev = bus_find_device_by_of_node(&i2c_bus_type, node); |
| 139 | if (!dev) | 134 | if (!dev) |
| 140 | return NULL; | 135 | return NULL; |
| 141 | 136 | ||
| @@ -4499,19 +4499,13 @@ static const struct acpi_device_id hns_roce_acpi_match[] = { · 4498 unmodified lines | |||
| 4499 | }; | 4499 | }; |
| 4500 | MODULE_DEVICE_TABLE(acpi, hns_roce_acpi_match); | 4500 | MODULE_DEVICE_TABLE(acpi, hns_roce_acpi_match); |
| 4501 | 4501 | ||
| 4502 | static int hns_roce_node_match(struct device *dev, const void *fwnode) | ||
| 4503 | { | ||
| 4504 | return dev->fwnode == fwnode; | ||
| 4505 | } | ||
| 4506 | |||
| 4507 | static struct | 4502 | static struct |
| 4508 | platform_device *hns_roce_find_pdev(struct fwnode_handle *fwnode) | 4503 | platform_device *hns_roce_find_pdev(struct fwnode_handle *fwnode) |
| 4509 | { | 4504 | { |
| 4510 | struct device *dev; | 4505 | struct device *dev; |
| 4511 | 4506 | ||
| 4512 | /* get the 'device' corresponding to the matching 'fwnode' */ | 4507 | /* get the 'device' corresponding to the matching 'fwnode' */ |
| 4513 | dev = bus_find_device(&platform_bus_type, NULL, | 4508 | dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode); |
| 4514 | fwnode, hns_roce_node_match); | ||
| 4515 | /* get the platform device */ | 4509 | /* get the platform device */ |
| 4516 | return dev ? to_platform_device(dev) : NULL; | 4510 | return dev ? to_platform_device(dev) : NULL; |
| 4517 | } | 4511 | } |
| @@ -2034,16 +2034,11 @@ arm_smmu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova) · 2033 unmodified lines | |||
| 2034 | 2034 | ||
| 2035 | static struct platform_driver arm_smmu_driver; | 2035 | static struct platform_driver arm_smmu_driver; |
| 2036 | 2036 | ||
| 2037 | static int arm_smmu_match_node(struct device *dev, const void *data) | ||
| 2038 | { | ||
| 2039 | return dev->fwnode == data; | ||
| 2040 | } | ||
| 2041 | |||
| 2042 | static | 2037 | static |
| 2043 | struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode) | 2038 | struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode) |
| 2044 | { | 2039 | { |
| 2045 | struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL, | 2040 | struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver, |
| 2046 | fwnode, arm_smmu_match_node); | 2041 | fwnode); |
| 2047 | put_device(dev); | 2042 | put_device(dev); |
| 2048 | return dev ? dev_get_drvdata(dev) : NULL; | 2043 | return dev ? dev_get_drvdata(dev) : NULL; |
| 2049 | } | 2044 | } |
| @@ -1426,16 +1426,11 @@ static bool arm_smmu_capable(enum iommu_cap cap) · 1425 unmodified lines | |||
| 1426 | } | 1426 | } |
| 1427 | } | 1427 | } |
| 1428 | 1428 | ||
| 1429 | static int arm_smmu_match_node(struct device *dev, const void *data) | ||
| 1430 | { | ||
| 1431 | return dev->fwnode == data; | ||
| 1432 | } | ||
| 1433 | |||
| 1434 | static | 1429 | static |
| 1435 | struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode) | 1430 | struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode) |
| 1436 | { | 1431 | { |
| 1437 | struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL, | 1432 | struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver, |
| 1438 | fwnode, arm_smmu_match_node); | 1433 | fwnode); |
| 1439 | put_device(dev); | 1434 | put_device(dev); |
| 1440 | return dev ? dev_get_drvdata(dev) : NULL; | 1435 | return dev ? dev_get_drvdata(dev) : NULL; |
| 1441 | } | 1436 | } |
| @@ -214,13 +214,6 @@ static int led_resume(struct device *dev) · 213 unmodified lines | |||
| 214 | 214 | ||
| 215 | static SIMPLE_DEV_PM_OPS(leds_class_dev_pm_ops, led_suspend, led_resume); | 215 | static SIMPLE_DEV_PM_OPS(leds_class_dev_pm_ops, led_suspend, led_resume); |
| 216 | 216 | ||
| 217 | static int match_name(struct device *dev, const void *data) | ||
| 218 | { | ||
| 219 | if (!dev_name(dev)) | ||
| 220 | return 0; | ||
| 221 | return !strcmp(dev_name(dev), (char *)data); | ||
| 222 | } | ||
| 223 | |||
| 224 | static int led_classdev_next_name(const char *init_name, char *name, | 217 | static int led_classdev_next_name(const char *init_name, char *name, |
| 225 | size_t len) | 218 | size_t len) |
| 226 | { | 219 | { |
| @@ -231,7 +224,7 @@ static int led_classdev_next_name(const char *init_name, char *name, · 4 unmodified lines | |||
| 231 | strlcpy(name, init_name, len); | 224 | strlcpy(name, init_name, len); |
| 232 | 225 | ||
| 233 | while ((ret < len) && | 226 | while ((ret < len) && |
| 234 | (dev = class_find_device(leds_class, NULL, name, match_name))) { | 227 | (dev = class_find_device_by_name(leds_class, name))) { |
| 235 | put_device(dev); | 228 | put_device(dev); |
| 236 | ret = snprintf(name, len, "%s_%u", init_name, ++i); | 229 | ret = snprintf(name, len, "%s_%u", init_name, ++i); |
| 237 | } | 230 | } |
| @@ -87,16 +87,6 @@ static struct regmap_config altr_sysmgr_regmap_cfg = { · 86 unmodified lines | |||
| 87 | .use_single_write = true, | 87 | .use_single_write = true, |
| 88 | }; | 88 | }; |
| 89 | 89 | ||
| 90 | /** | ||
| 91 | * sysmgr_match_phandle | ||
| 92 | * Matching function used by driver_find_device(). | ||
| 93 | * Return: True if match is found, otherwise false. | ||
| 94 | */ | ||
| 95 | static int sysmgr_match_phandle(struct device *dev, const void *data) | ||
| 96 | { | ||
| 97 | return dev->of_node == (const struct device_node *)data; | ||
| 98 | } | ||
| 99 | |||
| 100 | /** | 90 | /** |
| 101 | * altr_sysmgr_regmap_lookup_by_phandle | 91 | * altr_sysmgr_regmap_lookup_by_phandle |
| 102 | * Find the sysmgr previous configured in probe() and return regmap property. | 92 | * Find the sysmgr previous configured in probe() and return regmap property. |
| @@ -117,8 +107,8 @@ struct regmap *altr_sysmgr_regmap_lookup_by_phandle(struct device_node *np, · 14 unmodified lines | |||
| 117 | if (!sysmgr_np) | 107 | if (!sysmgr_np) |
| 118 | return ERR_PTR(-ENODEV); | 108 | return ERR_PTR(-ENODEV); |
| 119 | 109 | ||
| 120 | dev = driver_find_device(&altr_sysmgr_driver.driver, NULL, | 110 | dev = driver_find_device_by_of_node(&altr_sysmgr_driver.driver, |
| 121 | (void *)sysmgr_np, sysmgr_match_phandle); | 111 | (void *)sysmgr_np); |
| 122 | of_node_put(sysmgr_np); | 112 | of_node_put(sysmgr_np); |
| 123 | if (!dev) | 113 | if (!dev) |
| 124 | return ERR_PTR(-EPROBE_DEFER); | 114 | return ERR_PTR(-EPROBE_DEFER); |
| @@ -858,13 +858,6 @@ static ssize_t dev_state_show(struct device *device, · 857 unmodified lines | |||
| 858 | } | 858 | } |
| 859 | static DEVICE_ATTR_RO(dev_state); | 859 | static DEVICE_ATTR_RO(dev_state); |
| 860 | 860 | ||
| 861 | static int match_devt(struct device *dev, const void *data) | ||
| 862 | { | ||
| 863 | const dev_t *devt = data; | ||
| 864 | |||
| 865 | return dev->devt == *devt; | ||
| 866 | } | ||
| 867 | |||
| 868 | /** | 861 | /** |
| 869 | * dev_set_devstate: set to new device state and notify sysfs file. | 862 | * dev_set_devstate: set to new device state and notify sysfs file. |
| 870 | * | 863 | * |
| @@ -880,7 +873,7 @@ void mei_set_devstate(struct mei_device *dev, enum mei_dev_state state) · 9 unmodified lines | |||
| 880 | 873 | ||
| 881 | dev->dev_state = state; | 874 | dev->dev_state = state; |
| 882 | 875 | ||
| 883 | clsdev = class_find_device(mei_class, NULL, &dev->cdev.dev, match_devt); | 876 | clsdev = class_find_device_by_devt(mei_class, dev->cdev.dev); |
| 884 | if (clsdev) { | 877 | if (clsdev) { |
| 885 | sysfs_notify(&clsdev->kobj, NULL, "dev_state"); | 878 | sysfs_notify(&clsdev->kobj, NULL, "dev_state"); |
| 886 | put_device(clsdev); | 879 | put_device(clsdev); |
| @@ -405,17 +405,12 @@ int mux_control_deselect(struct mux_control *mux) · 404 unmodified lines | |||
| 405 | } | 405 | } |
| 406 | EXPORT_SYMBOL_GPL(mux_control_deselect); | 406 | EXPORT_SYMBOL_GPL(mux_control_deselect); |
| 407 | 407 | ||
| 408 | static int of_dev_node_match(struct device *dev, const void *data) | ||
| 409 | { | ||
| 410 | return dev->of_node == data; | ||
| 411 | } | ||
| 412 | |||
| 413 | /* Note this function returns a reference to the mux_chip dev. */ | 408 | /* Note this function returns a reference to the mux_chip dev. */ |
| 414 | static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np) | 409 | static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np) |
| 415 | { | 410 | { |
| 416 | struct device *dev; | 411 | struct device *dev; |
| 417 | 412 | ||
| 418 | dev = class_find_device(&mux_class, NULL, np, of_dev_node_match); | 413 | dev = class_find_device_by_of_node(&mux_class, np); |
| 419 | 414 | ||
| 420 | return dev ? to_mux_chip(dev) : NULL; | 415 | return dev ? to_mux_chip(dev) : NULL; |
| 421 | } | 416 | } |
| @@ -754,17 +754,11 @@ struct dsaf_misc_op *hns_misc_op_get(struct dsaf_device *dsaf_dev) · 753 unmodified lines | |||
| 754 | return (void *)misc_op; | 754 | return (void *)misc_op; |
| 755 | } | 755 | } |
| 756 | 756 | ||
| 757 | static int hns_dsaf_dev_match(struct device *dev, const void *fwnode) | ||
| 758 | { | ||
| 759 | return dev->fwnode == fwnode; | ||
| 760 | } | ||
| 761 | |||
| 762 | struct | 757 | struct |
| 763 | platform_device *hns_dsaf_find_platform_device(struct fwnode_handle *fwnode) | 758 | platform_device *hns_dsaf_find_platform_device(struct fwnode_handle *fwnode) |
| 764 | { | 759 | { |
| 765 | struct device *dev; | 760 | struct device *dev; |
| 766 | 761 | ||
| 767 | dev = bus_find_device(&platform_bus_type, NULL, | 762 | dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode); |
| 768 | fwnode, hns_dsaf_dev_match); | ||
| 769 | return dev ? to_platform_device(dev) : NULL; | 763 | return dev ? to_platform_device(dev) : NULL; |
| 770 | } | 764 | } |
| @@ -262,11 +262,6 @@ static struct class mdio_bus_class = { · 261 unmodified lines | |||
| 262 | }; | 262 | }; |
| 263 | 263 | ||
| 264 | #if IS_ENABLED(CONFIG_OF_MDIO) | 264 | #if IS_ENABLED(CONFIG_OF_MDIO) |
| 265 | /* Helper function for of_mdio_find_bus */ | ||
| 266 | static int of_mdio_bus_match(struct device *dev, const void *mdio_bus_np) | ||
| 267 | { | ||
| 268 | return dev->of_node == mdio_bus_np; | ||
| 269 | } | ||
| 270 | /** | 265 | /** |
| 271 | * of_mdio_find_bus - Given an mii_bus node, find the mii_bus. | 266 | * of_mdio_find_bus - Given an mii_bus node, find the mii_bus. |
| 272 | * @mdio_bus_np: Pointer to the mii_bus. | 267 | * @mdio_bus_np: Pointer to the mii_bus. |
| @@ -287,9 +282,7 @@ struct mii_bus *of_mdio_find_bus(struct device_node *mdio_bus_np) · 14 unmodified lines | |||
| 287 | if (!mdio_bus_np) | 282 | if (!mdio_bus_np) |
| 288 | return NULL; | 283 | return NULL; |
| 289 | 284 | ||
| 290 | d = class_find_device(&mdio_bus_class, NULL, mdio_bus_np, | 285 | d = class_find_device_by_of_node(&mdio_bus_class, mdio_bus_np); |
| 291 | of_mdio_bus_match); | ||
| 292 | |||
| 293 | return d ? to_mii_bus(d) : NULL; | 286 | return d ? to_mii_bus(d) : NULL; |
| 294 | } | 287 | } |
| 295 | EXPORT_SYMBOL(of_mdio_find_bus); | 288 | EXPORT_SYMBOL(of_mdio_find_bus); |
| @@ -76,11 +76,6 @@ static struct bus_type nvmem_bus_type = { · 75 unmodified lines | |||
| 76 | .name = "nvmem", | 76 | .name = "nvmem", |
| 77 | }; | 77 | }; |
| 78 | 78 | ||
| 79 | static int of_nvmem_match(struct device *dev, const void *nvmem_np) | ||
| 80 | { | ||
| 81 | return dev->of_node == nvmem_np; | ||
| 82 | } | ||
| 83 | |||
| 84 | static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np) | 79 | static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np) |
| 85 | { | 80 | { |
| 86 | struct device *d; | 81 | struct device *d; |
| @@ -88,7 +83,7 @@ static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np) · 1 unmodified line | |||
| 88 | if (!nvmem_np) | 83 | if (!nvmem_np) |
| 89 | return NULL; | 84 | return NULL; |
| 90 | 85 | ||
| 91 | d = bus_find_device(&nvmem_bus_type, NULL, nvmem_np, of_nvmem_match); | 86 | d = bus_find_device_by_of_node(&nvmem_bus_type, nvmem_np); |
| 92 | 87 | ||
| 93 | if (!d) | 88 | if (!d) |
| 94 | return NULL; | 89 | return NULL; |
| @@ -280,12 +280,6 @@ unregister: · 279 unmodified lines | |||
| 280 | } | 280 | } |
| 281 | EXPORT_SYMBOL(of_mdiobus_register); | 281 | EXPORT_SYMBOL(of_mdiobus_register); |
| 282 | 282 | ||
| 283 | /* Helper function for of_phy_find_device */ | ||
| 284 | static int of_phy_match(struct device *dev, const void *phy_np) | ||
| 285 | { | ||
| 286 | return dev->of_node == phy_np; | ||
| 287 | } | ||
| 288 | |||
| 289 | /** | 283 | /** |
| 290 | * of_phy_find_device - Give a PHY node, find the phy_device | 284 | * of_phy_find_device - Give a PHY node, find the phy_device |
| 291 | * @phy_np: Pointer to the phy's device tree node | 285 | * @phy_np: Pointer to the phy's device tree node |
| @@ -301,7 +295,7 @@ struct phy_device *of_phy_find_device(struct device_node *phy_np) · 9 unmodified lines | |||
| 301 | if (!phy_np) | 295 | if (!phy_np) |
| 302 | return NULL; | 296 | return NULL; |
| 303 | 297 | ||
| 304 | d = bus_find_device(&mdio_bus_type, NULL, phy_np, of_phy_match); | 298 | d = bus_find_device_by_of_node(&mdio_bus_type, phy_np); |
| 305 | if (d) { | 299 | if (d) { |
| 306 | mdiodev = to_mdio_device(d); | 300 | mdiodev = to_mdio_device(d); |
| 307 | if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) | 301 | if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) |
| @@ -37,11 +37,6 @@ static const struct of_device_id of_skipped_node_table[] = { · 36 unmodified lines | |||
| 37 | {} /* Empty terminated list */ | 37 | {} /* Empty terminated list */ |
| 38 | }; | 38 | }; |
| 39 | 39 | ||
| 40 | static int of_dev_node_match(struct device *dev, const void *data) | ||
| 41 | { | ||
| 42 | return dev->of_node == data; | ||
| 43 | } | ||
| 44 | |||
| 45 | /** | 40 | /** |
| 46 | * of_find_device_by_node - Find the platform_device associated with a node | 41 | * of_find_device_by_node - Find the platform_device associated with a node |
| 47 | * @np: Pointer to device tree node | 42 | * @np: Pointer to device tree node |
| @@ -55,7 +50,7 @@ struct platform_device *of_find_device_by_node(struct device_node *np) · 7 unmodified lines | |||
| 55 | { | 50 | { |
| 56 | struct device *dev; | 51 | struct device *dev; |
| 57 | 52 | ||
| 58 | dev = bus_find_device(&platform_bus_type, NULL, np, of_dev_node_match); | 53 | dev = bus_find_device_by_of_node(&platform_bus_type, np); |
| 59 | return dev ? to_platform_device(dev) : NULL; | 54 | return dev ? to_platform_device(dev) : NULL; |
| 60 | } | 55 | } |
| 61 | EXPORT_SYMBOL(of_find_device_by_node); | 56 | EXPORT_SYMBOL(of_find_device_by_node); |
| @@ -64,11 +64,6 @@ static struct resource *get_pci_domain_busn_res(int domain_nr) · 63 unmodified lines | |||
| 64 | return &r->res; | 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 | * Some device drivers need know if PCI is initiated. | 68 | * Some device drivers need know if PCI is initiated. |
| 74 | * Basically, we think PCI is not initiated when there | 69 | * Basically, we think PCI is not initiated when there |
| @@ -79,7 +74,7 @@ int no_pci_devices(void) · 4 unmodified lines | |||
| 79 | struct device *dev; | 74 | struct device *dev; |
| 80 | int no_devices; | 75 | int no_devices; |
| 81 | 76 | ||
| 82 | dev = bus_find_device(&pci_bus_type, NULL, NULL, find_anything); | 77 | dev = bus_find_next_device(&pci_bus_type, NULL); |
| 83 | no_devices = (dev == NULL); | 78 | no_devices = (dev == NULL); |
| 84 | put_device(dev); | 79 | put_device(dev); |
| 85 | return no_devices; | 80 | return no_devices; |
| @@ -460,16 +460,11 @@ error: · 459 unmodified lines | |||
| 460 | return NULL; | 460 | return NULL; |
| 461 | } | 461 | } |
| 462 | 462 | ||
| 463 | static int of_node_match(struct device *dev, const void *data) | ||
| 464 | { | ||
| 465 | return dev->of_node == data; | ||
| 466 | } | ||
| 467 | |||
| 468 | struct regulator_dev *of_find_regulator_by_node(struct device_node *np) | 463 | struct regulator_dev *of_find_regulator_by_node(struct device_node *np) |
| 469 | { | 464 | { |
| 470 | struct device *dev; | 465 | struct device *dev; |
| 471 | 466 | ||
| 472 | dev = class_find_device(®ulator_class, NULL, np, of_node_match); | 467 | dev = class_find_device_by_of_node(®ulator_class, np); |
| 473 | 468 | ||
| 474 | return dev ? dev_to_rdev(dev) : NULL; | 469 | return dev ? dev_to_rdev(dev) : NULL; |
| 475 | } | 470 | } |
| @@ -663,21 +663,12 @@ void rtc_update_irq(struct rtc_device *rtc, · 662 unmodified lines | |||
| 663 | } | 663 | } |
| 664 | EXPORT_SYMBOL_GPL(rtc_update_irq); | 664 | EXPORT_SYMBOL_GPL(rtc_update_irq); |
| 665 | 665 | ||
| 666 | static int __rtc_match(struct device *dev, const void *data) | ||
| 667 | { | ||
| 668 | const char *name = data; | ||
| 669 | |||
| 670 | if (strcmp(dev_name(dev), name) == 0) | ||
| 671 | return 1; | ||
| 672 | return 0; | ||
| 673 | } | ||
| 674 | |||
| 675 | struct rtc_device *rtc_class_open(const char *name) | 666 | struct rtc_device *rtc_class_open(const char *name) |
| 676 | { | 667 | { |
| 677 | struct device *dev; | 668 | struct device *dev; |
| 678 | struct rtc_device *rtc = NULL; | 669 | struct rtc_device *rtc = NULL; |
| 679 | 670 | ||
| 680 | dev = class_find_device(rtc_class, NULL, name, __rtc_match); | 671 | dev = class_find_device_by_name(rtc_class, name); |
| 681 | if (dev) | 672 | if (dev) |
| 682 | rtc = to_rtc_device(dev); | 673 | rtc = to_rtc_device(dev); |
| 683 | 674 | ||
| @@ -581,11 +581,6 @@ int ccwgroup_driver_register(struct ccwgroup_driver *cdriver) · 580 unmodified lines | |||
| 581 | } | 581 | } |
| 582 | EXPORT_SYMBOL(ccwgroup_driver_register); | 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 | * ccwgroup_driver_unregister() - deregister a ccw group driver | 585 | * ccwgroup_driver_unregister() - deregister a ccw group driver |
| 591 | * @cdriver: driver to be deregistered | 586 | * @cdriver: driver to be deregistered |
| @@ -597,8 +592,7 @@ void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver) · 5 unmodified lines | |||
| 597 | struct device *dev; | 592 | struct device *dev; |
| 598 | 593 | ||
| 599 | /* We don't want ccwgroup devices to live longer than their driver. */ | 594 | /* We don't want ccwgroup devices to live longer than their driver. */ |
| 600 | while ((dev = driver_find_device(&cdriver->driver, NULL, NULL, | 595 | while ((dev = driver_find_next_device(&cdriver->driver, NULL))) { |
| 601 | __ccwgroup_match_all))) { | ||
| 602 | struct ccwgroup_device *gdev = to_ccwgroupdev(dev); | 596 | struct ccwgroup_device *gdev = to_ccwgroupdev(dev); |
| 603 | 597 | ||
| 604 | ccwgroup_ungroup(gdev); | 598 | ccwgroup_ungroup(gdev); |
| @@ -608,13 +602,6 @@ void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver) · 3 unmodified lines | |||
| 608 | } | 602 | } |
| 609 | EXPORT_SYMBOL(ccwgroup_driver_unregister); | 603 | EXPORT_SYMBOL(ccwgroup_driver_unregister); |
| 610 | 604 | ||
| 611 | static int __ccwgroupdev_check_busid(struct device *dev, const void *id) | ||
| 612 | { | ||
| 613 | const char *bus_id = id; | ||
| 614 | |||
| 615 | return (strcmp(bus_id, dev_name(dev)) == 0); | ||
| 616 | } | ||
| 617 | |||
| 618 | /** | 605 | /** |
| 619 | * get_ccwgroupdev_by_busid() - obtain device from a bus id | 606 | * get_ccwgroupdev_by_busid() - obtain device from a bus id |
| 620 | * @gdrv: driver the device is owned by | 607 | * @gdrv: driver the device is owned by |
| @@ -631,8 +618,7 @@ struct ccwgroup_device *get_ccwgroupdev_by_busid(struct ccwgroup_driver *gdrv, · 10 unmodified lines | |||
| 631 | { | 618 | { |
| 632 | struct device *dev; | 619 | struct device *dev; |
| 633 | 620 | ||
| 634 | dev = driver_find_device(&gdrv->driver, NULL, bus_id, | 621 | dev = driver_find_device_by_name(&gdrv->driver, bus_id); |
| 635 | __ccwgroupdev_check_busid); | ||
| 636 | 622 | ||
| 637 | return dev ? to_ccwgroupdev(dev) : NULL; | 623 | return dev ? to_ccwgroupdev(dev) : NULL; |
| 638 | } | 624 | } |
| @@ -1695,18 +1695,6 @@ int ccw_device_force_console(struct ccw_device *cdev) · 1694 unmodified lines | |||
| 1695 | EXPORT_SYMBOL_GPL(ccw_device_force_console); | 1695 | EXPORT_SYMBOL_GPL(ccw_device_force_console); |
| 1696 | #endif | 1696 | #endif |
| 1697 | 1697 | ||
| 1698 | /* | ||
| 1699 | * get ccw_device matching the busid, but only if owned by cdrv | ||
| 1700 | */ | ||
| 1701 | static int | ||
| 1702 | __ccwdev_check_busid(struct device *dev, const void *id) | ||
| 1703 | { | ||
| 1704 | const char *bus_id = id; | ||
| 1705 | |||
| 1706 | return (strcmp(bus_id, dev_name(dev)) == 0); | ||
| 1707 | } | ||
| 1708 | |||
| 1709 | |||
| 1710 | /** | 1698 | /** |
| 1711 | * get_ccwdev_by_busid() - obtain device from a bus id | 1699 | * get_ccwdev_by_busid() - obtain device from a bus id |
| 1712 | * @cdrv: driver the device is owned by | 1700 | * @cdrv: driver the device is owned by |
| @@ -1723,8 +1711,7 @@ struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv, · 10 unmodified lines | |||
| 1723 | { | 1711 | { |
| 1724 | struct device *dev; | 1712 | struct device *dev; |
| 1725 | 1713 | ||
| 1726 | dev = driver_find_device(&cdrv->driver, NULL, (void *)bus_id, | 1714 | dev = driver_find_device_by_name(&cdrv->driver, bus_id); |
| 1727 | __ccwdev_check_busid); | ||
| 1728 | 1715 | ||
| 1729 | return dev ? to_ccwdev(dev) : NULL; | 1716 | return dev ? to_ccwdev(dev) : NULL; |
| 1730 | } | 1717 | } |
| @@ -133,18 +133,6 @@ struct zcdn_device { · 132 unmodified lines | |||
| 133 | static int zcdn_create(const char *name); | 133 | static int zcdn_create(const char *name); |
| 134 | static int zcdn_destroy(const char *name); | 134 | static int zcdn_destroy(const char *name); |
| 135 | 135 | ||
| 136 | /* helper function, matches the name for find_zcdndev_by_name() */ | ||
| 137 | static int __match_zcdn_name(struct device *dev, const void *data) | ||
| 138 | { | ||
| 139 | return strcmp(dev_name(dev), (const char *)data) == 0; | ||
| 140 | } | ||
| 141 | |||
| 142 | /* helper function, matches the devt value for find_zcdndev_by_devt() */ | ||
| 143 | static int __match_zcdn_devt(struct device *dev, const void *data) | ||
| 144 | { | ||
| 145 | return dev->devt == *((dev_t *) data); | ||
| 146 | } | ||
| 147 | |||
| 148 | /* | 136 | /* |
| 149 | * Find zcdn device by name. | 137 | * Find zcdn device by name. |
| 150 | * Returns reference to the zcdn device which needs to be released | 138 | * Returns reference to the zcdn device which needs to be released |
| @@ -152,10 +140,7 @@ static int __match_zcdn_devt(struct device *dev, const void *data) · 1 unmodified line | |||
| 152 | */ | 140 | */ |
| 153 | static inline struct zcdn_device *find_zcdndev_by_name(const char *name) | 141 | static inline struct zcdn_device *find_zcdndev_by_name(const char *name) |
| 154 | { | 142 | { |
| 155 | struct device *dev = | 143 | struct device *dev = class_find_device_by_name(zcrypt_class, name); |
| 156 | class_find_device(zcrypt_class, NULL, | ||
| 157 | (void *) name, | ||
| 158 | __match_zcdn_name); | ||
| 159 | 144 | ||
| 160 | return dev ? to_zcdn_dev(dev) : NULL; | 145 | return dev ? to_zcdn_dev(dev) : NULL; |
| 161 | } | 146 | } |
| @@ -167,10 +152,7 @@ static inline struct zcdn_device *find_zcdndev_by_name(const char *name) · 5 unmodified lines | |||
| 167 | */ | 152 | */ |
| 168 | static inline struct zcdn_device *find_zcdndev_by_devt(dev_t devt) | 153 | static inline struct zcdn_device *find_zcdndev_by_devt(dev_t devt) |
| 169 | { | 154 | { |
| 170 | struct device *dev = | 155 | struct device *dev = class_find_device_by_devt(zcrypt_class, devt); |
| 171 | class_find_device(zcrypt_class, NULL, | ||
| 172 | (void *) &devt, | ||
| 173 | __match_zcdn_devt); | ||
| 174 | 156 | ||
| 175 | return dev ? to_zcdn_dev(dev) : NULL; | 157 | return dev ? to_zcdn_dev(dev) : NULL; |
| 176 | } | 158 | } |
| @@ -372,15 +372,10 @@ static ssize_t proc_scsi_write(struct file *file, const char __user *buf, · 371 unmodified lines | |||
| 372 | return err; | 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 | static inline struct device *next_scsi_device(struct device *start) | 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, | 377 | struct device *next = bus_find_next_device(&scsi_bus_type, start); |
| 383 | always_match); | 378 | |
| 384 | put_device(start); | 379 | put_device(start); |
| 385 | return next; | 380 | return next; |
| 386 | } | 381 | } |
| @@ -3652,37 +3652,25 @@ EXPORT_SYMBOL_GPL(spi_write_then_read); · 3651 unmodified lines | |||
| 3652 | /*-------------------------------------------------------------------------*/ | 3652 | /*-------------------------------------------------------------------------*/ |
| 3653 | 3653 | ||
| 3654 | #if IS_ENABLED(CONFIG_OF) | 3654 | #if IS_ENABLED(CONFIG_OF) |
| 3655 | static int __spi_of_device_match(struct device *dev, const void *data) | ||
| 3656 | { | ||
| 3657 | return dev->of_node == data; | ||
| 3658 | } | ||
| 3659 | |||
| 3660 | /* must call put_device() when done with returned spi_device device */ | 3655 | /* must call put_device() when done with returned spi_device device */ |
| 3661 | struct spi_device *of_find_spi_device_by_node(struct device_node *node) | 3656 | struct spi_device *of_find_spi_device_by_node(struct device_node *node) |
| 3662 | { | 3657 | { |
| 3663 | struct device *dev = bus_find_device(&spi_bus_type, NULL, node, | 3658 | struct device *dev = bus_find_device_by_of_node(&spi_bus_type, node); |
| 3664 | __spi_of_device_match); | 3659 | |
| 3665 | return dev ? to_spi_device(dev) : NULL; | 3660 | return dev ? to_spi_device(dev) : NULL; |
| 3666 | } | 3661 | } |
| 3667 | EXPORT_SYMBOL_GPL(of_find_spi_device_by_node); | 3662 | EXPORT_SYMBOL_GPL(of_find_spi_device_by_node); |
| 3668 | #endif /* IS_ENABLED(CONFIG_OF) */ | 3663 | #endif /* IS_ENABLED(CONFIG_OF) */ |
| 3669 | 3664 | ||
| 3670 | #if IS_ENABLED(CONFIG_OF_DYNAMIC) | 3665 | #if IS_ENABLED(CONFIG_OF_DYNAMIC) |
| 3671 | static int __spi_of_controller_match(struct device *dev, const void *data) | ||
| 3672 | { | ||
| 3673 | return dev->of_node == data; | ||
| 3674 | } | ||
| 3675 | |||
| 3676 | /* the spi controllers are not using spi_bus, so we find it with another way */ | 3666 | /* the spi controllers are not using spi_bus, so we find it with another way */ |
| 3677 | static struct spi_controller *of_find_spi_controller_by_node(struct device_node *node) | 3667 | static struct spi_controller *of_find_spi_controller_by_node(struct device_node *node) |
| 3678 | { | 3668 | { |
| 3679 | struct device *dev; | 3669 | struct device *dev; |
| 3680 | 3670 | ||
| 3681 | dev = class_find_device(&spi_master_class, NULL, node, | 3671 | dev = class_find_device_by_of_node(&spi_master_class, node); |
| 3682 | __spi_of_controller_match); | ||
| 3683 | if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE)) | 3672 | if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE)) |
| 3684 | dev = class_find_device(&spi_slave_class, NULL, node, | 3673 | dev = class_find_device_by_of_node(&spi_slave_class, node); |
| 3685 | __spi_of_controller_match); | ||
| 3686 | if (!dev) | 3674 | if (!dev) |
| 3687 | return NULL; | 3675 | return NULL; |
| 3688 | 3676 | ||
| @@ -3753,11 +3741,6 @@ static int spi_acpi_controller_match(struct device *dev, const void *data) · 64 unmodified lines | |||
| 3753 | return ACPI_COMPANION(dev->parent) == data; | 3741 | return ACPI_COMPANION(dev->parent) == data; |
| 3754 | } | 3742 | } |
| 3755 | 3743 | ||
| 3756 | static int spi_acpi_device_match(struct device *dev, const void *data) | ||
| 3757 | { | ||
| 3758 | return ACPI_COMPANION(dev) == data; | ||
| 3759 | } | ||
| 3760 | |||
| 3761 | static struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev) | 3744 | static struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev) |
| 3762 | { | 3745 | { |
| 3763 | struct device *dev; | 3746 | struct device *dev; |
| @@ -3777,8 +3760,7 @@ static struct spi_device *acpi_spi_find_device_by_adev(struct acpi_device *adev) · 13 unmodified lines | |||
| 3777 | { | 3760 | { |
| 3778 | struct device *dev; | 3761 | struct device *dev; |
| 3779 | 3762 | ||
| 3780 | dev = bus_find_device(&spi_bus_type, NULL, adev, spi_acpi_device_match); | 3763 | dev = bus_find_device_by_acpi_dev(&spi_bus_type, adev); |
| 3781 | |||
| 3782 | return dev ? to_spi_device(dev) : NULL; | 3764 | return dev ? to_spi_device(dev) : NULL; |
| 3783 | } | 3765 | } |
| 3784 | 3766 | ||
| @@ -2952,17 +2952,11 @@ void do_SAK(struct tty_struct *tty) · 2951 unmodified lines | |||
| 2952 | 2952 | ||
| 2953 | EXPORT_SYMBOL(do_SAK); | 2953 | EXPORT_SYMBOL(do_SAK); |
| 2954 | 2954 | ||
| 2955 | static int dev_match_devt(struct device *dev, const void *data) | ||
| 2956 | { | ||
| 2957 | const dev_t *devt = data; | ||
| 2958 | return dev->devt == *devt; | ||
| 2959 | } | ||
| 2960 | |||
| 2961 | /* Must put_device() after it's unused! */ | 2955 | /* Must put_device() after it's unused! */ |
| 2962 | static struct device *tty_get_device(struct tty_struct *tty) | 2956 | static struct device *tty_get_device(struct tty_struct *tty) |
| 2963 | { | 2957 | { |
| 2964 | dev_t devt = tty_devnum(tty); | 2958 | dev_t devt = tty_devnum(tty); |
| 2965 | return class_find_device(tty_class, NULL, &devt, dev_match_devt); | 2959 | return class_find_device_by_devt(tty_class, devt); |
| 2966 | } | 2960 | } |
| 2967 | 2961 | ||
| 2968 | 2962 | ||
| @@ -942,17 +942,11 @@ error: · 941 unmodified lines | |||
| 942 | return ret; | 942 | return ret; |
| 943 | } | 943 | } |
| 944 | 944 | ||
| 945 | static int match_devt(struct device *dev, const void *data) | ||
| 946 | { | ||
| 947 | return dev->devt == (dev_t)(unsigned long)(void *)data; | ||
| 948 | } | ||
| 949 | |||
| 950 | static struct usb_device *usbdev_lookup_by_devt(dev_t devt) | 945 | static struct usb_device *usbdev_lookup_by_devt(dev_t devt) |
| 951 | { | 946 | { |
| 952 | struct device *dev; | 947 | struct device *dev; |
| 953 | 948 | ||
| 954 | dev = bus_find_device(&usb_bus_type, NULL, | 949 | dev = bus_find_device_by_devt(&usb_bus_type, devt); |
| 955 | (void *) (unsigned long) devt, match_devt); | ||
| 956 | if (!dev) | 950 | if (!dev) |
| 957 | return NULL; | 951 | return NULL; |
| 958 | return to_usb_device(dev); | 952 | return to_usb_device(dev); |
| @@ -85,16 +85,6 @@ enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw) · 84 unmodified lines | |||
| 85 | } | 85 | } |
| 86 | EXPORT_SYMBOL_GPL(usb_role_switch_get_role); | 86 | EXPORT_SYMBOL_GPL(usb_role_switch_get_role); |
| 87 | 87 | ||
| 88 | static int switch_fwnode_match(struct device *dev, const void *fwnode) | ||
| 89 | { | ||
| 90 | return dev_fwnode(dev) == fwnode; | ||
| 91 | } | ||
| 92 | |||
| 93 | static int switch_name_match(struct device *dev, const void *name) | ||
| 94 | { | ||
| 95 | return !strcmp((const char *)name, dev_name(dev)); | ||
| 96 | } | ||
| 97 | |||
| 98 | static void *usb_role_switch_match(struct device_connection *con, int ep, | 88 | static void *usb_role_switch_match(struct device_connection *con, int ep, |
| 99 | void *data) | 89 | void *data) |
| 100 | { | 90 | { |
| @@ -104,11 +94,9 @@ static void *usb_role_switch_match(struct device_connection *con, int ep, · 3 unmodified lines | |||
| 104 | if (con->id && !fwnode_property_present(con->fwnode, con->id)) | 94 | if (con->id && !fwnode_property_present(con->fwnode, con->id)) |
| 105 | return NULL; | 95 | return NULL; |
| 106 | 96 | ||
| 107 | dev = class_find_device(role_class, NULL, con->fwnode, | 97 | dev = class_find_device_by_fwnode(role_class, con->fwnode); |
| 108 | switch_fwnode_match); | ||
| 109 | } else { | 98 | } else { |
| 110 | dev = class_find_device(role_class, NULL, con->endpoint[ep], | 99 | dev = class_find_device_by_name(role_class, con->endpoint[ep]); |
| 111 | switch_name_match); | ||
| 112 | } | 100 | } |
| 113 | 101 | ||
| 114 | return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER); | 102 | return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER); |
| @@ -205,16 +205,6 @@ static void typec_altmode_put_partner(struct altmode *altmode) · 204 unmodified lines | |||
| 205 | put_device(&adev->dev); | 205 | put_device(&adev->dev); |
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | static int typec_port_fwnode_match(struct device *dev, const void *fwnode) | ||
| 209 | { | ||
| 210 | return dev_fwnode(dev) == fwnode; | ||
| 211 | } | ||
| 212 | |||
| 213 | static int typec_port_name_match(struct device *dev, const void *name) | ||
| 214 | { | ||
| 215 | return !strcmp((const char *)name, dev_name(dev)); | ||
| 216 | } | ||
| 217 | |||
| 218 | static void *typec_port_match(struct device_connection *con, int ep, void *data) | 208 | static void *typec_port_match(struct device_connection *con, int ep, void *data) |
| 219 | { | 209 | { |
| 220 | struct device *dev; | 210 | struct device *dev; |
| @@ -224,11 +214,9 @@ static void *typec_port_match(struct device_connection *con, int ep, void *data) · 3 unmodified lines | |||
| 224 | * we need to return ERR_PTR(-PROBE_DEFER) when there is no device. | 214 | * we need to return ERR_PTR(-PROBE_DEFER) when there is no device. |
| 225 | */ | 215 | */ |
| 226 | if (con->fwnode) | 216 | if (con->fwnode) |
| 227 | return class_find_device(typec_class, NULL, con->fwnode, | 217 | return class_find_device_by_fwnode(typec_class, con->fwnode); |
| 228 | typec_port_fwnode_match); | ||
| 229 | 218 | ||
| 230 | dev = class_find_device(typec_class, NULL, con->endpoint[ep], | 219 | dev = class_find_device_by_name(typec_class, con->endpoint[ep]); |
| 231 | typec_port_name_match); | ||
| 232 | 220 | ||
| 233 | return dev ? dev : ERR_PTR(-EPROBE_DEFER); | 221 | return dev ? dev : ERR_PTR(-EPROBE_DEFER); |
| 234 | } | 222 | } |
| @@ -164,16 +164,100 @@ void subsys_dev_iter_init(struct subsys_dev_iter *iter, · 163 unmodified lines | |||
| 164 | struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter); | 164 | struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter); |
| 165 | void subsys_dev_iter_exit(struct subsys_dev_iter *iter); | 165 | void subsys_dev_iter_exit(struct subsys_dev_iter *iter); |
| 166 | 166 | ||
| 167 | int device_match_name(struct device *dev, const void *name); | ||
| 167 | int device_match_of_node(struct device *dev, const void *np); | 168 | int device_match_of_node(struct device *dev, const void *np); |
| 169 | int device_match_fwnode(struct device *dev, const void *fwnode); | ||
| 170 | int device_match_devt(struct device *dev, const void *pdevt); | ||
| 171 | int device_match_acpi_dev(struct device *dev, const void *adev); | ||
| 172 | int device_match_any(struct device *dev, const void *unused); | ||
| 168 | 173 | ||
| 169 | int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, | 174 | int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, |
| 170 | int (*fn)(struct device *dev, void *data)); | 175 | int (*fn)(struct device *dev, void *data)); |
| 171 | struct device *bus_find_device(struct bus_type *bus, struct device *start, | 176 | struct device *bus_find_device(struct bus_type *bus, struct device *start, |
| 172 | const void *data, | 177 | const void *data, |
| 173 | int (*match)(struct device *dev, const void *data)); | 178 | int (*match)(struct device *dev, const void *data)); |
| 174 | struct device *bus_find_device_by_name(struct bus_type *bus, | 179 | /** |
| 175 | struct device *start, | 180 | * bus_find_device_by_name - device iterator for locating a particular device |
| 176 | const char *name); | 181 | * of a specific name. |
| 182 | * @bus: bus type | ||
| 183 | * @start: Device to begin with | ||
| 184 | * @name: name of the device to match | ||
| 185 | */ | ||
| 186 | static inline struct device *bus_find_device_by_name(struct bus_type *bus, | ||
| 187 | struct device *start, | ||
| 188 | const char *name) | ||
| 189 | { | ||
| 190 | return bus_find_device(bus, start, name, device_match_name); | ||
| 191 | } | ||
| 192 | |||
| 193 | /** | ||
| 194 | * bus_find_device_by_of_node : device iterator for locating a particular device | ||
| 195 | * matching the of_node. | ||
| 196 | * @bus: bus type | ||
| 197 | * @np: of_node of the device to match. | ||
| 198 | */ | ||
| 199 | static inline struct device * | ||
| 200 | bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np) | ||
| 201 | { | ||
| 202 | return bus_find_device(bus, NULL, np, device_match_of_node); | ||
| 203 | } | ||
| 204 | |||
| 205 | /** | ||
| 206 | * bus_find_device_by_fwnode : device iterator for locating a particular device | ||
| 207 | * matching the fwnode. | ||
| 208 | * @bus: bus type | ||
| 209 | * @fwnode: fwnode of the device to match. | ||
| 210 | */ | ||
| 211 | static inline struct device * | ||
| 212 | bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwnode) | ||
| 213 | { | ||
| 214 | return bus_find_device(bus, NULL, fwnode, device_match_fwnode); | ||
| 215 | } | ||
| 216 | |||
| 217 | /** | ||
| 218 | * bus_find_device_by_devt : device iterator for locating a particular device | ||
| 219 | * matching the device type. | ||
| 220 | * @bus: bus type | ||
| 221 | * @devt: device type of the device to match. | ||
| 222 | */ | ||
| 223 | static inline struct device *bus_find_device_by_devt(struct bus_type *bus, | ||
| 224 | dev_t devt) | ||
| 225 | { | ||
| 226 | return bus_find_device(bus, NULL, &devt, device_match_devt); | ||
| 227 | } | ||
| 228 | |||
| 229 | /** | ||
| 230 | * bus_find_next_device - Find the next device after a given device in a | ||
| 231 | * given bus. | ||
| 232 | */ | ||
| 233 | static inline struct device * | ||
| 234 | bus_find_next_device(struct bus_type *bus,struct device *cur) | ||
| 235 | { | ||
| 236 | return bus_find_device(bus, cur, NULL, device_match_any); | ||
| 237 | } | ||
| 238 | |||
| 239 | #ifdef CONFIG_ACPI | ||
| 240 | struct acpi_device; | ||
| 241 | |||
| 242 | /** | ||
| 243 | * bus_find_device_by_acpi_dev : device iterator for locating a particular device | ||
| 244 | * matching the ACPI COMPANION device. | ||
| 245 | * @bus: bus type | ||
| 246 | * @adev: ACPI COMPANION device to match. | ||
| 247 | */ | ||
| 248 | static inline struct device * | ||
| 249 | bus_find_device_by_acpi_dev(struct bus_type *bus, const struct acpi_device *adev) | ||
| 250 | { | ||
| 251 | return bus_find_device(bus, NULL, adev, device_match_acpi_dev); | ||
| 252 | } | ||
| 253 | #else | ||
| 254 | static inline struct device * | ||
| 255 | bus_find_device_by_acpi_dev(struct bus_type *bus, const void *adev) | ||
| 256 | { | ||
| 257 | return NULL; | ||
| 258 | } | ||
| 259 | #endif | ||
| 260 | |||
| 177 | struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, | 261 | struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, |
| 178 | struct device *hint); | 262 | struct device *hint); |
| 179 | int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, | 263 | int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, |
| @@ -342,6 +426,83 @@ struct device *driver_find_device(struct device_driver *drv, · 162 unmodified lines | |||
| 342 | struct device *start, const void *data, | 426 | struct device *start, const void *data, |
| 343 | int (*match)(struct device *dev, const void *data)); | 427 | int (*match)(struct device *dev, const void *data)); |
| 344 | 428 | ||
| 429 | /** | ||
| 430 | * driver_find_device_by_name - device iterator for locating a particular device | ||
| 431 | * of a specific name. | ||
| 432 | * @driver: the driver we're iterating | ||
| 433 | * @name: name of the device to match | ||
| 434 | */ | ||
| 435 | static inline struct device *driver_find_device_by_name(struct device_driver *drv, | ||
| 436 | const char *name) | ||
| 437 | { | ||
| 438 | return driver_find_device(drv, NULL, name, device_match_name); | ||
| 439 | } | ||
| 440 | |||
| 441 | /** | ||
| 442 | * driver_find_device_by_of_node- device iterator for locating a particular device | ||
| 443 | * by of_node pointer. | ||
| 444 | * @driver: the driver we're iterating | ||
| 445 | * @np: of_node pointer to match. | ||
| 446 | */ | ||
| 447 | static inline struct device * | ||
| 448 | driver_find_device_by_of_node(struct device_driver *drv, | ||
| 449 | const struct device_node *np) | ||
| 450 | { | ||
| 451 | return driver_find_device(drv, NULL, np, device_match_of_node); | ||
| 452 | } | ||
| 453 | |||
| 454 | /** | ||
| 455 | * driver_find_device_by_fwnode- device iterator for locating a particular device | ||
| 456 | * by fwnode pointer. | ||
| 457 | * @driver: the driver we're iterating | ||
| 458 | * @fwnode: fwnode pointer to match. | ||
| 459 | */ | ||
| 460 | static inline struct device * | ||
| 461 | driver_find_device_by_fwnode(struct device_driver *drv, | ||
| 462 | const struct fwnode_handle *fwnode) | ||
| 463 | { | ||
| 464 | return driver_find_device(drv, NULL, fwnode, device_match_fwnode); | ||
| 465 | } | ||
| 466 | |||
| 467 | /** | ||
| 468 | * driver_find_device_by_devt- device iterator for locating a particular device | ||
| 469 | * by devt. | ||
| 470 | * @driver: the driver we're iterating | ||
| 471 | * @devt: devt pointer to match. | ||
| 472 | */ | ||
| 473 | static inline struct device *driver_find_device_by_devt(struct device_driver *drv, | ||
| 474 | dev_t devt) | ||
| 475 | { | ||
| 476 | return driver_find_device(drv, NULL, &devt, device_match_devt); | ||
| 477 | } | ||
| 478 | |||
| 479 | static inline struct device *driver_find_next_device(struct device_driver *drv, | ||
| 480 | struct device *start) | ||
| 481 | { | ||
| 482 | return driver_find_device(drv, start, NULL, device_match_any); | ||
| 483 | } | ||
| 484 | |||
| 485 | #ifdef CONFIG_ACPI | ||
| 486 | /** | ||
| 487 | * driver_find_device_by_acpi_dev : device iterator for locating a particular | ||
| 488 | * device matching the ACPI_COMPANION device. | ||
| 489 | * @driver: the driver we're iterating | ||
| 490 | * @adev: ACPI_COMPANION device to match. | ||
| 491 | */ | ||
| 492 | static inline struct device * | ||
| 493 | driver_find_device_by_acpi_dev(struct device_driver *drv, | ||
| 494 | const struct acpi_device *adev) | ||
| 495 | { | ||
| 496 | return driver_find_device(drv, NULL, adev, device_match_acpi_dev); | ||
| 497 | } | ||
| 498 | #else | ||
| 499 | static inline struct device * | ||
| 500 | driver_find_device_by_acpi_dev(struct device_driver *drv, const void *adev) | ||
| 501 | { | ||
| 502 | return NULL; | ||
| 503 | } | ||
| 504 | #endif | ||
| 505 | |||
| 345 | void driver_deferred_probe_add(struct device *dev); | 506 | void driver_deferred_probe_add(struct device *dev); |
| 346 | int driver_deferred_probe_check_state(struct device *dev); | 507 | int driver_deferred_probe_check_state(struct device *dev); |
| 347 | int driver_deferred_probe_check_state_continue(struct device *dev); | 508 | int driver_deferred_probe_check_state_continue(struct device *dev); |
| @@ -471,6 +632,76 @@ extern struct device *class_find_device(struct class *class, · 123 unmodified lines | |||
| 471 | struct device *start, const void *data, | 632 | struct device *start, const void *data, |
| 472 | int (*match)(struct device *, const void *)); | 633 | int (*match)(struct device *, const void *)); |
| 473 | 634 | ||
| 635 | /** | ||
| 636 | * class_find_device_by_name - device iterator for locating a particular device | ||
| 637 | * of a specific name. | ||
| 638 | * @class: class type | ||
| 639 | * @name: name of the device to match | ||
| 640 | */ | ||
| 641 | static inline struct device *class_find_device_by_name(struct class *class, | ||
| 642 | const char *name) | ||
| 643 | { | ||
| 644 | return class_find_device(class, NULL, name, device_match_name); | ||
| 645 | } | ||
| 646 | |||
| 647 | /** | ||
| 648 | * class_find_device_by_of_node : device iterator for locating a particular device | ||
| 649 | * matching the of_node. | ||
| 650 | * @class: class type | ||
| 651 | * @np: of_node of the device to match. | ||
| 652 | */ | ||
| 653 | static inline struct device * | ||
| 654 | class_find_device_by_of_node(struct class *class, const struct device_node *np) | ||
| 655 | { | ||
| 656 | return class_find_device(class, NULL, np, device_match_of_node); | ||
| 657 | } | ||
| 658 | |||
| 659 | /** | ||
| 660 | * class_find_device_by_fwnode : device iterator for locating a particular device | ||
| 661 | * matching the fwnode. | ||
| 662 | * @class: class type | ||
| 663 | * @fwnode: fwnode of the device to match. | ||
| 664 | */ | ||
| 665 | static inline struct device * | ||
| 666 | class_find_device_by_fwnode(struct class *class, | ||
| 667 | const struct fwnode_handle *fwnode) | ||
| 668 | { | ||
| 669 | return class_find_device(class, NULL, fwnode, device_match_fwnode); | ||
| 670 | } | ||
| 671 | |||
| 672 | /** | ||
| 673 | * class_find_device_by_devt : device iterator for locating a particular device | ||
| 674 | * matching the device type. | ||
| 675 | * @class: class type | ||
| 676 | * @devt: device type of the device to match. | ||
| 677 | */ | ||
| 678 | static inline struct device *class_find_device_by_devt(struct class *class, | ||
| 679 | dev_t devt) | ||
| 680 | { | ||
| 681 | return class_find_device(class, NULL, &devt, device_match_devt); | ||
| 682 | } | ||
| 683 | |||
| 684 | #ifdef CONFIG_ACPI | ||
| 685 | struct acpi_device; | ||
| 686 | /** | ||
| 687 | * class_find_device_by_acpi_dev : device iterator for locating a particular | ||
| 688 | * device matching the ACPI_COMPANION device. | ||
| 689 | * @class: class type | ||
| 690 | * @adev: ACPI_COMPANION device to match. | ||
| 691 | */ | ||
| 692 | static inline struct device * | ||
| 693 | class_find_device_by_acpi_dev(struct class *class, const struct acpi_device *adev) | ||
| 694 | { | ||
| 695 | return class_find_device(class, NULL, adev, device_match_acpi_dev); | ||
| 696 | } | ||
| 697 | #else | ||
| 698 | static inline struct device * | ||
| 699 | class_find_device_by_acpi_dev(struct class *class, const void *adev) | ||
| 700 | { | ||
| 701 | return NULL; | ||
| 702 | } | ||
| 703 | #endif | ||
| 704 | |||
| 474 | struct class_attribute { | 705 | struct class_attribute { |
| 475 | struct attribute attr; | 706 | struct attribute attr; |
| 476 | ssize_t (*show)(struct class *class, struct class_attribute *attr, | 707 | ssize_t (*show)(struct class *class, struct class_attribute *attr, |
| @@ -51,6 +51,9 @@ extern struct device platform_bus; · 50 unmodified lines | |||
| 51 | extern void arch_setup_pdev_archdata(struct platform_device *); | 51 | extern void arch_setup_pdev_archdata(struct platform_device *); |
| 52 | extern struct resource *platform_get_resource(struct platform_device *, | 52 | extern struct resource *platform_get_resource(struct platform_device *, |
| 53 | unsigned int, unsigned int); | 53 | unsigned int, unsigned int); |
| 54 | extern struct device * | ||
| 55 | platform_find_device_by_driver(struct device *start, | ||
| 56 | const struct device_driver *drv); | ||
| 54 | extern void __iomem * | 57 | extern void __iomem * |
| 55 | devm_platform_ioremap_resource(struct platform_device *pdev, | 58 | devm_platform_ioremap_resource(struct platform_device *pdev, |
| 56 | unsigned int index); | 59 | unsigned int index); |
| @@ -23,11 +23,6 @@ · 22 unmodified lines | |||
| 23 | LIST_HEAD(cfg802154_rdev_list); | 23 | LIST_HEAD(cfg802154_rdev_list); |
| 24 | int cfg802154_rdev_list_generation; | 24 | int cfg802154_rdev_list_generation; |
| 25 | 25 | ||
| 26 | static int wpan_phy_match(struct device *dev, const void *data) | ||
| 27 | { | ||
| 28 | return !strcmp(dev_name(dev), (const char *)data); | ||
| 29 | } | ||
| 30 | |||
| 31 | struct wpan_phy *wpan_phy_find(const char *str) | 26 | struct wpan_phy *wpan_phy_find(const char *str) |
| 32 | { | 27 | { |
| 33 | struct device *dev; | 28 | struct device *dev; |
| @@ -35,7 +30,7 @@ struct wpan_phy *wpan_phy_find(const char *str) · 1 unmodified line | |||
| 35 | if (WARN_ON(!str)) | 30 | if (WARN_ON(!str)) |
| 36 | return NULL; | 31 | return NULL; |
| 37 | 32 | ||
| 38 | dev = class_find_device(&wpan_phy_class, NULL, str, wpan_phy_match); | 33 | dev = class_find_device_by_name(&wpan_phy_class, str); |
| 39 | if (!dev) | 34 | if (!dev) |
| 40 | return NULL; | 35 | return NULL; |
| 41 | 36 | ||
| @@ -422,11 +422,6 @@ static const struct dailink_match_data dailink_match[] = { · 421 unmodified lines | |||
| 422 | }, | 422 | }, |
| 423 | }; | 423 | }; |
| 424 | 424 | ||
| 425 | static int of_dev_node_match(struct device *dev, const void *data) | ||
| 426 | { | ||
| 427 | return dev->of_node == data; | ||
| 428 | } | ||
| 429 | |||
| 430 | static int rockchip_sound_codec_node_match(struct device_node *np_codec) | 425 | static int rockchip_sound_codec_node_match(struct device_node *np_codec) |
| 431 | { | 426 | { |
| 432 | struct device *dev; | 427 | struct device *dev; |
| @@ -438,8 +433,8 @@ static int rockchip_sound_codec_node_match(struct device_node *np_codec) · 5 unmodified lines | |||
| 438 | continue; | 433 | continue; |
| 439 | 434 | ||
| 440 | if (dailink_match[i].bus_type) { | 435 | if (dailink_match[i].bus_type) { |
| 441 | dev = bus_find_device(dailink_match[i].bus_type, NULL, | 436 | dev = bus_find_device_by_of_node(dailink_match[i].bus_type, |
| 442 | np_codec, of_dev_node_match); | 437 | np_codec); |
| 443 | if (!dev) | 438 | if (!dev) |
| 444 | continue; | 439 | continue; |
| 445 | put_device(dev); | 440 | put_device(dev); |