From: Suzuki K Poulose <suzuki.poulose@arm.com>
To: linux-kernel@vger.kernel.org
Cc: gregkh@linuxfoundation.org, rafael@kernel.org,
linux-arm-kernel@lists.infradead.org,
"Suzuki K Poulose" <suzuki.poulose@arm.com>,
"Eric Anholt" <eric@anholt.net>,
"Heiko Stübner" <heiko@sntech.de>,
"Inki Dae" <inki.dae@samsung.com>,
"Sandy Huang" <hjc@rock-chips.com>,
"Seung-Woo Kim" <sw0312.kim@samsung.com>
Subject: [PATCH v3 7/7] platform: Add platform_find_device_by_driver() helper
Date: Tue, 23 Jul 2019 23:18:38 +0100 [thread overview]
Message-ID: <20190723221838.12024-8-suzuki.poulose@arm.com> (raw)
In-Reply-To: <20190723221838.12024-1-suzuki.poulose@arm.com>
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>
---
drivers/base/platform.c | 14 ++++++++++++++
drivers/gpu/drm/exynos/exynos_drm_drv.c | 9 +++------
drivers/gpu/drm/mcde/mcde_drv.c | 3 +--
drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 3 +--
drivers/gpu/drm/vc4/vc4_drv.c | 3 +--
include/linux/platform_device.h | 3 +++
6 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 506a0175a5a7..a174ce5ea17c 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -1197,6 +1197,20 @@ struct bus_type platform_bus_type = {
};
EXPORT_SYMBOL_GPL(platform_bus_type);
+/**
+ * platform_find_device_by_driver - Find a platform device with a given
+ * driver.
+ * @start: The device to start the search from.
+ * @drv: The device driver to look for.
+ */
+struct device *platform_find_device_by_driver(struct device *start,
+ const struct device_driver *drv)
+{
+ return bus_find_device(&platform_bus_type, start, drv,
+ (void *)platform_match);
+}
+EXPORT_SYMBOL_GPL(platform_find_device_by_driver);
+
int __init platform_bus_init(void)
{
int error;
diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c
index 58baf49d9926..badab94be2d6 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
@@ -242,9 +242,7 @@ static struct component_match *exynos_drm_match_add(struct device *dev)
if (!info->driver || !(info->flags & DRM_COMPONENT_DRIVER))
continue;
- while ((d = bus_find_device(&platform_bus_type, p,
- &info->driver->driver,
- (void *)platform_bus_type.match))) {
+ while ((d = platform_find_device_by_driver(p, &info->driver->driver))) {
put_device(p);
if (!(info->flags & DRM_FIMC_DEVICE) ||
@@ -412,9 +410,8 @@ static void exynos_drm_unregister_devices(void)
if (!info->driver || !(info->flags & DRM_VIRTUAL_DEVICE))
continue;
- while ((dev = bus_find_device(&platform_bus_type, NULL,
- &info->driver->driver,
- (void *)platform_bus_type.match))) {
+ while ((dev = platform_find_device_by_driver(NULL,
+ &info->driver->driver))) {
put_device(dev);
platform_device_unregister(to_platform_device(dev));
}
diff --git a/drivers/gpu/drm/mcde/mcde_drv.c b/drivers/gpu/drm/mcde/mcde_drv.c
index baf63fb6850a..c07abf9e201c 100644
--- a/drivers/gpu/drm/mcde/mcde_drv.c
+++ b/drivers/gpu/drm/mcde/mcde_drv.c
@@ -477,8 +477,7 @@ static int mcde_probe(struct platform_device *pdev)
struct device_driver *drv = &mcde_component_drivers[i]->driver;
struct device *p = NULL, *d;
- while ((d = bus_find_device(&platform_bus_type, p, drv,
- (void *)platform_bus_type.match))) {
+ while ((d = platform_find_device_by_driver(p, drv))) {
put_device(p);
component_match_add(dev, &match, mcde_compare_dev, d);
p = d;
diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
index 53d2c5bd61dc..38dc26376961 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
@@ -330,8 +330,7 @@ static struct component_match *rockchip_drm_match_add(struct device *dev)
struct device *p = NULL, *d;
do {
- d = bus_find_device(&platform_bus_type, p, &drv->driver,
- (void *)platform_bus_type.match);
+ d = platform_find_device_by_driver(p, &drv->driver);
put_device(p);
p = d;
diff --git a/drivers/gpu/drm/vc4/vc4_drv.c b/drivers/gpu/drm/vc4/vc4_drv.c
index bf11930e40e1..1551c8253bec 100644
--- a/drivers/gpu/drm/vc4/vc4_drv.c
+++ b/drivers/gpu/drm/vc4/vc4_drv.c
@@ -237,8 +237,7 @@ static void vc4_match_add_drivers(struct device *dev,
struct device_driver *drv = &drivers[i]->driver;
struct device *p = NULL, *d;
- while ((d = bus_find_device(&platform_bus_type, p, drv,
- (void *)platform_bus_type.match))) {
+ while ((d = platform_find_device_by_driver(p, drv))) {
put_device(p);
component_match_add(dev, match, compare_dev, d);
p = d;
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 9bc36b589827..37e15a935a42 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -51,6 +51,9 @@ extern struct device platform_bus;
extern void arch_setup_pdev_archdata(struct platform_device *);
extern struct resource *platform_get_resource(struct platform_device *,
unsigned int, unsigned int);
+extern struct device *
+platform_find_device_by_driver(struct device *start,
+ const struct device_driver *drv);
extern void __iomem *
devm_platform_ioremap_resource(struct platform_device *pdev,
unsigned int index);
--
2.21.0
next prev parent reply other threads:[~2019-07-23 22:19 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20190723221838.12024-1-suzuki.poulose@arm.com>
2019-07-23 22:18 ` [PATCH v3 1/7] drivers: Introduce device lookup variants by name Suzuki K Poulose
2019-07-25 15:42 ` Alexandre Belloni
2019-07-29 14:37 ` Heikki Krogerus
2019-07-23 22:18 ` [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node Suzuki K Poulose
2019-07-25 13:54 ` Lee Jones
2019-07-30 11:03 ` Greg KH
2019-07-25 19:25 ` Wolfram Sang
2019-07-25 21:01 ` Moritz Fischer
2019-07-26 17:18 ` Mark Brown
2019-07-23 22:18 ` [PATCH v3 3/7] drivers: Introduce device lookup variants by fwnode Suzuki K Poulose
2019-07-24 10:16 ` Robin Murphy
2019-07-25 17:10 ` Mathieu Poirier
2019-07-29 14:36 ` Heikki Krogerus
2019-07-23 22:18 ` [PATCH v3 4/7] drivers: Introduce device lookup variants by device type Suzuki K Poulose
2019-07-23 22:18 ` [PATCH v3 5/7] drivers: Introduce device lookup variants by ACPI_COMPANION device Suzuki K Poulose
2019-07-26 17:18 ` Mark Brown
2019-07-26 20:23 ` Wolfram Sang
2019-08-01 11:58 ` Andy Shevchenko
2019-08-01 12:08 ` Wolfram Sang
2019-08-01 12:21 ` Andy Shevchenko
2019-08-01 12:27 ` Wolfram Sang
2019-07-23 22:18 ` [PATCH v3 6/7] drivers: Add generic helper to match any device Suzuki K Poulose
2019-07-23 22:24 ` Bjorn Helgaas
2019-07-23 22:18 ` Suzuki K Poulose [this message]
2019-07-24 10:44 ` [PATCH v3 7/7] platform: Add platform_find_device_by_driver() helper Robin Murphy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190723221838.12024-8-suzuki.poulose@arm.com \
--to=suzuki.poulose@arm.com \
--cc=eric@anholt.net \
--cc=gregkh@linuxfoundation.org \
--cc=heiko@sntech.de \
--cc=hjc@rock-chips.com \
--cc=inki.dae@samsung.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=sw0312.kim@samsung.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).