Skip to content

Commit 36f3313

Browse files
Suzuki K Poulosegregkh
authored andcommitted
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 <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: "Heiko Stübner" <[email protected]> Cc: Inki Dae <[email protected]> Cc: "Rafael J. Wysocki" <[email protected]> Cc: Sandy Huang <[email protected]> Cc: Seung-Woo Kim <[email protected]> Tested-by: Heiko Stuebner <[email protected]> Signed-off-by: Suzuki K Poulose <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6bf85ba commit 36f3313

File tree

6 files changed

+23
-12
lines changed

6 files changed

+23
-12
lines changed

drivers/base/platform.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,20 @@ struct bus_type platform_bus_type = {
11971197
};
11981198
EXPORT_SYMBOL_GPL(platform_bus_type);
11991199

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+
12001214
int __init platform_bus_init(void)
12011215
{
12021216
int error;

drivers/gpu/drm/exynos/exynos_drm_drv.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,7 @@ static struct component_match *exynos_drm_match_add(struct device *dev)
242242
if (!info->driver || !(info->flags & DRM_COMPONENT_DRIVER))
243243
continue;
244244

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))) {
248246
put_device(p);
249247

250248
if (!(info->flags & DRM_FIMC_DEVICE) ||
@@ -412,9 +410,8 @@ static void exynos_drm_unregister_devices(void)
412410
if (!info->driver || !(info->flags & DRM_VIRTUAL_DEVICE))
413411
continue;
414412

415-
while ((dev = bus_find_device(&platform_bus_type, NULL,
416-
&info->driver->driver,
417-
(void *)platform_bus_type.match))) {
413+
while ((dev = platform_find_device_by_driver(NULL,
414+
&info->driver->driver))) {
418415
put_device(dev);
419416
platform_device_unregister(to_platform_device(dev));
420417
}

drivers/gpu/drm/mcde/mcde_drv.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,7 @@ static int mcde_probe(struct platform_device *pdev)
477477
struct device_driver *drv = &mcde_component_drivers[i]->driver;
478478
struct device *p = NULL, *d;
479479

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))) {
482481
put_device(p);
483482
component_match_add(dev, &match, mcde_compare_dev, d);
484483
p = d;

drivers/gpu/drm/rockchip/rockchip_drm_drv.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,7 @@ static struct component_match *rockchip_drm_match_add(struct device *dev)
330330
struct device *p = NULL, *d;
331331

332332
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);
335334
put_device(p);
336335
p = d;
337336

drivers/gpu/drm/vc4/vc4_drv.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,7 @@ static void vc4_match_add_drivers(struct device *dev,
237237
struct device_driver *drv = &drivers[i]->driver;
238238
struct device *p = NULL, *d;
239239

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))) {
242241
put_device(p);
243242
component_match_add(dev, match, compare_dev, d);
244243
p = d;

include/linux/platform_device.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ extern struct device platform_bus;
5151
extern void arch_setup_pdev_archdata(struct platform_device *);
5252
extern struct resource *platform_get_resource(struct platform_device *,
5353
unsigned int, unsigned int);
54+
extern struct device *
55+
platform_find_device_by_driver(struct device *start,
56+
const struct device_driver *drv);
5457
extern void __iomem *
5558
devm_platform_ioremap_resource(struct platform_device *pdev,
5659
unsigned int index);

0 commit comments

Comments
 (0)