linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Suzuki K Poulose <suzuki.poulose@arm.com>
To: linux-kernel@vger.kernel.org
Cc: gregkh@linuxfoundation.org, rafael@kernel.org,
	suzuki.poulose@arm.com, "Inki Dae" <inki.dae@samsung.com>,
	"Seung-Woo Kim" <sw0312.kim@samsung.com>,
	"Sandy Huang" <hjc@rock-chips.com>,
	"Heiko Stübner" <heiko@sntech.de>,
	"Eric Anholt" <eric@anholt.net>
Subject: [RFC PATCH 20/57] platform: Add a helper to find device by driver
Date: Mon,  3 Jun 2019 16:49:46 +0100	[thread overview]
Message-ID: <1559577023-558-21-git-send-email-suzuki.poulose@arm.com> (raw)
In-Reply-To: <1559577023-558-1-git-send-email-suzuki.poulose@arm.com>

There are a couple of places where we reuse platform specific
match to find a device. Instead of spilling the global varilable
everywhere, let us provide a helper to do the same.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Inki Dae <inki.dae@samsung.com>
Cc: Seung-Woo Kim <sw0312.kim@samsung.com>
Cc: Sandy Huang <hjc@rock-chips.com>
Cc: "Heiko Stübner" <heiko@sntech.de>
Cc: Eric Anholt <eric@anholt.net>
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/rockchip/rockchip_drm_drv.c |  3 +--
 drivers/gpu/drm/vc4/vc4_drv.c               |  3 +--
 include/linux/platform_device.h             |  3 +++
 5 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 4d17298..daca44f 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, (void *)drv,
+			       (int (*)(struct device *, 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 ba8932a..b357e0d 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
@@ -244,9 +244,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) ||
@@ -414,9 +412,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/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
index cb938d3..4eb4fb8 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
@@ -338,8 +338,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 6d9be20..d159eb5 100644
--- a/drivers/gpu/drm/vc4/vc4_drv.c
+++ b/drivers/gpu/drm/vc4/vc4_drv.c
@@ -236,8 +236,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 cc46485..a82b3ec 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -52,6 +52,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 dev*,
+			       const struct device_driver *drv);
 extern void __iomem *
 devm_platform_ioremap_resource(struct platform_device *pdev,
 			       unsigned int index);
-- 
2.7.4


  parent reply	other threads:[~2019-06-03 15:54 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1559577023-558-1-git-send-email-suzuki.poulose@arm.com>
2019-06-03 15:49 ` [RFC PATCH 01/57] drivers: s390/cio: Use driver_for_each_device Suzuki K Poulose
2019-06-14 13:32   ` Suzuki K Poulose
2019-06-17  9:21   ` Sebastian Ott
2019-06-03 15:49 ` [RFC PATCH 02/57] drivers: ipmi: Drop device reference Suzuki K Poulose
2019-06-03 17:01   ` Corey Minyard
2019-06-03 17:03     ` Suzuki K Poulose
2019-06-03 19:09   ` Greg KH
2019-06-03 19:59     ` Corey Minyard
2019-06-04  7:43       ` Greg KH
2019-06-03 15:49 ` [RFC PATCH 03/57] drivers: coresight: Drop device references found via bus_find_device Suzuki K Poulose
2019-06-03 19:08   ` Greg KH
2019-06-04  8:19     ` Suzuki K Poulose
2019-06-03 15:49 ` [RFC PATCH 04/57] drivers: Add generic match helper to match the device of_node Suzuki K Poulose
2019-06-03 15:49 ` [RFC PATCH 05/57] drm: mipi_dsi: Use bus_find_device_by_of_node() helper Suzuki K Poulose
2019-06-03 15:49 ` [RFC PATCH 06/57] drivers: i2c: i2c-core: Use bus_find_device_by_of_node helper Suzuki K Poulose
2019-06-03 15:49 ` [RFC PATCH 07/57] drivers: nvmem: " Suzuki K Poulose
2019-06-03 15:49 ` [RFC PATCH 08/57] drivers: spi: " Suzuki K Poulose
2019-06-03 16:04   ` Mark Brown
2019-06-03 15:49 ` [RFC PATCH 09/57] drivers: sound: rockchip: rk3399: " Suzuki K Poulose
2019-06-03 16:02   ` Mark Brown
2019-06-03 15:49 ` [RFC PATCH 10/57] drivers: coresight: " Suzuki K Poulose
2019-06-03 15:49 ` [RFC PATCH 11/57] of: mdio: " Suzuki K Poulose
2019-06-03 16:00   ` Andrew Lunn
2019-06-03 15:49 ` [RFC PATCH 12/57] of: platform: " Suzuki K Poulose
2019-06-10 20:44   ` Rob Herring
2019-06-03 15:49 ` [RFC PATCH 13/57] drivers: Add generic helper for matching device by fwnode Suzuki K Poulose
2019-06-03 15:49 ` [RFC PATCH 14/57] drivers: devcon: Use bus_find_device_by_fwnode helper Suzuki K Poulose
2019-06-03 15:49 ` [RFC PATCH 15/57] net: hisilicon: hnfs:Use " Suzuki K Poulose
2019-06-03 15:49 ` [RFC PATCH 16/57] net: hns_roce: Use " Suzuki K Poulose
2019-06-03 16:05   ` Jason Gunthorpe
2019-06-03 15:49 ` [RFC PATCH 17/57] drivers: Add generic match by device type helper Suzuki K Poulose
2019-06-03 15:49 ` [RFC PATCH 18/57] drivers: intel_th: Use bus_find_device_by_devt helper Suzuki K Poulose
2019-06-03 15:49 ` [RFC PATCH 19/57] drivers: usb: core: " Suzuki K Poulose
2019-06-03 15:49 ` Suzuki K Poulose [this message]
2019-06-04 13:29   ` [RFC PATCH 20/57] platform: Add a helper to find device by driver Heiko Stuebner
2019-06-04 13:31     ` Suzuki K Poulose
2019-06-03 15:49 ` [RFC PATCH 21/57] drivers: Add generic match helper by ACPI_COMPANION device Suzuki K Poulose
2019-06-03 15:49 ` [RFC PATCH 22/57] drivers: i2c: Use generic helper to match device by acpi_dev Suzuki K Poulose
2019-06-04  9:27   ` Mika Westerberg
2019-06-06 20:03   ` Wolfram Sang
2019-06-10 12:49     ` Suzuki K Poulose
2019-06-03 15:49 ` [RFC PATCH 23/57] drivers: spi: Use bus_find_device_by_acpi_dev match helper Suzuki K Poulose
2019-06-03 16:04   ` Mark Brown
2019-06-03 15:49 ` [RFC PATCH 24/57] drivers: staging: most-core: Use bus_find_device_by_name Suzuki K Poulose
2019-06-03 15:49 ` [RFC PATCH 25/57] drivers: Add generic match by name helper Suzuki K Poulose
2019-06-03 15:49 ` [RFC PATCH 26/57] drivers: acpi: Clean up acpi_dev_match_cb Suzuki K Poulose
2019-06-03 15:49 ` [RFC PATCH 27/57] drivers: Unify the match prototype for bus_find_device with class_find_device Suzuki K Poulose
2019-06-04  6:52   ` Harald Freudenberger
2019-06-04 11:26   ` Rafael J. Wysocki
2019-06-04 11:39     ` Suzuki K Poulose
2019-06-03 15:49 ` [RFC PATCH 28/57] drivers: class: Add variants of class_find_device() Suzuki K Poulose
2019-06-03 15:49 ` [RFC PATCH 29/57] drivers: stm: Use class_find_device_by_name() helper Suzuki K Poulose
2019-06-03 15:49 ` [RFC PATCH 30/57] drivers: leds: " Suzuki K Poulose
2019-06-04  8:35   ` Pavel Machek
2019-06-03 15:49 ` [RFC PATCH 31/57] drivers: rtc: " Suzuki K Poulose
2019-06-03 15:49 ` [RFC PATCH 32/57] drivers: s390-crypto: Use class_device_find_by_name() helper Suzuki K Poulose
2019-06-04  6:45   ` Harald Freudenberger
2019-06-03 15:49 ` [RFC PATCH 33/57] drivers: usb: Use class_find_device_by_name() helper Suzuki K Poulose
2019-06-03 15:50 ` [RFC PATCH 34/57] drivers: ieee802154: " Suzuki K Poulose
2019-06-03 15:50 ` [RFC PATCH 35/57] drivers: core: Reuse generic match by device type helper Suzuki K Poulose
2019-06-03 15:50 ` [RFC PATCH 36/57] drivers: mei: Use class_find_device_by_devt match helper Suzuki K Poulose
2019-06-03 18:00   ` Winkler, Tomas
2019-06-04  8:27     ` Suzuki K Poulose
2019-06-03 15:50 ` [RFC PATCH 37/57] drivers: s390: zcrypt: Use class_find_device_by_devt helper Suzuki K Poulose
2019-06-04  6:47   ` Harald Freudenberger
2019-06-03 15:50 ` [RFC PATCH 38/57] drivers: fpga: Use generic helpers to match by of_node Suzuki K Poulose
2019-06-03 15:50 ` [RFC PATCH 39/57] drivers: mux: Use class_find_device_by_of_node helper Suzuki K Poulose
2019-06-03 16:22   ` Peter Rosin
2019-06-03 16:45     ` Suzuki K Poulose
2019-06-03 18:39       ` Peter Rosin
2019-06-03 15:50 ` [RFC PATCH 40/57] drivers: spi: " Suzuki K Poulose
2019-06-03 15:50 ` [RFC PATCH 41/57] drivers: net: phy: " Suzuki K Poulose
2019-06-03 16:02   ` Andrew Lunn
2019-06-03 15:50 ` [RFC PATCH 42/57] drivers: regulator: " Suzuki K Poulose
2019-06-03 16:04   ` Mark Brown
2019-06-03 15:50 ` [RFC PATCH 43/57] drivers: tty : " Suzuki K Poulose
2019-06-03 15:50 ` [RFC PATCH 44/57] drivers: usb : Use class_find_device_by_fwnode() helper Suzuki K Poulose
2019-06-03 15:50 ` [RFC PATCH 45/57] drivers: driver_find_device: Unify the match function Suzuki K Poulose
2019-06-03 15:50 ` [RFC PATCH 46/57] driver: Add variants of driver_find_device() Suzuki K Poulose
2019-06-03 19:10   ` Greg KH
2019-06-04  8:45     ` Suzuki K Poulose
2019-06-04 10:55       ` Suzuki K Poulose
2019-06-04 11:32         ` Greg KH
2019-06-04 11:44           ` Suzuki K Poulose
2019-06-04 11:33         ` Rafael J. Wysocki
2019-06-03 19:11   ` Greg KH
2019-06-04  8:36     ` Suzuki K Poulose
2019-06-04  8:46       ` Greg KH
2019-06-03 19:12   ` Greg KH
2019-06-04  8:33     ` Suzuki K Poulose
2019-06-03 15:50 ` [RFC PATCH 47/57] drivers: mfd: Use driver_find_device_by_name helper Suzuki K Poulose
2019-06-04  9:45   ` Arnd Bergmann
2019-06-04 11:42     ` Suzuki K Poulose
2019-06-04 11:47       ` Arnd Bergmann
2019-06-03 15:50 ` [RFC PATCH 48/57] drivers: s390: cio: Use driver_find_by_name() helper Suzuki K Poulose
2019-06-03 15:50 ` [RFC PATCH 49/57] drivers: mfd: altera: Use driver_find_device_by_of_node() helper Suzuki K Poulose
2019-06-04 16:13   ` Thor Thayer
2019-06-03 15:50 ` [RFC PATCH 50/57] drivers: iommu: arm-smmu: Use driver_find_device_by_fwnode() helper Suzuki K Poulose
2019-06-03 15:50 ` [RFC PATCH 51/57] drivers: Add generic helper to match all devices Suzuki K Poulose
2019-06-03 15:50 ` [RFC PATCH 52/57] drivers: tegra: Use driver_find_device_by_of_node() helper Suzuki K Poulose
2019-06-03 15:50 ` [RFC PATCH 53/57] drivers: Introduce bus_find_next_device() helper Suzuki K Poulose
2019-06-03 15:50 ` [RFC PATCH 54/57] drivers: pci: Use " Suzuki K Poulose
2019-06-03 15:50 ` [RFC PATCH 55/57] drivers: scsi: " Suzuki K Poulose
2019-06-03 15:50 ` [RFC PATCH 56/57] drivers: Introduce driver_find_next_device() helper Suzuki K Poulose
2019-06-03 15:50 ` [RFC PATCH 57/57] drivers: i2c-amd: Use " Suzuki K Poulose

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=1559577023-558-21-git-send-email-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-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).