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

platform: Add platform_find_device_by_driver() helper

Provide a helper to lookup platform devices by matching device
driver in order to avoid drivers trying to use platform bus
internals.

Cc: Eric Anholt <eric@anholt.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Heiko Stübner" <heiko@sntech.de>
Cc: Inki Dae <inki.dae@samsung.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Sandy Huang <hjc@rock-chips.com>
Cc: Seung-Woo Kim <sw0312.kim@samsung.com>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Link: https://lore.kernel.org/r/20190723221838.12024-8-suzuki.poulose@arm.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

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

+23 -12
+14
drivers/base/platform.c
··· 1197 1197 }; 1198 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 1214 int __init platform_bus_init(void) 1201 1215 { 1202 1216 int error;
+3 -6
drivers/gpu/drm/exynos/exynos_drm_drv.c
··· 242 242 if (!info->driver || !(info->flags & DRM_COMPONENT_DRIVER)) 243 243 continue; 244 244 245 - while ((d = bus_find_device(&platform_bus_type, p, 246 - &info->driver->driver, 247 - (void *)platform_bus_type.match))) { 245 + while ((d = platform_find_device_by_driver(p, &info->driver->driver))) { 248 246 put_device(p); 249 247 250 248 if (!(info->flags & DRM_FIMC_DEVICE) || ··· 410 412 if (!info->driver || !(info->flags & DRM_VIRTUAL_DEVICE)) 411 413 continue; 412 414 413 - while ((dev = bus_find_device(&platform_bus_type, NULL, 414 - &info->driver->driver, 415 - (void *)platform_bus_type.match))) { 415 + while ((dev = platform_find_device_by_driver(NULL, 416 + &info->driver->driver))) { 416 417 put_device(dev); 417 418 platform_device_unregister(to_platform_device(dev)); 418 419 }
+1 -2
drivers/gpu/drm/mcde/mcde_drv.c
··· 477 477 struct device_driver *drv = &mcde_component_drivers[i]->driver; 478 478 struct device *p = NULL, *d; 479 479 480 - while ((d = bus_find_device(&platform_bus_type, p, drv, 481 - (void *)platform_bus_type.match))) { 480 + while ((d = platform_find_device_by_driver(p, drv))) { 482 481 put_device(p); 483 482 component_match_add(dev, &match, mcde_compare_dev, d); 484 483 p = d;
+1 -2
drivers/gpu/drm/rockchip/rockchip_drm_drv.c
··· 330 330 struct device *p = NULL, *d; 331 331 332 332 do { 333 - d = bus_find_device(&platform_bus_type, p, &drv->driver, 334 - (void *)platform_bus_type.match); 333 + d = platform_find_device_by_driver(p, &drv->driver); 335 334 put_device(p); 336 335 p = d; 337 336
+1 -2
drivers/gpu/drm/vc4/vc4_drv.c
··· 237 237 struct device_driver *drv = &drivers[i]->driver; 238 238 struct device *p = NULL, *d; 239 239 240 - while ((d = bus_find_device(&platform_bus_type, p, drv, 241 - (void *)platform_bus_type.match))) { 240 + while ((d = platform_find_device_by_driver(p, drv))) { 242 241 put_device(p); 243 242 component_match_add(dev, match, compare_dev, d); 244 243 p = d;
+3
include/linux/platform_device.h
··· 51 51 extern void arch_setup_pdev_archdata(struct platform_device *); 52 52 extern struct resource *platform_get_resource(struct platform_device *, 53 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 57 extern void __iomem * 55 58 devm_platform_ioremap_resource(struct platform_device *pdev, 56 59 unsigned int index);