All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/7] drivers: Add generic device lookup helpers
@ 2019-07-23 22:18 ` Suzuki K Poulose
  0 siblings, 0 replies; 71+ messages in thread
From: Suzuki K Poulose @ 2019-07-23 22:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: gregkh, rafael, linux-arm-kernel, Suzuki K Poulose, Alan Tull,
	Alessandro Zummo, Alexander Aring, Alexander Shishkin,
	Alexandre Belloni, Andrew Lunn, Arnd Bergmann, Bjorn Helgaas,
	Daniel Vetter, Dan Murphy, David Airlie, David S. Miller,
	devicetree, Doug Ledford, dri-devel, Elie Morisse, Eric Anholt,
	Florian Fainelli, Frank Rowand, Harald Freudenberger,
	Heikki Krogerus, Heiko Carstens, Heiko Stübner,
	Heiner Kallweit, Inki Dae, Jacek Anaszewski,
	James E.J. Bottomley, Jason Gunthorpe, Jiri Slaby, Joe Perches,
	Joerg Roedel, Lee Jones, Len Brown, Liam Girdwood, linux-acpi,
	linux-fpga, linux-i2c, linux-leds, linux-rockchip, linux-rtc,
	linux-spi, linux-usb, linux-wpan, Maarten Lankhorst, Mark Brown,
	Martin K. Petersen, Mathieu Poirier, Maxime Coquelin,
	Maxime Ripard, Mika Westerberg, Moritz Fischer, Nehal Shah,
	Oliver Neukum, Pavel Machek, Peter Oberparleiter, Peter Rosin,
	Rafael J. Wysocki, Rob Herring, Robin Murphy, Sandy Huang,
	Sebastian Andrzej Siewior, Seung-Woo Kim, Shyam Sundar S K,
	Srinivas Kandagatla, Stefan Schmidt, Takashi Iwai, Thor Thayer,
	Tomas Winkler, Ulf Hansson, Will Deacon, Wolfram Sang

We have device iterators to find a particular device matching a criteria
for a given bus/class/driver. i.e, {bus,class,driver}_find_device()
APIs. The matching criteria is a function pointer for the APIs. Often the
lookup is based on a generic property of a device (e.g, name, fwnode, of node
pointer or device type) rather than a driver specific information. However, each
driver writes up its own "match" function, spilling the similar match functions
all over the driver subsystems.

This series adds device match helpers by generic device properties of a device.
Using these generic match functions, introduce wrappers to the existing
 *_find_device() helpers and converts the existing users to use the new wrappers.
 i.e,
	{bus/class/driver}_find_device_by_name()
	{bus/class/driver}_find_device_by_fwnode()
	{bus/class/driver}_find_device_by_devt()
	{bus/class/driver}_find_device_by_acpi_dev()

Also adds a wrapper for finding a platform device by driver, to avoid
spilling the platform_bus internals in the individual drivers. Applies
on 5.3-rc1.

   [0] git://linux-arm.org/linux-skp.git driver-cleanup/v3
RFC[1] https://marc.info/?i=1559577023-558-1-git-send-email-suzuki.poulose@arm.com
V1 [2] https://marc.info/?i=1559747630-28065-1-git-send-email-suzuki.poulose@arm.com
V2 [3] https://marc.info/?i=1560534863-15115-1-git-send-email-suzuki.poulose@arm.com

Changes since v2:
 - Merge the device match helper introduction patch with the variants
   of the helpers, for better review.
 - Use platform_find_device_by_driver for mcde drm driver.

Cc: Alan Tull <atull@kernel.org>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Dan Murphy <dmurphy@ti.com>
Cc: David Airlie <airlied@linux.ie>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: devicetree@vger.kernel.org
Cc: Doug Ledford <dledford@redhat.com>
Cc: dri-devel@lists.freedesktop.org
Cc: Elie Morisse <syniurge@gmail.com>
Cc: Eric Anholt <eric@anholt.net>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Frank Rowand <frowand.list@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Harald Freudenberger <freude@linux.ibm.com>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: "Heiko Stübner" <heiko@sntech.de>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: Heiner Kallweit <hkallweit1@gmail.com>
Cc: Inki Dae <inki.dae@samsung.com>
Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Joe Perches <joe@perches.com>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Lee Jones <lee.jones@linaro.org>
Cc: Len Brown <lenb@kernel.org>
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: linux-acpi@vger.kernel.org
Cc: linux-fpga@vger.kernel.org
Cc: linux-i2c@vger.kernel.org
Cc: linux-leds@vger.kernel.org
Cc: linux-rockchip@lists.infradead.org
Cc: linux-rtc@vger.kernel.org
Cc: linux-spi@vger.kernel.org
Cc: linux-usb@vger.kernel.org
Cc: linux-wpan@vger.kernel.org
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Maxime Ripard <maxime.ripard@bootlin.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Moritz Fischer <mdf@kernel.org>
Cc: Nehal Shah <nehal-bakulchandra.shah@amd.com>
Cc: Oliver Neukum <oneukum@suse.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Peter Oberparleiter <oberpar@linux.ibm.com>
Cc: Peter Rosin <peda@axentia.se>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Sandy Huang <hjc@rock-chips.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Seung-Woo Kim <sw0312.kim@samsung.com>
Cc: Shyam Sundar S K <shyam-sundar.s-k@amd.com>
Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Stefan Schmidt <stefan@datenfreihafen.org>
Cc: Takashi Iwai <tiwai@suse.com>
Cc: Thor Thayer <thor.thayer@linux.intel.com>
Cc: Tomas Winkler <tomas.winkler@intel.com>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Wolfram Sang <wsa@the-dreams.de>

Suzuki K Poulose (7):
  drivers: Introduce device lookup variants by name
  drivers: Introduce device lookup variants by of_node
  drivers: Introduce device lookup variants by fwnode
  drivers: Introduce device lookup variants by device type
  drivers: Introduce device lookup variants by ACPI_COMPANION device
  drivers: Add generic helper to match any device
  platform: Add platform_find_device_by_driver() helper

 drivers/amba/tegra-ahb.c                      |  11 +-
 drivers/base/bus.c                            |  24 --
 drivers/base/core.c                           |  39 ++-
 drivers/base/devcon.c                         |   8 +-
 drivers/base/platform.c                       |  14 ++
 drivers/fpga/fpga-bridge.c                    |   8 +-
 drivers/fpga/fpga-mgr.c                       |   8 +-
 drivers/gpu/drm/drm_mipi_dsi.c                |   7 +-
 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 +-
 .../hwtracing/coresight/coresight-platform.c  |  11 +-
 drivers/hwtracing/coresight/coresight-priv.h  |   2 -
 drivers/hwtracing/coresight/coresight.c       |   4 +-
 drivers/hwtracing/intel_th/core.c             |  10 +-
 drivers/hwtracing/stm/core.c                  |   9 +-
 drivers/i2c/busses/i2c-amd-mp2-pci.c          |   8 +-
 drivers/i2c/i2c-core-acpi.c                   |  11 +-
 drivers/i2c/i2c-core-of.c                     |   7 +-
 drivers/infiniband/hw/hns/hns_roce_hw_v1.c    |   8 +-
 drivers/iommu/arm-smmu-v3.c                   |   9 +-
 drivers/iommu/arm-smmu.c                      |   9 +-
 drivers/leds/led-class.c                      |   9 +-
 drivers/mfd/altera-sysmgr.c                   |  14 +-
 drivers/misc/mei/main.c                       |   9 +-
 drivers/mux/core.c                            |   7 +-
 .../ethernet/hisilicon/hns/hns_dsaf_misc.c    |   8 +-
 drivers/net/phy/mdio_bus.c                    |   9 +-
 drivers/nvmem/core.c                          |   7 +-
 drivers/of/of_mdio.c                          |   8 +-
 drivers/of/platform.c                         |   7 +-
 drivers/pci/probe.c                           |   7 +-
 drivers/regulator/of_regulator.c              |   7 +-
 drivers/rtc/interface.c                       |  11 +-
 drivers/s390/cio/ccwgroup.c                   |  18 +-
 drivers/s390/cio/device.c                     |  15 +-
 drivers/s390/crypto/zcrypt_api.c              |  22 +-
 drivers/scsi/scsi_proc.c                      |   9 +-
 drivers/spi/spi.c                             |  28 +--
 drivers/tty/tty_io.c                          |   8 +-
 drivers/usb/core/devio.c                      |   8 +-
 drivers/usb/roles/class.c                     |  16 +-
 drivers/usb/typec/class.c                     |  16 +-
 include/linux/device.h                        | 237 +++++++++++++++++-
 include/linux/platform_device.h               |   3 +
 net/ieee802154/core.c                         |   7 +-
 sound/soc/rockchip/rk3399_gru_sound.c         |   9 +-
 48 files changed, 341 insertions(+), 383 deletions(-)

-- 
2.21.0

^ permalink raw reply	[flat|nested] 71+ messages in thread

* [PATCH v3 0/7] drivers: Add generic device lookup helpers
@ 2019-07-23 22:18 ` Suzuki K Poulose
  0 siblings, 0 replies; 71+ messages in thread
From: Suzuki K Poulose @ 2019-07-23 22:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Lunn, Alexander Aring, Heikki Krogerus, Jacek Anaszewski,
	rafael, Alexander Shishkin, linux-fpga, Heiko Carstens,
	Alexandre Belloni, dri-devel, Peter Oberparleiter,
	Rafael J. Wysocki, Elie Morisse, Srinivas Kandagatla, linux-i2c,
	Pavel Machek, Shyam Sundar S K, Frank Rowand, linux-leds,
	linux-rtc, Maxime Ripard, Florian Fainelli, linux-acpi

We have device iterators to find a particular device matching a criteria
for a given bus/class/driver. i.e, {bus,class,driver}_find_device()
APIs. The matching criteria is a function pointer for the APIs. Often the
lookup is based on a generic property of a device (e.g, name, fwnode, of node
pointer or device type) rather than a driver specific information. However, each
driver writes up its own "match" function, spilling the similar match functions
all over the driver subsystems.

This series adds device match helpers by generic device properties of a device.
Using these generic match functions, introduce wrappers to the existing
 *_find_device() helpers and converts the existing users to use the new wrappers.
 i.e,
	{bus/class/driver}_find_device_by_name()
	{bus/class/driver}_find_device_by_fwnode()
	{bus/class/driver}_find_device_by_devt()
	{bus/class/driver}_find_device_by_acpi_dev()

Also adds a wrapper for finding a platform device by driver, to avoid
spilling the platform_bus internals in the individual drivers. Applies
on 5.3-rc1.

   [0] git://linux-arm.org/linux-skp.git driver-cleanup/v3
RFC[1] https://marc.info/?i=1559577023-558-1-git-send-email-suzuki.poulose@arm.com
V1 [2] https://marc.info/?i=1559747630-28065-1-git-send-email-suzuki.poulose@arm.com
V2 [3] https://marc.info/?i=1560534863-15115-1-git-send-email-suzuki.poulose@arm.com

Changes since v2:
 - Merge the device match helper introduction patch with the variants
   of the helpers, for better review.
 - Use platform_find_device_by_driver for mcde drm driver.

Cc: Alan Tull <atull@kernel.org>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Dan Murphy <dmurphy@ti.com>
Cc: David Airlie <airlied@linux.ie>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: devicetree@vger.kernel.org
Cc: Doug Ledford <dledford@redhat.com>
Cc: dri-devel@lists.freedesktop.org
Cc: Elie Morisse <syniurge@gmail.com>
Cc: Eric Anholt <eric@anholt.net>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Frank Rowand <frowand.list@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Harald Freudenberger <freude@linux.ibm.com>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: "Heiko Stübner" <heiko@sntech.de>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: Heiner Kallweit <hkallweit1@gmail.com>
Cc: Inki Dae <inki.dae@samsung.com>
Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Joe Perches <joe@perches.com>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Lee Jones <lee.jones@linaro.org>
Cc: Len Brown <lenb@kernel.org>
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: linux-acpi@vger.kernel.org
Cc: linux-fpga@vger.kernel.org
Cc: linux-i2c@vger.kernel.org
Cc: linux-leds@vger.kernel.org
Cc: linux-rockchip@lists.infradead.org
Cc: linux-rtc@vger.kernel.org
Cc: linux-spi@vger.kernel.org
Cc: linux-usb@vger.kernel.org
Cc: linux-wpan@vger.kernel.org
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Maxime Ripard <maxime.ripard@bootlin.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Moritz Fischer <mdf@kernel.org>
Cc: Nehal Shah <nehal-bakulchandra.shah@amd.com>
Cc: Oliver Neukum <oneukum@suse.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Peter Oberparleiter <oberpar@linux.ibm.com>
Cc: Peter Rosin <peda@axentia.se>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Sandy Huang <hjc@rock-chips.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Seung-Woo Kim <sw0312.kim@samsung.com>
Cc: Shyam Sundar S K <shyam-sundar.s-k@amd.com>
Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Stefan Schmidt <stefan@datenfreihafen.org>
Cc: Takashi Iwai <tiwai@suse.com>
Cc: Thor Thayer <thor.thayer@linux.intel.com>
Cc: Tomas Winkler <tomas.winkler@intel.com>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Wolfram Sang <wsa@the-dreams.de>

Suzuki K Poulose (7):
  drivers: Introduce device lookup variants by name
  drivers: Introduce device lookup variants by of_node
  drivers: Introduce device lookup variants by fwnode
  drivers: Introduce device lookup variants by device type
  drivers: Introduce device lookup variants by ACPI_COMPANION device
  drivers: Add generic helper to match any device
  platform: Add platform_find_device_by_driver() helper

 drivers/amba/tegra-ahb.c                      |  11 +-
 drivers/base/bus.c                            |  24 --
 drivers/base/core.c                           |  39 ++-
 drivers/base/devcon.c                         |   8 +-
 drivers/base/platform.c                       |  14 ++
 drivers/fpga/fpga-bridge.c                    |   8 +-
 drivers/fpga/fpga-mgr.c                       |   8 +-
 drivers/gpu/drm/drm_mipi_dsi.c                |   7 +-
 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 +-
 .../hwtracing/coresight/coresight-platform.c  |  11 +-
 drivers/hwtracing/coresight/coresight-priv.h  |   2 -
 drivers/hwtracing/coresight/coresight.c       |   4 +-
 drivers/hwtracing/intel_th/core.c             |  10 +-
 drivers/hwtracing/stm/core.c                  |   9 +-
 drivers/i2c/busses/i2c-amd-mp2-pci.c          |   8 +-
 drivers/i2c/i2c-core-acpi.c                   |  11 +-
 drivers/i2c/i2c-core-of.c                     |   7 +-
 drivers/infiniband/hw/hns/hns_roce_hw_v1.c    |   8 +-
 drivers/iommu/arm-smmu-v3.c                   |   9 +-
 drivers/iommu/arm-smmu.c                      |   9 +-
 drivers/leds/led-class.c                      |   9 +-
 drivers/mfd/altera-sysmgr.c                   |  14 +-
 drivers/misc/mei/main.c                       |   9 +-
 drivers/mux/core.c                            |   7 +-
 .../ethernet/hisilicon/hns/hns_dsaf_misc.c    |   8 +-
 drivers/net/phy/mdio_bus.c                    |   9 +-
 drivers/nvmem/core.c                          |   7 +-
 drivers/of/of_mdio.c                          |   8 +-
 drivers/of/platform.c                         |   7 +-
 drivers/pci/probe.c                           |   7 +-
 drivers/regulator/of_regulator.c              |   7 +-
 drivers/rtc/interface.c                       |  11 +-
 drivers/s390/cio/ccwgroup.c                   |  18 +-
 drivers/s390/cio/device.c                     |  15 +-
 drivers/s390/crypto/zcrypt_api.c              |  22 +-
 drivers/scsi/scsi_proc.c                      |   9 +-
 drivers/spi/spi.c                             |  28 +--
 drivers/tty/tty_io.c                          |   8 +-
 drivers/usb/core/devio.c                      |   8 +-
 drivers/usb/roles/class.c                     |  16 +-
 drivers/usb/typec/class.c                     |  16 +-
 include/linux/device.h                        | 237 +++++++++++++++++-
 include/linux/platform_device.h               |   3 +
 net/ieee802154/core.c                         |   7 +-
 sound/soc/rockchip/rk3399_gru_sound.c         |   9 +-
 48 files changed, 341 insertions(+), 383 deletions(-)

-- 
2.21.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* [PATCH v3 1/7] drivers: Introduce device lookup variants by name
  2019-07-23 22:18 ` Suzuki K Poulose
@ 2019-07-23 22:18   ` Suzuki K Poulose
  -1 siblings, 0 replies; 71+ messages in thread
From: Suzuki K Poulose @ 2019-07-23 22:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: gregkh, rafael, linux-arm-kernel, Suzuki K Poulose,
	Alessandro Zummo, Alexander Aring, Alexander Shishkin,
	Alexandre Belloni, Arnd Bergmann, Dan Murphy,
	Harald Freudenberger, Heikki Krogerus, Heiko Carstens,
	Jacek Anaszewski, Lee Jones, linux-leds, linux-rtc, linux-usb,
	linux-wpan, Maxime Coquelin, Pavel Machek, Peter Oberparleiter,
	Stefan Schmidt, Rafael J. Wysocki

Add a helper to match the device name for device lookup. Also
reuse this generic exported helper for the existing bus_find_device_by_name().
and add similar variants for driver/class.

Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Dan Murphy <dmurphy@ti.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Harald Freudenberger <freude@linux.ibm.com>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Cc: Lee Jones <lee.jones@linaro.org>
Cc: linux-leds@vger.kernel.org
Cc: linux-rtc@vger.kernel.org
Cc: linux-usb@vger.kernel.org
Cc: linux-wpan@vger.kernel.org
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Peter Oberparleiter <oberpar@linux.ibm.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Stefan Schmidt <stefan@datenfreihafen.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/base/bus.c               | 24 ------------------
 drivers/base/core.c              |  6 +++++
 drivers/hwtracing/stm/core.c     |  9 +------
 drivers/leds/led-class.c         |  9 +------
 drivers/rtc/interface.c          | 11 +--------
 drivers/s390/cio/ccwgroup.c      | 10 +-------
 drivers/s390/cio/device.c        | 15 +-----------
 drivers/s390/crypto/zcrypt_api.c | 11 +--------
 drivers/usb/roles/class.c        |  8 +-----
 drivers/usb/typec/class.c        |  8 +-----
 include/linux/device.h           | 42 +++++++++++++++++++++++++++++---
 net/ieee802154/core.c            |  7 +-----
 12 files changed, 54 insertions(+), 106 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index df3cac739813..a1d1e8256324 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -342,30 +342,6 @@ struct device *bus_find_device(struct bus_type *bus,
 }
 EXPORT_SYMBOL_GPL(bus_find_device);
 
-static int match_name(struct device *dev, const void *data)
-{
-	const char *name = data;
-
-	return sysfs_streq(name, dev_name(dev));
-}
-
-/**
- * bus_find_device_by_name - device iterator for locating a particular device of a specific name
- * @bus: bus type
- * @start: Device to begin with
- * @name: name of the device to match
- *
- * This is similar to the bus_find_device() function above, but it handles
- * searching by a name automatically, no need to write another strcmp matching
- * function.
- */
-struct device *bus_find_device_by_name(struct bus_type *bus,
-				       struct device *start, const char *name)
-{
-	return bus_find_device(bus, start, (void *)name, match_name);
-}
-EXPORT_SYMBOL_GPL(bus_find_device_by_name);
-
 /**
  * subsys_find_device_by_id - find a device with a specific enumeration number
  * @subsys: subsystem
diff --git a/drivers/base/core.c b/drivers/base/core.c
index da84a73f2ba6..fb83647d685a 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3357,6 +3357,12 @@ void device_set_of_node_from_dev(struct device *dev, const struct device *dev2)
 }
 EXPORT_SYMBOL_GPL(device_set_of_node_from_dev);
 
+int device_match_name(struct device *dev, const void *name)
+{
+	return sysfs_streq(dev_name(dev), name);
+}
+EXPORT_SYMBOL_GPL(device_match_name);
+
 int device_match_of_node(struct device *dev, const void *np)
 {
 	return dev->of_node == np;
diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
index e55b902560de..2b6bd42632e8 100644
--- a/drivers/hwtracing/stm/core.c
+++ b/drivers/hwtracing/stm/core.c
@@ -89,13 +89,6 @@ static struct class stm_class = {
 	.dev_groups	= stm_groups,
 };
 
-static int stm_dev_match(struct device *dev, const void *data)
-{
-	const char *name = data;
-
-	return sysfs_streq(name, dev_name(dev));
-}
-
 /**
  * stm_find_device() - find stm device by name
  * @buf:	character buffer containing the name
@@ -116,7 +109,7 @@ struct stm_device *stm_find_device(const char *buf)
 	if (!stm_core_up)
 		return NULL;
 
-	dev = class_find_device(&stm_class, NULL, buf, stm_dev_match);
+	dev = class_find_device_by_name(&stm_class, buf);
 	if (!dev)
 		return NULL;
 
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 4793e77808e2..d54c8e4d8954 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -213,13 +213,6 @@ static int led_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(leds_class_dev_pm_ops, led_suspend, led_resume);
 
-static int match_name(struct device *dev, const void *data)
-{
-	if (!dev_name(dev))
-		return 0;
-	return !strcmp(dev_name(dev), (char *)data);
-}
-
 static int led_classdev_next_name(const char *init_name, char *name,
 				  size_t len)
 {
@@ -230,7 +223,7 @@ static int led_classdev_next_name(const char *init_name, char *name,
 	strlcpy(name, init_name, len);
 
 	while ((ret < len) &&
-	       (dev = class_find_device(leds_class, NULL, name, match_name))) {
+	       (dev = class_find_device_by_name(leds_class, name))) {
 		put_device(dev);
 		ret = snprintf(name, len, "%s_%u", init_name, ++i);
 	}
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 72b7ddc43116..c93ef33b01d3 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -663,21 +663,12 @@ void rtc_update_irq(struct rtc_device *rtc,
 }
 EXPORT_SYMBOL_GPL(rtc_update_irq);
 
-static int __rtc_match(struct device *dev, const void *data)
-{
-	const char *name = data;
-
-	if (strcmp(dev_name(dev), name) == 0)
-		return 1;
-	return 0;
-}
-
 struct rtc_device *rtc_class_open(const char *name)
 {
 	struct device *dev;
 	struct rtc_device *rtc = NULL;
 
-	dev = class_find_device(rtc_class, NULL, name, __rtc_match);
+	dev = class_find_device_by_name(rtc_class, name);
 	if (dev)
 		rtc = to_rtc_device(dev);
 
diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
index c522e9313c50..d843e362c167 100644
--- a/drivers/s390/cio/ccwgroup.c
+++ b/drivers/s390/cio/ccwgroup.c
@@ -608,13 +608,6 @@ void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver)
 }
 EXPORT_SYMBOL(ccwgroup_driver_unregister);
 
-static int __ccwgroupdev_check_busid(struct device *dev, const void *id)
-{
-	const char *bus_id = id;
-
-	return (strcmp(bus_id, dev_name(dev)) == 0);
-}
-
 /**
  * get_ccwgroupdev_by_busid() - obtain device from a bus id
  * @gdrv: driver the device is owned by
@@ -631,8 +624,7 @@ struct ccwgroup_device *get_ccwgroupdev_by_busid(struct ccwgroup_driver *gdrv,
 {
 	struct device *dev;
 
-	dev = driver_find_device(&gdrv->driver, NULL, bus_id,
-				 __ccwgroupdev_check_busid);
+	dev = driver_find_device_by_name(&gdrv->driver, bus_id);
 
 	return dev ? to_ccwgroupdev(dev) : NULL;
 }
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index c421899be20f..131430bd48d9 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -1695,18 +1695,6 @@ int ccw_device_force_console(struct ccw_device *cdev)
 EXPORT_SYMBOL_GPL(ccw_device_force_console);
 #endif
 
-/*
- * get ccw_device matching the busid, but only if owned by cdrv
- */
-static int
-__ccwdev_check_busid(struct device *dev, const void *id)
-{
-	const char *bus_id = id;
-
-	return (strcmp(bus_id, dev_name(dev)) == 0);
-}
-
-
 /**
  * get_ccwdev_by_busid() - obtain device from a bus id
  * @cdrv: driver the device is owned by
@@ -1723,8 +1711,7 @@ struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
 {
 	struct device *dev;
 
-	dev = driver_find_device(&cdrv->driver, NULL, (void *)bus_id,
-				 __ccwdev_check_busid);
+	dev = driver_find_device_by_name(&cdrv->driver, bus_id);
 
 	return dev ? to_ccwdev(dev) : NULL;
 }
diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c
index 1058b4b5cc1e..38a5a47b8c9c 100644
--- a/drivers/s390/crypto/zcrypt_api.c
+++ b/drivers/s390/crypto/zcrypt_api.c
@@ -133,12 +133,6 @@ struct zcdn_device {
 static int zcdn_create(const char *name);
 static int zcdn_destroy(const char *name);
 
-/* helper function, matches the name for find_zcdndev_by_name() */
-static int __match_zcdn_name(struct device *dev, const void *data)
-{
-	return strcmp(dev_name(dev), (const char *)data) == 0;
-}
-
 /* helper function, matches the devt value for find_zcdndev_by_devt() */
 static int __match_zcdn_devt(struct device *dev, const void *data)
 {
@@ -152,10 +146,7 @@ static int __match_zcdn_devt(struct device *dev, const void *data)
  */
 static inline struct zcdn_device *find_zcdndev_by_name(const char *name)
 {
-	struct device *dev =
-		class_find_device(zcrypt_class, NULL,
-				  (void *) name,
-				  __match_zcdn_name);
+	struct device *dev = class_find_device_by_name(zcrypt_class, name);
 
 	return dev ? to_zcdn_dev(dev) : NULL;
 }
diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
index 86defca6623e..c8efe60e2465 100644
--- a/drivers/usb/roles/class.c
+++ b/drivers/usb/roles/class.c
@@ -90,11 +90,6 @@ static int switch_fwnode_match(struct device *dev, const void *fwnode)
 	return dev_fwnode(dev) == fwnode;
 }
 
-static int switch_name_match(struct device *dev, const void *name)
-{
-	return !strcmp((const char *)name, dev_name(dev));
-}
-
 static void *usb_role_switch_match(struct device_connection *con, int ep,
 				   void *data)
 {
@@ -107,8 +102,7 @@ static void *usb_role_switch_match(struct device_connection *con, int ep,
 		dev = class_find_device(role_class, NULL, con->fwnode,
 					switch_fwnode_match);
 	} else {
-		dev = class_find_device(role_class, NULL, con->endpoint[ep],
-					switch_name_match);
+		dev = class_find_device_by_name(role_class, con->endpoint[ep]);
 	}
 
 	return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index a18285a990a8..9b0d15b487e5 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -210,11 +210,6 @@ static int typec_port_fwnode_match(struct device *dev, const void *fwnode)
 	return dev_fwnode(dev) == fwnode;
 }
 
-static int typec_port_name_match(struct device *dev, const void *name)
-{
-	return !strcmp((const char *)name, dev_name(dev));
-}
-
 static void *typec_port_match(struct device_connection *con, int ep, void *data)
 {
 	struct device *dev;
@@ -227,8 +222,7 @@ static void *typec_port_match(struct device_connection *con, int ep, void *data)
 		return class_find_device(typec_class, NULL, con->fwnode,
 					 typec_port_fwnode_match);
 
-	dev = class_find_device(typec_class, NULL, con->endpoint[ep],
-				typec_port_name_match);
+	dev = class_find_device_by_name(typec_class, con->endpoint[ep]);
 
 	return dev ? dev : ERR_PTR(-EPROBE_DEFER);
 }
diff --git a/include/linux/device.h b/include/linux/device.h
index c330b75c6c57..3ba376b8b456 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -164,6 +164,7 @@ void subsys_dev_iter_init(struct subsys_dev_iter *iter,
 struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter);
 void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
 
+int device_match_name(struct device *dev, const void *name);
 int device_match_of_node(struct device *dev, const void *np);
 
 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
@@ -171,9 +172,20 @@ int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
 struct device *bus_find_device(struct bus_type *bus, struct device *start,
 			       const void *data,
 			       int (*match)(struct device *dev, const void *data));
-struct device *bus_find_device_by_name(struct bus_type *bus,
-				       struct device *start,
-				       const char *name);
+/**
+ * bus_find_device_by_name - device iterator for locating a particular device
+ * of a specific name.
+ * @bus: bus type
+ * @start: Device to begin with
+ * @name: name of the device to match
+ */
+static inline struct device *bus_find_device_by_name(struct bus_type *bus,
+						     struct device *start,
+						     const char *name)
+{
+	return bus_find_device(bus, start, name, device_match_name);
+}
+
 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
 					struct device *hint);
 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
@@ -342,6 +354,18 @@ struct device *driver_find_device(struct device_driver *drv,
 				  struct device *start, const void *data,
 				  int (*match)(struct device *dev, const void *data));
 
+/**
+ * driver_find_device_by_name - device iterator for locating a particular device
+ * of a specific name.
+ * @driver: the driver we're iterating
+ * @name: name of the device to match
+ */
+static inline struct device *driver_find_device_by_name(struct device_driver *drv,
+							const char *name)
+{
+	return driver_find_device(drv, NULL, name, device_match_name);
+}
+
 void driver_deferred_probe_add(struct device *dev);
 int driver_deferred_probe_check_state(struct device *dev);
 int driver_deferred_probe_check_state_continue(struct device *dev);
@@ -471,6 +495,18 @@ extern struct device *class_find_device(struct class *class,
 					struct device *start, const void *data,
 					int (*match)(struct device *, const void *));
 
+/**
+ * class_find_device_by_name - device iterator for locating a particular device
+ * of a specific name.
+ * @class: class type
+ * @name: name of the device to match
+ */
+static inline struct device *class_find_device_by_name(struct class *class,
+						       const char *name)
+{
+	return class_find_device(class, NULL, name, device_match_name);
+}
+
 struct class_attribute {
 	struct attribute attr;
 	ssize_t (*show)(struct class *class, struct class_attribute *attr,
diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
index 60b7ac56a1f5..de259b5170ab 100644
--- a/net/ieee802154/core.c
+++ b/net/ieee802154/core.c
@@ -23,11 +23,6 @@
 LIST_HEAD(cfg802154_rdev_list);
 int cfg802154_rdev_list_generation;
 
-static int wpan_phy_match(struct device *dev, const void *data)
-{
-	return !strcmp(dev_name(dev), (const char *)data);
-}
-
 struct wpan_phy *wpan_phy_find(const char *str)
 {
 	struct device *dev;
@@ -35,7 +30,7 @@ struct wpan_phy *wpan_phy_find(const char *str)
 	if (WARN_ON(!str))
 		return NULL;
 
-	dev = class_find_device(&wpan_phy_class, NULL, str, wpan_phy_match);
+	dev = class_find_device_by_name(&wpan_phy_class, str);
 	if (!dev)
 		return NULL;
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH v3 1/7] drivers: Introduce device lookup variants by name
@ 2019-07-23 22:18   ` Suzuki K Poulose
  0 siblings, 0 replies; 71+ messages in thread
From: Suzuki K Poulose @ 2019-07-23 22:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: Alexander Aring, Heikki Krogerus, rafael, Alexander Shishkin,
	Heiko Carstens, Alexandre Belloni, Pavel Machek, Lee Jones,
	linux-leds, linux-rtc, Rafael J. Wysocki, Stefan Schmidt,
	Arnd Bergmann, Suzuki K Poulose, Harald Freudenberger,
	Dan Murphy, linux-arm-kernel, Alessandro Zummo, gregkh,
	linux-usb, Peter Oberparleiter, Maxime Coquelin, linux-wpan,
	Jacek Anaszewski

Add a helper to match the device name for device lookup. Also
reuse this generic exported helper for the existing bus_find_device_by_name().
and add similar variants for driver/class.

Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Dan Murphy <dmurphy@ti.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Harald Freudenberger <freude@linux.ibm.com>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Cc: Lee Jones <lee.jones@linaro.org>
Cc: linux-leds@vger.kernel.org
Cc: linux-rtc@vger.kernel.org
Cc: linux-usb@vger.kernel.org
Cc: linux-wpan@vger.kernel.org
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Peter Oberparleiter <oberpar@linux.ibm.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Stefan Schmidt <stefan@datenfreihafen.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/base/bus.c               | 24 ------------------
 drivers/base/core.c              |  6 +++++
 drivers/hwtracing/stm/core.c     |  9 +------
 drivers/leds/led-class.c         |  9 +------
 drivers/rtc/interface.c          | 11 +--------
 drivers/s390/cio/ccwgroup.c      | 10 +-------
 drivers/s390/cio/device.c        | 15 +-----------
 drivers/s390/crypto/zcrypt_api.c | 11 +--------
 drivers/usb/roles/class.c        |  8 +-----
 drivers/usb/typec/class.c        |  8 +-----
 include/linux/device.h           | 42 +++++++++++++++++++++++++++++---
 net/ieee802154/core.c            |  7 +-----
 12 files changed, 54 insertions(+), 106 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index df3cac739813..a1d1e8256324 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -342,30 +342,6 @@ struct device *bus_find_device(struct bus_type *bus,
 }
 EXPORT_SYMBOL_GPL(bus_find_device);
 
-static int match_name(struct device *dev, const void *data)
-{
-	const char *name = data;
-
-	return sysfs_streq(name, dev_name(dev));
-}
-
-/**
- * bus_find_device_by_name - device iterator for locating a particular device of a specific name
- * @bus: bus type
- * @start: Device to begin with
- * @name: name of the device to match
- *
- * This is similar to the bus_find_device() function above, but it handles
- * searching by a name automatically, no need to write another strcmp matching
- * function.
- */
-struct device *bus_find_device_by_name(struct bus_type *bus,
-				       struct device *start, const char *name)
-{
-	return bus_find_device(bus, start, (void *)name, match_name);
-}
-EXPORT_SYMBOL_GPL(bus_find_device_by_name);
-
 /**
  * subsys_find_device_by_id - find a device with a specific enumeration number
  * @subsys: subsystem
diff --git a/drivers/base/core.c b/drivers/base/core.c
index da84a73f2ba6..fb83647d685a 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3357,6 +3357,12 @@ void device_set_of_node_from_dev(struct device *dev, const struct device *dev2)
 }
 EXPORT_SYMBOL_GPL(device_set_of_node_from_dev);
 
+int device_match_name(struct device *dev, const void *name)
+{
+	return sysfs_streq(dev_name(dev), name);
+}
+EXPORT_SYMBOL_GPL(device_match_name);
+
 int device_match_of_node(struct device *dev, const void *np)
 {
 	return dev->of_node == np;
diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
index e55b902560de..2b6bd42632e8 100644
--- a/drivers/hwtracing/stm/core.c
+++ b/drivers/hwtracing/stm/core.c
@@ -89,13 +89,6 @@ static struct class stm_class = {
 	.dev_groups	= stm_groups,
 };
 
-static int stm_dev_match(struct device *dev, const void *data)
-{
-	const char *name = data;
-
-	return sysfs_streq(name, dev_name(dev));
-}
-
 /**
  * stm_find_device() - find stm device by name
  * @buf:	character buffer containing the name
@@ -116,7 +109,7 @@ struct stm_device *stm_find_device(const char *buf)
 	if (!stm_core_up)
 		return NULL;
 
-	dev = class_find_device(&stm_class, NULL, buf, stm_dev_match);
+	dev = class_find_device_by_name(&stm_class, buf);
 	if (!dev)
 		return NULL;
 
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 4793e77808e2..d54c8e4d8954 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -213,13 +213,6 @@ static int led_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(leds_class_dev_pm_ops, led_suspend, led_resume);
 
-static int match_name(struct device *dev, const void *data)
-{
-	if (!dev_name(dev))
-		return 0;
-	return !strcmp(dev_name(dev), (char *)data);
-}
-
 static int led_classdev_next_name(const char *init_name, char *name,
 				  size_t len)
 {
@@ -230,7 +223,7 @@ static int led_classdev_next_name(const char *init_name, char *name,
 	strlcpy(name, init_name, len);
 
 	while ((ret < len) &&
-	       (dev = class_find_device(leds_class, NULL, name, match_name))) {
+	       (dev = class_find_device_by_name(leds_class, name))) {
 		put_device(dev);
 		ret = snprintf(name, len, "%s_%u", init_name, ++i);
 	}
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 72b7ddc43116..c93ef33b01d3 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -663,21 +663,12 @@ void rtc_update_irq(struct rtc_device *rtc,
 }
 EXPORT_SYMBOL_GPL(rtc_update_irq);
 
-static int __rtc_match(struct device *dev, const void *data)
-{
-	const char *name = data;
-
-	if (strcmp(dev_name(dev), name) == 0)
-		return 1;
-	return 0;
-}
-
 struct rtc_device *rtc_class_open(const char *name)
 {
 	struct device *dev;
 	struct rtc_device *rtc = NULL;
 
-	dev = class_find_device(rtc_class, NULL, name, __rtc_match);
+	dev = class_find_device_by_name(rtc_class, name);
 	if (dev)
 		rtc = to_rtc_device(dev);
 
diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
index c522e9313c50..d843e362c167 100644
--- a/drivers/s390/cio/ccwgroup.c
+++ b/drivers/s390/cio/ccwgroup.c
@@ -608,13 +608,6 @@ void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver)
 }
 EXPORT_SYMBOL(ccwgroup_driver_unregister);
 
-static int __ccwgroupdev_check_busid(struct device *dev, const void *id)
-{
-	const char *bus_id = id;
-
-	return (strcmp(bus_id, dev_name(dev)) == 0);
-}
-
 /**
  * get_ccwgroupdev_by_busid() - obtain device from a bus id
  * @gdrv: driver the device is owned by
@@ -631,8 +624,7 @@ struct ccwgroup_device *get_ccwgroupdev_by_busid(struct ccwgroup_driver *gdrv,
 {
 	struct device *dev;
 
-	dev = driver_find_device(&gdrv->driver, NULL, bus_id,
-				 __ccwgroupdev_check_busid);
+	dev = driver_find_device_by_name(&gdrv->driver, bus_id);
 
 	return dev ? to_ccwgroupdev(dev) : NULL;
 }
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index c421899be20f..131430bd48d9 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -1695,18 +1695,6 @@ int ccw_device_force_console(struct ccw_device *cdev)
 EXPORT_SYMBOL_GPL(ccw_device_force_console);
 #endif
 
-/*
- * get ccw_device matching the busid, but only if owned by cdrv
- */
-static int
-__ccwdev_check_busid(struct device *dev, const void *id)
-{
-	const char *bus_id = id;
-
-	return (strcmp(bus_id, dev_name(dev)) == 0);
-}
-
-
 /**
  * get_ccwdev_by_busid() - obtain device from a bus id
  * @cdrv: driver the device is owned by
@@ -1723,8 +1711,7 @@ struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
 {
 	struct device *dev;
 
-	dev = driver_find_device(&cdrv->driver, NULL, (void *)bus_id,
-				 __ccwdev_check_busid);
+	dev = driver_find_device_by_name(&cdrv->driver, bus_id);
 
 	return dev ? to_ccwdev(dev) : NULL;
 }
diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c
index 1058b4b5cc1e..38a5a47b8c9c 100644
--- a/drivers/s390/crypto/zcrypt_api.c
+++ b/drivers/s390/crypto/zcrypt_api.c
@@ -133,12 +133,6 @@ struct zcdn_device {
 static int zcdn_create(const char *name);
 static int zcdn_destroy(const char *name);
 
-/* helper function, matches the name for find_zcdndev_by_name() */
-static int __match_zcdn_name(struct device *dev, const void *data)
-{
-	return strcmp(dev_name(dev), (const char *)data) == 0;
-}
-
 /* helper function, matches the devt value for find_zcdndev_by_devt() */
 static int __match_zcdn_devt(struct device *dev, const void *data)
 {
@@ -152,10 +146,7 @@ static int __match_zcdn_devt(struct device *dev, const void *data)
  */
 static inline struct zcdn_device *find_zcdndev_by_name(const char *name)
 {
-	struct device *dev =
-		class_find_device(zcrypt_class, NULL,
-				  (void *) name,
-				  __match_zcdn_name);
+	struct device *dev = class_find_device_by_name(zcrypt_class, name);
 
 	return dev ? to_zcdn_dev(dev) : NULL;
 }
diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
index 86defca6623e..c8efe60e2465 100644
--- a/drivers/usb/roles/class.c
+++ b/drivers/usb/roles/class.c
@@ -90,11 +90,6 @@ static int switch_fwnode_match(struct device *dev, const void *fwnode)
 	return dev_fwnode(dev) == fwnode;
 }
 
-static int switch_name_match(struct device *dev, const void *name)
-{
-	return !strcmp((const char *)name, dev_name(dev));
-}
-
 static void *usb_role_switch_match(struct device_connection *con, int ep,
 				   void *data)
 {
@@ -107,8 +102,7 @@ static void *usb_role_switch_match(struct device_connection *con, int ep,
 		dev = class_find_device(role_class, NULL, con->fwnode,
 					switch_fwnode_match);
 	} else {
-		dev = class_find_device(role_class, NULL, con->endpoint[ep],
-					switch_name_match);
+		dev = class_find_device_by_name(role_class, con->endpoint[ep]);
 	}
 
 	return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index a18285a990a8..9b0d15b487e5 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -210,11 +210,6 @@ static int typec_port_fwnode_match(struct device *dev, const void *fwnode)
 	return dev_fwnode(dev) == fwnode;
 }
 
-static int typec_port_name_match(struct device *dev, const void *name)
-{
-	return !strcmp((const char *)name, dev_name(dev));
-}
-
 static void *typec_port_match(struct device_connection *con, int ep, void *data)
 {
 	struct device *dev;
@@ -227,8 +222,7 @@ static void *typec_port_match(struct device_connection *con, int ep, void *data)
 		return class_find_device(typec_class, NULL, con->fwnode,
 					 typec_port_fwnode_match);
 
-	dev = class_find_device(typec_class, NULL, con->endpoint[ep],
-				typec_port_name_match);
+	dev = class_find_device_by_name(typec_class, con->endpoint[ep]);
 
 	return dev ? dev : ERR_PTR(-EPROBE_DEFER);
 }
diff --git a/include/linux/device.h b/include/linux/device.h
index c330b75c6c57..3ba376b8b456 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -164,6 +164,7 @@ void subsys_dev_iter_init(struct subsys_dev_iter *iter,
 struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter);
 void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
 
+int device_match_name(struct device *dev, const void *name);
 int device_match_of_node(struct device *dev, const void *np);
 
 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
@@ -171,9 +172,20 @@ int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
 struct device *bus_find_device(struct bus_type *bus, struct device *start,
 			       const void *data,
 			       int (*match)(struct device *dev, const void *data));
-struct device *bus_find_device_by_name(struct bus_type *bus,
-				       struct device *start,
-				       const char *name);
+/**
+ * bus_find_device_by_name - device iterator for locating a particular device
+ * of a specific name.
+ * @bus: bus type
+ * @start: Device to begin with
+ * @name: name of the device to match
+ */
+static inline struct device *bus_find_device_by_name(struct bus_type *bus,
+						     struct device *start,
+						     const char *name)
+{
+	return bus_find_device(bus, start, name, device_match_name);
+}
+
 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
 					struct device *hint);
 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
@@ -342,6 +354,18 @@ struct device *driver_find_device(struct device_driver *drv,
 				  struct device *start, const void *data,
 				  int (*match)(struct device *dev, const void *data));
 
+/**
+ * driver_find_device_by_name - device iterator for locating a particular device
+ * of a specific name.
+ * @driver: the driver we're iterating
+ * @name: name of the device to match
+ */
+static inline struct device *driver_find_device_by_name(struct device_driver *drv,
+							const char *name)
+{
+	return driver_find_device(drv, NULL, name, device_match_name);
+}
+
 void driver_deferred_probe_add(struct device *dev);
 int driver_deferred_probe_check_state(struct device *dev);
 int driver_deferred_probe_check_state_continue(struct device *dev);
@@ -471,6 +495,18 @@ extern struct device *class_find_device(struct class *class,
 					struct device *start, const void *data,
 					int (*match)(struct device *, const void *));
 
+/**
+ * class_find_device_by_name - device iterator for locating a particular device
+ * of a specific name.
+ * @class: class type
+ * @name: name of the device to match
+ */
+static inline struct device *class_find_device_by_name(struct class *class,
+						       const char *name)
+{
+	return class_find_device(class, NULL, name, device_match_name);
+}
+
 struct class_attribute {
 	struct attribute attr;
 	ssize_t (*show)(struct class *class, struct class_attribute *attr,
diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
index 60b7ac56a1f5..de259b5170ab 100644
--- a/net/ieee802154/core.c
+++ b/net/ieee802154/core.c
@@ -23,11 +23,6 @@
 LIST_HEAD(cfg802154_rdev_list);
 int cfg802154_rdev_list_generation;
 
-static int wpan_phy_match(struct device *dev, const void *data)
-{
-	return !strcmp(dev_name(dev), (const char *)data);
-}
-
 struct wpan_phy *wpan_phy_find(const char *str)
 {
 	struct device *dev;
@@ -35,7 +30,7 @@ struct wpan_phy *wpan_phy_find(const char *str)
 	if (WARN_ON(!str))
 		return NULL;
 
-	dev = class_find_device(&wpan_phy_class, NULL, str, wpan_phy_match);
+	dev = class_find_device_by_name(&wpan_phy_class, str);
 	if (!dev)
 		return NULL;
 
-- 
2.21.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
  2019-07-23 22:18 ` Suzuki K Poulose
  (?)
  (?)
@ 2019-07-23 22:18   ` Suzuki K Poulose
  -1 siblings, 0 replies; 71+ messages in thread
From: Suzuki K Poulose @ 2019-07-23 22:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: gregkh, rafael, linux-arm-kernel, Suzuki K Poulose,
	Maarten Lankhorst, Maxime Ripard, dri-devel, David Airlie,
	Daniel Vetter, devicetree, Florian Fainelli, Frank Rowand,
	Heiko Stuebner, Liam Girdwood, linux-i2c, linux-rockchip,
	linux-spi, Mathieu Poirier, Rob Herring, Srinivas Kandagatla,
	Takashi Iwai, Wolfram Sang, Alan Tull, Moritz Fischer,
	linux-fpga, Peter Rosin, Mark Brown, Heiner Kallweit,
	David S. Miller, Andrew Lunn, Lee Jones, Thor Thayer, Jiri Slaby

Introduce wrappers for {bus/driver/class}_find_device() to
locate devices by its of_node.

Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <maxime.ripard@bootlin.com>
Cc: dri-devel@lists.freedesktop.org
Cc: David Airlie <airlied@linux.ie>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: devicetree@vger.kernel.org
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Frank Rowand <frowand.list@gmail.com>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: linux-i2c@vger.kernel.org
Cc: linux-rockchip@lists.infradead.org
Cc: linux-spi@vger.kernel.org
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Takashi Iwai <tiwai@suse.com>
Cc: Wolfram Sang <wsa@the-dreams.de>
Cc: Alan Tull <atull@kernel.org>
Cc: Moritz Fischer <mdf@kernel.org>
Cc: linux-fpga@vger.kernel.org
Cc: Peter Rosin <peda@axentia.se>
Cc: Mark Brown <broonie@kernel.org>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Heiner Kallweit <hkallweit1@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Lee Jones <lee.jones@linaro.org>
Cc: Thor Thayer <thor.thayer@linux.intel.com>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Peter Rosin <peda@axentia.se>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 - Dropped the reviewed-by tags from Thor, Mark, Andrew and Peter as the
   patches are mereged, though there are no functional changes.
---
 drivers/amba/tegra-ahb.c              | 11 +-------
 drivers/fpga/fpga-bridge.c            |  8 +-----
 drivers/fpga/fpga-mgr.c               |  8 +-----
 drivers/gpu/drm/drm_mipi_dsi.c        |  7 +----
 drivers/i2c/i2c-core-of.c             |  7 +----
 drivers/mfd/altera-sysmgr.c           | 14 ++--------
 drivers/mux/core.c                    |  7 +----
 drivers/net/phy/mdio_bus.c            |  9 +------
 drivers/nvmem/core.c                  |  7 +----
 drivers/of/of_mdio.c                  |  8 +-----
 drivers/of/platform.c                 |  7 +----
 drivers/regulator/of_regulator.c      |  7 +----
 drivers/spi/spi.c                     | 20 +++------------
 include/linux/device.h                | 37 +++++++++++++++++++++++++++
 sound/soc/rockchip/rk3399_gru_sound.c |  9 ++-----
 15 files changed, 56 insertions(+), 110 deletions(-)

diff --git a/drivers/amba/tegra-ahb.c b/drivers/amba/tegra-ahb.c
index aa64eece77a6..57d3b2e2d007 100644
--- a/drivers/amba/tegra-ahb.c
+++ b/drivers/amba/tegra-ahb.c
@@ -134,22 +134,13 @@ static inline void gizmo_writel(struct tegra_ahb *ahb, u32 value, u32 offset)
 }
 
 #ifdef CONFIG_TEGRA_IOMMU_SMMU
-static int tegra_ahb_match_by_smmu(struct device *dev, const void *data)
-{
-	struct tegra_ahb *ahb = dev_get_drvdata(dev);
-	const struct device_node *dn = data;
-
-	return (ahb->dev->of_node == dn) ? 1 : 0;
-}
-
 int tegra_ahb_enable_smmu(struct device_node *dn)
 {
 	struct device *dev;
 	u32 val;
 	struct tegra_ahb *ahb;
 
-	dev = driver_find_device(&tegra_ahb_driver.driver, NULL, dn,
-				 tegra_ahb_match_by_smmu);
+	dev = driver_find_device_by_of_node(&tegra_ahb_driver.driver, dn);
 	if (!dev)
 		return -EPROBE_DEFER;
 	ahb = dev_get_drvdata(dev);
diff --git a/drivers/fpga/fpga-bridge.c b/drivers/fpga/fpga-bridge.c
index 80bd8f1b2aa6..4bab9028940a 100644
--- a/drivers/fpga/fpga-bridge.c
+++ b/drivers/fpga/fpga-bridge.c
@@ -19,11 +19,6 @@ static struct class *fpga_bridge_class;
 /* Lock for adding/removing bridges to linked lists*/
 static spinlock_t bridge_list_lock;
 
-static int fpga_bridge_of_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /**
  * fpga_bridge_enable - Enable transactions on the bridge
  *
@@ -104,8 +99,7 @@ struct fpga_bridge *of_fpga_bridge_get(struct device_node *np,
 {
 	struct device *dev;
 
-	dev = class_find_device(fpga_bridge_class, NULL, np,
-				fpga_bridge_of_node_match);
+	dev = class_find_device_by_of_node(fpga_bridge_class, np);
 	if (!dev)
 		return ERR_PTR(-ENODEV);
 
diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
index c3866816456a..e05104f5e40c 100644
--- a/drivers/fpga/fpga-mgr.c
+++ b/drivers/fpga/fpga-mgr.c
@@ -482,11 +482,6 @@ struct fpga_manager *fpga_mgr_get(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(fpga_mgr_get);
 
-static int fpga_mgr_of_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /**
  * of_fpga_mgr_get - Given a device node, get a reference to a fpga mgr.
  *
@@ -498,8 +493,7 @@ struct fpga_manager *of_fpga_mgr_get(struct device_node *node)
 {
 	struct device *dev;
 
-	dev = class_find_device(fpga_mgr_class, NULL, node,
-				fpga_mgr_of_node_match);
+	dev = class_find_device_by_of_node(fpga_mgr_class, node);
 	if (!dev)
 		return ERR_PTR(-ENODEV);
 
diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
index ad19df0686c9..bd2498bbd74a 100644
--- a/drivers/gpu/drm/drm_mipi_dsi.c
+++ b/drivers/gpu/drm/drm_mipi_dsi.c
@@ -93,11 +93,6 @@ static struct bus_type mipi_dsi_bus_type = {
 	.pm = &mipi_dsi_device_pm_ops,
 };
 
-static int of_device_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /**
  * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a
  *    device tree node
@@ -110,7 +105,7 @@ struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np)
 {
 	struct device *dev;
 
-	dev = bus_find_device(&mipi_dsi_bus_type, NULL, np, of_device_match);
+	dev = bus_find_device_by_of_node(&mipi_dsi_bus_type, np);
 
 	return dev ? to_mipi_dsi_device(dev) : NULL;
 }
diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
index d1c48dec7118..6f632d543fcc 100644
--- a/drivers/i2c/i2c-core-of.c
+++ b/drivers/i2c/i2c-core-of.c
@@ -113,11 +113,6 @@ void of_i2c_register_devices(struct i2c_adapter *adap)
 	of_node_put(bus);
 }
 
-static int of_dev_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 static int of_dev_or_parent_node_match(struct device *dev, const void *data)
 {
 	if (dev->of_node == data)
@@ -135,7 +130,7 @@ struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
 	struct device *dev;
 	struct i2c_client *client;
 
-	dev = bus_find_device(&i2c_bus_type, NULL, node, of_dev_node_match);
+	dev = bus_find_device_by_of_node(&i2c_bus_type, node);
 	if (!dev)
 		return NULL;
 
diff --git a/drivers/mfd/altera-sysmgr.c b/drivers/mfd/altera-sysmgr.c
index 2ee14d8a6d31..d2a13a547a3c 100644
--- a/drivers/mfd/altera-sysmgr.c
+++ b/drivers/mfd/altera-sysmgr.c
@@ -87,16 +87,6 @@ static struct regmap_config altr_sysmgr_regmap_cfg = {
 	.use_single_write = true,
 };
 
-/**
- * sysmgr_match_phandle
- * Matching function used by driver_find_device().
- * Return: True if match is found, otherwise false.
- */
-static int sysmgr_match_phandle(struct device *dev, const void *data)
-{
-	return dev->of_node == (const struct device_node *)data;
-}
-
 /**
  * altr_sysmgr_regmap_lookup_by_phandle
  * 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,
 	if (!sysmgr_np)
 		return ERR_PTR(-ENODEV);
 
-	dev = driver_find_device(&altr_sysmgr_driver.driver, NULL,
-				 (void *)sysmgr_np, sysmgr_match_phandle);
+	dev = driver_find_device_by_of_node(&altr_sysmgr_driver.driver,
+					    (void *)sysmgr_np);
 	of_node_put(sysmgr_np);
 	if (!dev)
 		return ERR_PTR(-EPROBE_DEFER);
diff --git a/drivers/mux/core.c b/drivers/mux/core.c
index d1271c1ee23c..1fb22388e7e0 100644
--- a/drivers/mux/core.c
+++ b/drivers/mux/core.c
@@ -405,17 +405,12 @@ int mux_control_deselect(struct mux_control *mux)
 }
 EXPORT_SYMBOL_GPL(mux_control_deselect);
 
-static int of_dev_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /* Note this function returns a reference to the mux_chip dev. */
 static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np)
 {
 	struct device *dev;
 
-	dev = class_find_device(&mux_class, NULL, np, of_dev_node_match);
+	dev = class_find_device_by_of_node(&mux_class, np);
 
 	return dev ? to_mux_chip(dev) : NULL;
 }
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index bd04fe762056..ce940871331e 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -262,11 +262,6 @@ static struct class mdio_bus_class = {
 };
 
 #if IS_ENABLED(CONFIG_OF_MDIO)
-/* Helper function for of_mdio_find_bus */
-static int of_mdio_bus_match(struct device *dev, const void *mdio_bus_np)
-{
-	return dev->of_node == mdio_bus_np;
-}
 /**
  * of_mdio_find_bus - Given an mii_bus node, find the mii_bus.
  * @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)
 	if (!mdio_bus_np)
 		return NULL;
 
-	d = class_find_device(&mdio_bus_class, NULL,  mdio_bus_np,
-			      of_mdio_bus_match);
-
+	d = class_find_device_by_of_node(&mdio_bus_class, mdio_bus_np);
 	return d ? to_mii_bus(d) : NULL;
 }
 EXPORT_SYMBOL(of_mdio_find_bus);
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index ac5d945be88a..057d1ff87d5d 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -76,11 +76,6 @@ static struct bus_type nvmem_bus_type = {
 	.name		= "nvmem",
 };
 
-static int of_nvmem_match(struct device *dev, const void *nvmem_np)
-{
-	return dev->of_node == nvmem_np;
-}
-
 static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)
 {
 	struct device *d;
@@ -88,7 +83,7 @@ static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)
 	if (!nvmem_np)
 		return NULL;
 
-	d = bus_find_device(&nvmem_bus_type, NULL, nvmem_np, of_nvmem_match);
+	d = bus_find_device_by_of_node(&nvmem_bus_type, nvmem_np);
 
 	if (!d)
 		return NULL;
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index 44f53496cab1..000b95787df1 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -280,12 +280,6 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
 }
 EXPORT_SYMBOL(of_mdiobus_register);
 
-/* Helper function for of_phy_find_device */
-static int of_phy_match(struct device *dev, const void *phy_np)
-{
-	return dev->of_node == phy_np;
-}
-
 /**
  * of_phy_find_device - Give a PHY node, find the phy_device
  * @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)
 	if (!phy_np)
 		return NULL;
 
-	d = bus_find_device(&mdio_bus_type, NULL, phy_np, of_phy_match);
+	d = bus_find_device_by_of_node(&mdio_bus_type, phy_np);
 	if (d) {
 		mdiodev = to_mdio_device(d);
 		if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 7801e25e6895..b47a2292fe8e 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -37,11 +37,6 @@ static const struct of_device_id of_skipped_node_table[] = {
 	{} /* Empty terminated list */
 };
 
-static int of_dev_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /**
  * of_find_device_by_node - Find the platform_device associated with a node
  * @np: Pointer to device tree node
@@ -55,7 +50,7 @@ struct platform_device *of_find_device_by_node(struct device_node *np)
 {
 	struct device *dev;
 
-	dev = bus_find_device(&platform_bus_type, NULL, np, of_dev_node_match);
+	dev = bus_find_device_by_of_node(&platform_bus_type, np);
 	return dev ? to_platform_device(dev) : NULL;
 }
 EXPORT_SYMBOL(of_find_device_by_node);
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 397918ebba55..20dcc9c03adc 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -460,16 +460,11 @@ struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
 	return NULL;
 }
 
-static int of_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 struct regulator_dev *of_find_regulator_by_node(struct device_node *np)
 {
 	struct device *dev;
 
-	dev = class_find_device(&regulator_class, NULL, np, of_node_match);
+	dev = class_find_device_by_of_node(&regulator_class, np);
 
 	return dev ? dev_to_rdev(dev) : NULL;
 }
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 75ac046cae52..a591da87981a 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -3652,37 +3652,25 @@ EXPORT_SYMBOL_GPL(spi_write_then_read);
 /*-------------------------------------------------------------------------*/
 
 #if IS_ENABLED(CONFIG_OF)
-static int __spi_of_device_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /* must call put_device() when done with returned spi_device device */
 struct spi_device *of_find_spi_device_by_node(struct device_node *node)
 {
-	struct device *dev = bus_find_device(&spi_bus_type, NULL, node,
-						__spi_of_device_match);
+	struct device *dev = bus_find_device_by_of_node(&spi_bus_type, node);
+
 	return dev ? to_spi_device(dev) : NULL;
 }
 EXPORT_SYMBOL_GPL(of_find_spi_device_by_node);
 #endif /* IS_ENABLED(CONFIG_OF) */
 
 #if IS_ENABLED(CONFIG_OF_DYNAMIC)
-static int __spi_of_controller_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /* the spi controllers are not using spi_bus, so we find it with another way */
 static struct spi_controller *of_find_spi_controller_by_node(struct device_node *node)
 {
 	struct device *dev;
 
-	dev = class_find_device(&spi_master_class, NULL, node,
-				__spi_of_controller_match);
+	dev = class_find_device_by_of_node(&spi_master_class, node);
 	if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE))
-		dev = class_find_device(&spi_slave_class, NULL, node,
-					__spi_of_controller_match);
+		dev = class_find_device_by_of_node(&spi_slave_class, node);
 	if (!dev)
 		return NULL;
 
diff --git a/include/linux/device.h b/include/linux/device.h
index 3ba376b8b456..29d8d7ad41e6 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -186,6 +186,18 @@ static inline struct device *bus_find_device_by_name(struct bus_type *bus,
 	return bus_find_device(bus, start, name, device_match_name);
 }
 
+/**
+ * bus_find_device_by_of_node : device iterator for locating a particular device
+ * matching the of_node.
+ * @bus: bus type
+ * @np: of_node of the device to match.
+ */
+static inline struct device *
+bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
+{
+	return bus_find_device(bus, NULL, np, device_match_of_node);
+}
+
 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
 					struct device *hint);
 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
@@ -366,6 +378,19 @@ static inline struct device *driver_find_device_by_name(struct device_driver *dr
 	return driver_find_device(drv, NULL, name, device_match_name);
 }
 
+/**
+ * driver_find_device_by_of_node- device iterator for locating a particular device
+ * by of_node pointer.
+ * @driver: the driver we're iterating
+ * @np: of_node pointer to match.
+ */
+static inline struct device *
+driver_find_device_by_of_node(struct device_driver *drv,
+			      const struct device_node *np)
+{
+	return driver_find_device(drv, NULL, np, device_match_of_node);
+}
+
 void driver_deferred_probe_add(struct device *dev);
 int driver_deferred_probe_check_state(struct device *dev);
 int driver_deferred_probe_check_state_continue(struct device *dev);
@@ -507,6 +532,18 @@ static inline struct device *class_find_device_by_name(struct class *class,
 	return class_find_device(class, NULL, name, device_match_name);
 }
 
+/**
+ * class_find_device_by_of_node : device iterator for locating a particular device
+ * matching the of_node.
+ * @class: class type
+ * @np: of_node of the device to match.
+ */
+static inline struct device *
+class_find_device_by_of_node(struct class *class, const struct device_node *np)
+{
+	return class_find_device(class, NULL, np, device_match_of_node);
+}
+
 struct class_attribute {
 	struct attribute attr;
 	ssize_t (*show)(struct class *class, struct class_attribute *attr,
diff --git a/sound/soc/rockchip/rk3399_gru_sound.c b/sound/soc/rockchip/rk3399_gru_sound.c
index c16b0ffe8cfc..d951100bf770 100644
--- a/sound/soc/rockchip/rk3399_gru_sound.c
+++ b/sound/soc/rockchip/rk3399_gru_sound.c
@@ -422,11 +422,6 @@ static const struct dailink_match_data dailink_match[] = {
 	},
 };
 
-static int of_dev_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 static int rockchip_sound_codec_node_match(struct device_node *np_codec)
 {
 	struct device *dev;
@@ -438,8 +433,8 @@ static int rockchip_sound_codec_node_match(struct device_node *np_codec)
 			continue;
 
 		if (dailink_match[i].bus_type) {
-			dev = bus_find_device(dailink_match[i].bus_type, NULL,
-					      np_codec, of_dev_node_match);
+			dev = bus_find_device_by_of_node(dailink_match[i].bus_type,
+							 np_codec);
 			if (!dev)
 				continue;
 			put_device(dev);
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
@ 2019-07-23 22:18   ` Suzuki K Poulose
  0 siblings, 0 replies; 71+ messages in thread
From: Suzuki K Poulose @ 2019-07-23 22:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: gregkh, rafael, linux-arm-kernel, Suzuki K Poulose,
	Maarten Lankhorst, Maxime Ripard, dri-devel, David Airlie,
	Daniel Vetter, devicetree, Florian Fainelli, Frank Rowand,
	Heiko Stuebner, Liam Girdwood, linux-i2c, linux-rockchip,
	linux-spi, Mathieu Poirier, Rob Herring, Srinivas Kandagatla,
	Takashi Iwai, Wolfram

Introduce wrappers for {bus/driver/class}_find_device() to
locate devices by its of_node.

Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <maxime.ripard@bootlin.com>
Cc: dri-devel@lists.freedesktop.org
Cc: David Airlie <airlied@linux.ie>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: devicetree@vger.kernel.org
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Frank Rowand <frowand.list@gmail.com>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: linux-i2c@vger.kernel.org
Cc: linux-rockchip@lists.infradead.org
Cc: linux-spi@vger.kernel.org
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Takashi Iwai <tiwai@suse.com>
Cc: Wolfram Sang <wsa@the-dreams.de>
Cc: Alan Tull <atull@kernel.org>
Cc: Moritz Fischer <mdf@kernel.org>
Cc: linux-fpga@vger.kernel.org
Cc: Peter Rosin <peda@axentia.se>
Cc: Mark Brown <broonie@kernel.org>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Heiner Kallweit <hkallweit1@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Lee Jones <lee.jones@linaro.org>
Cc: Thor Thayer <thor.thayer@linux.intel.com>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Peter Rosin <peda@axentia.se>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 - Dropped the reviewed-by tags from Thor, Mark, Andrew and Peter as the
   patches are mereged, though there are no functional changes.
---
 drivers/amba/tegra-ahb.c              | 11 +-------
 drivers/fpga/fpga-bridge.c            |  8 +-----
 drivers/fpga/fpga-mgr.c               |  8 +-----
 drivers/gpu/drm/drm_mipi_dsi.c        |  7 +----
 drivers/i2c/i2c-core-of.c             |  7 +----
 drivers/mfd/altera-sysmgr.c           | 14 ++--------
 drivers/mux/core.c                    |  7 +----
 drivers/net/phy/mdio_bus.c            |  9 +------
 drivers/nvmem/core.c                  |  7 +----
 drivers/of/of_mdio.c                  |  8 +-----
 drivers/of/platform.c                 |  7 +----
 drivers/regulator/of_regulator.c      |  7 +----
 drivers/spi/spi.c                     | 20 +++------------
 include/linux/device.h                | 37 +++++++++++++++++++++++++++
 sound/soc/rockchip/rk3399_gru_sound.c |  9 ++-----
 15 files changed, 56 insertions(+), 110 deletions(-)

diff --git a/drivers/amba/tegra-ahb.c b/drivers/amba/tegra-ahb.c
index aa64eece77a6..57d3b2e2d007 100644
--- a/drivers/amba/tegra-ahb.c
+++ b/drivers/amba/tegra-ahb.c
@@ -134,22 +134,13 @@ static inline void gizmo_writel(struct tegra_ahb *ahb, u32 value, u32 offset)
 }
 
 #ifdef CONFIG_TEGRA_IOMMU_SMMU
-static int tegra_ahb_match_by_smmu(struct device *dev, const void *data)
-{
-	struct tegra_ahb *ahb = dev_get_drvdata(dev);
-	const struct device_node *dn = data;
-
-	return (ahb->dev->of_node == dn) ? 1 : 0;
-}
-
 int tegra_ahb_enable_smmu(struct device_node *dn)
 {
 	struct device *dev;
 	u32 val;
 	struct tegra_ahb *ahb;
 
-	dev = driver_find_device(&tegra_ahb_driver.driver, NULL, dn,
-				 tegra_ahb_match_by_smmu);
+	dev = driver_find_device_by_of_node(&tegra_ahb_driver.driver, dn);
 	if (!dev)
 		return -EPROBE_DEFER;
 	ahb = dev_get_drvdata(dev);
diff --git a/drivers/fpga/fpga-bridge.c b/drivers/fpga/fpga-bridge.c
index 80bd8f1b2aa6..4bab9028940a 100644
--- a/drivers/fpga/fpga-bridge.c
+++ b/drivers/fpga/fpga-bridge.c
@@ -19,11 +19,6 @@ static struct class *fpga_bridge_class;
 /* Lock for adding/removing bridges to linked lists*/
 static spinlock_t bridge_list_lock;
 
-static int fpga_bridge_of_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /**
  * fpga_bridge_enable - Enable transactions on the bridge
  *
@@ -104,8 +99,7 @@ struct fpga_bridge *of_fpga_bridge_get(struct device_node *np,
 {
 	struct device *dev;
 
-	dev = class_find_device(fpga_bridge_class, NULL, np,
-				fpga_bridge_of_node_match);
+	dev = class_find_device_by_of_node(fpga_bridge_class, np);
 	if (!dev)
 		return ERR_PTR(-ENODEV);
 
diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
index c3866816456a..e05104f5e40c 100644
--- a/drivers/fpga/fpga-mgr.c
+++ b/drivers/fpga/fpga-mgr.c
@@ -482,11 +482,6 @@ struct fpga_manager *fpga_mgr_get(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(fpga_mgr_get);
 
-static int fpga_mgr_of_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /**
  * of_fpga_mgr_get - Given a device node, get a reference to a fpga mgr.
  *
@@ -498,8 +493,7 @@ struct fpga_manager *of_fpga_mgr_get(struct device_node *node)
 {
 	struct device *dev;
 
-	dev = class_find_device(fpga_mgr_class, NULL, node,
-				fpga_mgr_of_node_match);
+	dev = class_find_device_by_of_node(fpga_mgr_class, node);
 	if (!dev)
 		return ERR_PTR(-ENODEV);
 
diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
index ad19df0686c9..bd2498bbd74a 100644
--- a/drivers/gpu/drm/drm_mipi_dsi.c
+++ b/drivers/gpu/drm/drm_mipi_dsi.c
@@ -93,11 +93,6 @@ static struct bus_type mipi_dsi_bus_type = {
 	.pm = &mipi_dsi_device_pm_ops,
 };
 
-static int of_device_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /**
  * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a
  *    device tree node
@@ -110,7 +105,7 @@ struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np)
 {
 	struct device *dev;
 
-	dev = bus_find_device(&mipi_dsi_bus_type, NULL, np, of_device_match);
+	dev = bus_find_device_by_of_node(&mipi_dsi_bus_type, np);
 
 	return dev ? to_mipi_dsi_device(dev) : NULL;
 }
diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
index d1c48dec7118..6f632d543fcc 100644
--- a/drivers/i2c/i2c-core-of.c
+++ b/drivers/i2c/i2c-core-of.c
@@ -113,11 +113,6 @@ void of_i2c_register_devices(struct i2c_adapter *adap)
 	of_node_put(bus);
 }
 
-static int of_dev_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 static int of_dev_or_parent_node_match(struct device *dev, const void *data)
 {
 	if (dev->of_node == data)
@@ -135,7 +130,7 @@ struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
 	struct device *dev;
 	struct i2c_client *client;
 
-	dev = bus_find_device(&i2c_bus_type, NULL, node, of_dev_node_match);
+	dev = bus_find_device_by_of_node(&i2c_bus_type, node);
 	if (!dev)
 		return NULL;
 
diff --git a/drivers/mfd/altera-sysmgr.c b/drivers/mfd/altera-sysmgr.c
index 2ee14d8a6d31..d2a13a547a3c 100644
--- a/drivers/mfd/altera-sysmgr.c
+++ b/drivers/mfd/altera-sysmgr.c
@@ -87,16 +87,6 @@ static struct regmap_config altr_sysmgr_regmap_cfg = {
 	.use_single_write = true,
 };
 
-/**
- * sysmgr_match_phandle
- * Matching function used by driver_find_device().
- * Return: True if match is found, otherwise false.
- */
-static int sysmgr_match_phandle(struct device *dev, const void *data)
-{
-	return dev->of_node == (const struct device_node *)data;
-}
-
 /**
  * altr_sysmgr_regmap_lookup_by_phandle
  * 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,
 	if (!sysmgr_np)
 		return ERR_PTR(-ENODEV);
 
-	dev = driver_find_device(&altr_sysmgr_driver.driver, NULL,
-				 (void *)sysmgr_np, sysmgr_match_phandle);
+	dev = driver_find_device_by_of_node(&altr_sysmgr_driver.driver,
+					    (void *)sysmgr_np);
 	of_node_put(sysmgr_np);
 	if (!dev)
 		return ERR_PTR(-EPROBE_DEFER);
diff --git a/drivers/mux/core.c b/drivers/mux/core.c
index d1271c1ee23c..1fb22388e7e0 100644
--- a/drivers/mux/core.c
+++ b/drivers/mux/core.c
@@ -405,17 +405,12 @@ int mux_control_deselect(struct mux_control *mux)
 }
 EXPORT_SYMBOL_GPL(mux_control_deselect);
 
-static int of_dev_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /* Note this function returns a reference to the mux_chip dev. */
 static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np)
 {
 	struct device *dev;
 
-	dev = class_find_device(&mux_class, NULL, np, of_dev_node_match);
+	dev = class_find_device_by_of_node(&mux_class, np);
 
 	return dev ? to_mux_chip(dev) : NULL;
 }
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index bd04fe762056..ce940871331e 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -262,11 +262,6 @@ static struct class mdio_bus_class = {
 };
 
 #if IS_ENABLED(CONFIG_OF_MDIO)
-/* Helper function for of_mdio_find_bus */
-static int of_mdio_bus_match(struct device *dev, const void *mdio_bus_np)
-{
-	return dev->of_node == mdio_bus_np;
-}
 /**
  * of_mdio_find_bus - Given an mii_bus node, find the mii_bus.
  * @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)
 	if (!mdio_bus_np)
 		return NULL;
 
-	d = class_find_device(&mdio_bus_class, NULL,  mdio_bus_np,
-			      of_mdio_bus_match);
-
+	d = class_find_device_by_of_node(&mdio_bus_class, mdio_bus_np);
 	return d ? to_mii_bus(d) : NULL;
 }
 EXPORT_SYMBOL(of_mdio_find_bus);
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index ac5d945be88a..057d1ff87d5d 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -76,11 +76,6 @@ static struct bus_type nvmem_bus_type = {
 	.name		= "nvmem",
 };
 
-static int of_nvmem_match(struct device *dev, const void *nvmem_np)
-{
-	return dev->of_node == nvmem_np;
-}
-
 static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)
 {
 	struct device *d;
@@ -88,7 +83,7 @@ static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)
 	if (!nvmem_np)
 		return NULL;
 
-	d = bus_find_device(&nvmem_bus_type, NULL, nvmem_np, of_nvmem_match);
+	d = bus_find_device_by_of_node(&nvmem_bus_type, nvmem_np);
 
 	if (!d)
 		return NULL;
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index 44f53496cab1..000b95787df1 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -280,12 +280,6 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
 }
 EXPORT_SYMBOL(of_mdiobus_register);
 
-/* Helper function for of_phy_find_device */
-static int of_phy_match(struct device *dev, const void *phy_np)
-{
-	return dev->of_node == phy_np;
-}
-
 /**
  * of_phy_find_device - Give a PHY node, find the phy_device
  * @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)
 	if (!phy_np)
 		return NULL;
 
-	d = bus_find_device(&mdio_bus_type, NULL, phy_np, of_phy_match);
+	d = bus_find_device_by_of_node(&mdio_bus_type, phy_np);
 	if (d) {
 		mdiodev = to_mdio_device(d);
 		if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 7801e25e6895..b47a2292fe8e 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -37,11 +37,6 @@ static const struct of_device_id of_skipped_node_table[] = {
 	{} /* Empty terminated list */
 };
 
-static int of_dev_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /**
  * of_find_device_by_node - Find the platform_device associated with a node
  * @np: Pointer to device tree node
@@ -55,7 +50,7 @@ struct platform_device *of_find_device_by_node(struct device_node *np)
 {
 	struct device *dev;
 
-	dev = bus_find_device(&platform_bus_type, NULL, np, of_dev_node_match);
+	dev = bus_find_device_by_of_node(&platform_bus_type, np);
 	return dev ? to_platform_device(dev) : NULL;
 }
 EXPORT_SYMBOL(of_find_device_by_node);
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 397918ebba55..20dcc9c03adc 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -460,16 +460,11 @@ struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
 	return NULL;
 }
 
-static int of_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 struct regulator_dev *of_find_regulator_by_node(struct device_node *np)
 {
 	struct device *dev;
 
-	dev = class_find_device(&regulator_class, NULL, np, of_node_match);
+	dev = class_find_device_by_of_node(&regulator_class, np);
 
 	return dev ? dev_to_rdev(dev) : NULL;
 }
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 75ac046cae52..a591da87981a 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -3652,37 +3652,25 @@ EXPORT_SYMBOL_GPL(spi_write_then_read);
 /*-------------------------------------------------------------------------*/
 
 #if IS_ENABLED(CONFIG_OF)
-static int __spi_of_device_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /* must call put_device() when done with returned spi_device device */
 struct spi_device *of_find_spi_device_by_node(struct device_node *node)
 {
-	struct device *dev = bus_find_device(&spi_bus_type, NULL, node,
-						__spi_of_device_match);
+	struct device *dev = bus_find_device_by_of_node(&spi_bus_type, node);
+
 	return dev ? to_spi_device(dev) : NULL;
 }
 EXPORT_SYMBOL_GPL(of_find_spi_device_by_node);
 #endif /* IS_ENABLED(CONFIG_OF) */
 
 #if IS_ENABLED(CONFIG_OF_DYNAMIC)
-static int __spi_of_controller_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /* the spi controllers are not using spi_bus, so we find it with another way */
 static struct spi_controller *of_find_spi_controller_by_node(struct device_node *node)
 {
 	struct device *dev;
 
-	dev = class_find_device(&spi_master_class, NULL, node,
-				__spi_of_controller_match);
+	dev = class_find_device_by_of_node(&spi_master_class, node);
 	if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE))
-		dev = class_find_device(&spi_slave_class, NULL, node,
-					__spi_of_controller_match);
+		dev = class_find_device_by_of_node(&spi_slave_class, node);
 	if (!dev)
 		return NULL;
 
diff --git a/include/linux/device.h b/include/linux/device.h
index 3ba376b8b456..29d8d7ad41e6 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -186,6 +186,18 @@ static inline struct device *bus_find_device_by_name(struct bus_type *bus,
 	return bus_find_device(bus, start, name, device_match_name);
 }
 
+/**
+ * bus_find_device_by_of_node : device iterator for locating a particular device
+ * matching the of_node.
+ * @bus: bus type
+ * @np: of_node of the device to match.
+ */
+static inline struct device *
+bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
+{
+	return bus_find_device(bus, NULL, np, device_match_of_node);
+}
+
 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
 					struct device *hint);
 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
@@ -366,6 +378,19 @@ static inline struct device *driver_find_device_by_name(struct device_driver *dr
 	return driver_find_device(drv, NULL, name, device_match_name);
 }
 
+/**
+ * driver_find_device_by_of_node- device iterator for locating a particular device
+ * by of_node pointer.
+ * @driver: the driver we're iterating
+ * @np: of_node pointer to match.
+ */
+static inline struct device *
+driver_find_device_by_of_node(struct device_driver *drv,
+			      const struct device_node *np)
+{
+	return driver_find_device(drv, NULL, np, device_match_of_node);
+}
+
 void driver_deferred_probe_add(struct device *dev);
 int driver_deferred_probe_check_state(struct device *dev);
 int driver_deferred_probe_check_state_continue(struct device *dev);
@@ -507,6 +532,18 @@ static inline struct device *class_find_device_by_name(struct class *class,
 	return class_find_device(class, NULL, name, device_match_name);
 }
 
+/**
+ * class_find_device_by_of_node : device iterator for locating a particular device
+ * matching the of_node.
+ * @class: class type
+ * @np: of_node of the device to match.
+ */
+static inline struct device *
+class_find_device_by_of_node(struct class *class, const struct device_node *np)
+{
+	return class_find_device(class, NULL, np, device_match_of_node);
+}
+
 struct class_attribute {
 	struct attribute attr;
 	ssize_t (*show)(struct class *class, struct class_attribute *attr,
diff --git a/sound/soc/rockchip/rk3399_gru_sound.c b/sound/soc/rockchip/rk3399_gru_sound.c
index c16b0ffe8cfc..d951100bf770 100644
--- a/sound/soc/rockchip/rk3399_gru_sound.c
+++ b/sound/soc/rockchip/rk3399_gru_sound.c
@@ -422,11 +422,6 @@ static const struct dailink_match_data dailink_match[] = {
 	},
 };
 
-static int of_dev_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 static int rockchip_sound_codec_node_match(struct device_node *np_codec)
 {
 	struct device *dev;
@@ -438,8 +433,8 @@ static int rockchip_sound_codec_node_match(struct device_node *np_codec)
 			continue;
 
 		if (dailink_match[i].bus_type) {
-			dev = bus_find_device(dailink_match[i].bus_type, NULL,
-					      np_codec, of_dev_node_match);
+			dev = bus_find_device_by_of_node(dailink_match[i].bus_type,
+							 np_codec);
 			if (!dev)
 				continue;
 			put_device(dev);
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
@ 2019-07-23 22:18   ` Suzuki K Poulose
  0 siblings, 0 replies; 71+ messages in thread
From: Suzuki K Poulose @ 2019-07-23 22:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: gregkh, rafael, linux-arm-kernel, Suzuki K Poulose,
	Maarten Lankhorst, Maxime Ripard, dri-devel, David Airlie,
	Daniel Vetter, devicetree, Florian Fainelli, Frank Rowand,
	Heiko Stuebner, Liam Girdwood, linux-i2c, linux-rockchip,
	linux-spi, Mathieu Poirier, Rob Herring, Srinivas Kandagatla,
	Takashi Iwai, Wolfram

Introduce wrappers for {bus/driver/class}_find_device() to
locate devices by its of_node.

Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <maxime.ripard@bootlin.com>
Cc: dri-devel@lists.freedesktop.org
Cc: David Airlie <airlied@linux.ie>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: devicetree@vger.kernel.org
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Frank Rowand <frowand.list@gmail.com>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: linux-i2c@vger.kernel.org
Cc: linux-rockchip@lists.infradead.org
Cc: linux-spi@vger.kernel.org
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Takashi Iwai <tiwai@suse.com>
Cc: Wolfram Sang <wsa@the-dreams.de>
Cc: Alan Tull <atull@kernel.org>
Cc: Moritz Fischer <mdf@kernel.org>
Cc: linux-fpga@vger.kernel.org
Cc: Peter Rosin <peda@axentia.se>
Cc: Mark Brown <broonie@kernel.org>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Heiner Kallweit <hkallweit1@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Lee Jones <lee.jones@linaro.org>
Cc: Thor Thayer <thor.thayer@linux.intel.com>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Peter Rosin <peda@axentia.se>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 - Dropped the reviewed-by tags from Thor, Mark, Andrew and Peter as the
   patches are mereged, though there are no functional changes.
---
 drivers/amba/tegra-ahb.c              | 11 +-------
 drivers/fpga/fpga-bridge.c            |  8 +-----
 drivers/fpga/fpga-mgr.c               |  8 +-----
 drivers/gpu/drm/drm_mipi_dsi.c        |  7 +----
 drivers/i2c/i2c-core-of.c             |  7 +----
 drivers/mfd/altera-sysmgr.c           | 14 ++--------
 drivers/mux/core.c                    |  7 +----
 drivers/net/phy/mdio_bus.c            |  9 +------
 drivers/nvmem/core.c                  |  7 +----
 drivers/of/of_mdio.c                  |  8 +-----
 drivers/of/platform.c                 |  7 +----
 drivers/regulator/of_regulator.c      |  7 +----
 drivers/spi/spi.c                     | 20 +++------------
 include/linux/device.h                | 37 +++++++++++++++++++++++++++
 sound/soc/rockchip/rk3399_gru_sound.c |  9 ++-----
 15 files changed, 56 insertions(+), 110 deletions(-)

diff --git a/drivers/amba/tegra-ahb.c b/drivers/amba/tegra-ahb.c
index aa64eece77a6..57d3b2e2d007 100644
--- a/drivers/amba/tegra-ahb.c
+++ b/drivers/amba/tegra-ahb.c
@@ -134,22 +134,13 @@ static inline void gizmo_writel(struct tegra_ahb *ahb, u32 value, u32 offset)
 }
 
 #ifdef CONFIG_TEGRA_IOMMU_SMMU
-static int tegra_ahb_match_by_smmu(struct device *dev, const void *data)
-{
-	struct tegra_ahb *ahb = dev_get_drvdata(dev);
-	const struct device_node *dn = data;
-
-	return (ahb->dev->of_node == dn) ? 1 : 0;
-}
-
 int tegra_ahb_enable_smmu(struct device_node *dn)
 {
 	struct device *dev;
 	u32 val;
 	struct tegra_ahb *ahb;
 
-	dev = driver_find_device(&tegra_ahb_driver.driver, NULL, dn,
-				 tegra_ahb_match_by_smmu);
+	dev = driver_find_device_by_of_node(&tegra_ahb_driver.driver, dn);
 	if (!dev)
 		return -EPROBE_DEFER;
 	ahb = dev_get_drvdata(dev);
diff --git a/drivers/fpga/fpga-bridge.c b/drivers/fpga/fpga-bridge.c
index 80bd8f1b2aa6..4bab9028940a 100644
--- a/drivers/fpga/fpga-bridge.c
+++ b/drivers/fpga/fpga-bridge.c
@@ -19,11 +19,6 @@ static struct class *fpga_bridge_class;
 /* Lock for adding/removing bridges to linked lists*/
 static spinlock_t bridge_list_lock;
 
-static int fpga_bridge_of_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /**
  * fpga_bridge_enable - Enable transactions on the bridge
  *
@@ -104,8 +99,7 @@ struct fpga_bridge *of_fpga_bridge_get(struct device_node *np,
 {
 	struct device *dev;
 
-	dev = class_find_device(fpga_bridge_class, NULL, np,
-				fpga_bridge_of_node_match);
+	dev = class_find_device_by_of_node(fpga_bridge_class, np);
 	if (!dev)
 		return ERR_PTR(-ENODEV);
 
diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
index c3866816456a..e05104f5e40c 100644
--- a/drivers/fpga/fpga-mgr.c
+++ b/drivers/fpga/fpga-mgr.c
@@ -482,11 +482,6 @@ struct fpga_manager *fpga_mgr_get(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(fpga_mgr_get);
 
-static int fpga_mgr_of_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /**
  * of_fpga_mgr_get - Given a device node, get a reference to a fpga mgr.
  *
@@ -498,8 +493,7 @@ struct fpga_manager *of_fpga_mgr_get(struct device_node *node)
 {
 	struct device *dev;
 
-	dev = class_find_device(fpga_mgr_class, NULL, node,
-				fpga_mgr_of_node_match);
+	dev = class_find_device_by_of_node(fpga_mgr_class, node);
 	if (!dev)
 		return ERR_PTR(-ENODEV);
 
diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
index ad19df0686c9..bd2498bbd74a 100644
--- a/drivers/gpu/drm/drm_mipi_dsi.c
+++ b/drivers/gpu/drm/drm_mipi_dsi.c
@@ -93,11 +93,6 @@ static struct bus_type mipi_dsi_bus_type = {
 	.pm = &mipi_dsi_device_pm_ops,
 };
 
-static int of_device_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /**
  * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a
  *    device tree node
@@ -110,7 +105,7 @@ struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np)
 {
 	struct device *dev;
 
-	dev = bus_find_device(&mipi_dsi_bus_type, NULL, np, of_device_match);
+	dev = bus_find_device_by_of_node(&mipi_dsi_bus_type, np);
 
 	return dev ? to_mipi_dsi_device(dev) : NULL;
 }
diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
index d1c48dec7118..6f632d543fcc 100644
--- a/drivers/i2c/i2c-core-of.c
+++ b/drivers/i2c/i2c-core-of.c
@@ -113,11 +113,6 @@ void of_i2c_register_devices(struct i2c_adapter *adap)
 	of_node_put(bus);
 }
 
-static int of_dev_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 static int of_dev_or_parent_node_match(struct device *dev, const void *data)
 {
 	if (dev->of_node == data)
@@ -135,7 +130,7 @@ struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
 	struct device *dev;
 	struct i2c_client *client;
 
-	dev = bus_find_device(&i2c_bus_type, NULL, node, of_dev_node_match);
+	dev = bus_find_device_by_of_node(&i2c_bus_type, node);
 	if (!dev)
 		return NULL;
 
diff --git a/drivers/mfd/altera-sysmgr.c b/drivers/mfd/altera-sysmgr.c
index 2ee14d8a6d31..d2a13a547a3c 100644
--- a/drivers/mfd/altera-sysmgr.c
+++ b/drivers/mfd/altera-sysmgr.c
@@ -87,16 +87,6 @@ static struct regmap_config altr_sysmgr_regmap_cfg = {
 	.use_single_write = true,
 };
 
-/**
- * sysmgr_match_phandle
- * Matching function used by driver_find_device().
- * Return: True if match is found, otherwise false.
- */
-static int sysmgr_match_phandle(struct device *dev, const void *data)
-{
-	return dev->of_node == (const struct device_node *)data;
-}
-
 /**
  * altr_sysmgr_regmap_lookup_by_phandle
  * 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,
 	if (!sysmgr_np)
 		return ERR_PTR(-ENODEV);
 
-	dev = driver_find_device(&altr_sysmgr_driver.driver, NULL,
-				 (void *)sysmgr_np, sysmgr_match_phandle);
+	dev = driver_find_device_by_of_node(&altr_sysmgr_driver.driver,
+					    (void *)sysmgr_np);
 	of_node_put(sysmgr_np);
 	if (!dev)
 		return ERR_PTR(-EPROBE_DEFER);
diff --git a/drivers/mux/core.c b/drivers/mux/core.c
index d1271c1ee23c..1fb22388e7e0 100644
--- a/drivers/mux/core.c
+++ b/drivers/mux/core.c
@@ -405,17 +405,12 @@ int mux_control_deselect(struct mux_control *mux)
 }
 EXPORT_SYMBOL_GPL(mux_control_deselect);
 
-static int of_dev_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /* Note this function returns a reference to the mux_chip dev. */
 static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np)
 {
 	struct device *dev;
 
-	dev = class_find_device(&mux_class, NULL, np, of_dev_node_match);
+	dev = class_find_device_by_of_node(&mux_class, np);
 
 	return dev ? to_mux_chip(dev) : NULL;
 }
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index bd04fe762056..ce940871331e 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -262,11 +262,6 @@ static struct class mdio_bus_class = {
 };
 
 #if IS_ENABLED(CONFIG_OF_MDIO)
-/* Helper function for of_mdio_find_bus */
-static int of_mdio_bus_match(struct device *dev, const void *mdio_bus_np)
-{
-	return dev->of_node == mdio_bus_np;
-}
 /**
  * of_mdio_find_bus - Given an mii_bus node, find the mii_bus.
  * @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)
 	if (!mdio_bus_np)
 		return NULL;
 
-	d = class_find_device(&mdio_bus_class, NULL,  mdio_bus_np,
-			      of_mdio_bus_match);
-
+	d = class_find_device_by_of_node(&mdio_bus_class, mdio_bus_np);
 	return d ? to_mii_bus(d) : NULL;
 }
 EXPORT_SYMBOL(of_mdio_find_bus);
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index ac5d945be88a..057d1ff87d5d 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -76,11 +76,6 @@ static struct bus_type nvmem_bus_type = {
 	.name		= "nvmem",
 };
 
-static int of_nvmem_match(struct device *dev, const void *nvmem_np)
-{
-	return dev->of_node == nvmem_np;
-}
-
 static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)
 {
 	struct device *d;
@@ -88,7 +83,7 @@ static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)
 	if (!nvmem_np)
 		return NULL;
 
-	d = bus_find_device(&nvmem_bus_type, NULL, nvmem_np, of_nvmem_match);
+	d = bus_find_device_by_of_node(&nvmem_bus_type, nvmem_np);
 
 	if (!d)
 		return NULL;
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index 44f53496cab1..000b95787df1 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -280,12 +280,6 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
 }
 EXPORT_SYMBOL(of_mdiobus_register);
 
-/* Helper function for of_phy_find_device */
-static int of_phy_match(struct device *dev, const void *phy_np)
-{
-	return dev->of_node == phy_np;
-}
-
 /**
  * of_phy_find_device - Give a PHY node, find the phy_device
  * @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)
 	if (!phy_np)
 		return NULL;
 
-	d = bus_find_device(&mdio_bus_type, NULL, phy_np, of_phy_match);
+	d = bus_find_device_by_of_node(&mdio_bus_type, phy_np);
 	if (d) {
 		mdiodev = to_mdio_device(d);
 		if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 7801e25e6895..b47a2292fe8e 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -37,11 +37,6 @@ static const struct of_device_id of_skipped_node_table[] = {
 	{} /* Empty terminated list */
 };
 
-static int of_dev_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /**
  * of_find_device_by_node - Find the platform_device associated with a node
  * @np: Pointer to device tree node
@@ -55,7 +50,7 @@ struct platform_device *of_find_device_by_node(struct device_node *np)
 {
 	struct device *dev;
 
-	dev = bus_find_device(&platform_bus_type, NULL, np, of_dev_node_match);
+	dev = bus_find_device_by_of_node(&platform_bus_type, np);
 	return dev ? to_platform_device(dev) : NULL;
 }
 EXPORT_SYMBOL(of_find_device_by_node);
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 397918ebba55..20dcc9c03adc 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -460,16 +460,11 @@ struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
 	return NULL;
 }
 
-static int of_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 struct regulator_dev *of_find_regulator_by_node(struct device_node *np)
 {
 	struct device *dev;
 
-	dev = class_find_device(&regulator_class, NULL, np, of_node_match);
+	dev = class_find_device_by_of_node(&regulator_class, np);
 
 	return dev ? dev_to_rdev(dev) : NULL;
 }
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 75ac046cae52..a591da87981a 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -3652,37 +3652,25 @@ EXPORT_SYMBOL_GPL(spi_write_then_read);
 /*-------------------------------------------------------------------------*/
 
 #if IS_ENABLED(CONFIG_OF)
-static int __spi_of_device_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /* must call put_device() when done with returned spi_device device */
 struct spi_device *of_find_spi_device_by_node(struct device_node *node)
 {
-	struct device *dev = bus_find_device(&spi_bus_type, NULL, node,
-						__spi_of_device_match);
+	struct device *dev = bus_find_device_by_of_node(&spi_bus_type, node);
+
 	return dev ? to_spi_device(dev) : NULL;
 }
 EXPORT_SYMBOL_GPL(of_find_spi_device_by_node);
 #endif /* IS_ENABLED(CONFIG_OF) */
 
 #if IS_ENABLED(CONFIG_OF_DYNAMIC)
-static int __spi_of_controller_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /* the spi controllers are not using spi_bus, so we find it with another way */
 static struct spi_controller *of_find_spi_controller_by_node(struct device_node *node)
 {
 	struct device *dev;
 
-	dev = class_find_device(&spi_master_class, NULL, node,
-				__spi_of_controller_match);
+	dev = class_find_device_by_of_node(&spi_master_class, node);
 	if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE))
-		dev = class_find_device(&spi_slave_class, NULL, node,
-					__spi_of_controller_match);
+		dev = class_find_device_by_of_node(&spi_slave_class, node);
 	if (!dev)
 		return NULL;
 
diff --git a/include/linux/device.h b/include/linux/device.h
index 3ba376b8b456..29d8d7ad41e6 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -186,6 +186,18 @@ static inline struct device *bus_find_device_by_name(struct bus_type *bus,
 	return bus_find_device(bus, start, name, device_match_name);
 }
 
+/**
+ * bus_find_device_by_of_node : device iterator for locating a particular device
+ * matching the of_node.
+ * @bus: bus type
+ * @np: of_node of the device to match.
+ */
+static inline struct device *
+bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
+{
+	return bus_find_device(bus, NULL, np, device_match_of_node);
+}
+
 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
 					struct device *hint);
 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
@@ -366,6 +378,19 @@ static inline struct device *driver_find_device_by_name(struct device_driver *dr
 	return driver_find_device(drv, NULL, name, device_match_name);
 }
 
+/**
+ * driver_find_device_by_of_node- device iterator for locating a particular device
+ * by of_node pointer.
+ * @driver: the driver we're iterating
+ * @np: of_node pointer to match.
+ */
+static inline struct device *
+driver_find_device_by_of_node(struct device_driver *drv,
+			      const struct device_node *np)
+{
+	return driver_find_device(drv, NULL, np, device_match_of_node);
+}
+
 void driver_deferred_probe_add(struct device *dev);
 int driver_deferred_probe_check_state(struct device *dev);
 int driver_deferred_probe_check_state_continue(struct device *dev);
@@ -507,6 +532,18 @@ static inline struct device *class_find_device_by_name(struct class *class,
 	return class_find_device(class, NULL, name, device_match_name);
 }
 
+/**
+ * class_find_device_by_of_node : device iterator for locating a particular device
+ * matching the of_node.
+ * @class: class type
+ * @np: of_node of the device to match.
+ */
+static inline struct device *
+class_find_device_by_of_node(struct class *class, const struct device_node *np)
+{
+	return class_find_device(class, NULL, np, device_match_of_node);
+}
+
 struct class_attribute {
 	struct attribute attr;
 	ssize_t (*show)(struct class *class, struct class_attribute *attr,
diff --git a/sound/soc/rockchip/rk3399_gru_sound.c b/sound/soc/rockchip/rk3399_gru_sound.c
index c16b0ffe8cfc..d951100bf770 100644
--- a/sound/soc/rockchip/rk3399_gru_sound.c
+++ b/sound/soc/rockchip/rk3399_gru_sound.c
@@ -422,11 +422,6 @@ static const struct dailink_match_data dailink_match[] = {
 	},
 };
 
-static int of_dev_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 static int rockchip_sound_codec_node_match(struct device_node *np_codec)
 {
 	struct device *dev;
@@ -438,8 +433,8 @@ static int rockchip_sound_codec_node_match(struct device_node *np_codec)
 			continue;
 
 		if (dailink_match[i].bus_type) {
-			dev = bus_find_device(dailink_match[i].bus_type, NULL,
-					      np_codec, of_dev_node_match);
+			dev = bus_find_device_by_of_node(dailink_match[i].bus_type,
+							 np_codec);
 			if (!dev)
 				continue;
 			put_device(dev);
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
@ 2019-07-23 22:18   ` Suzuki K Poulose
  0 siblings, 0 replies; 71+ messages in thread
From: Suzuki K Poulose @ 2019-07-23 22:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Lunn, Thor Thayer, Heiko Stuebner, rafael, Maxime Ripard,
	linux-fpga, dri-devel, Takashi Iwai, David S. Miller,
	Srinivas Kandagatla, linux-i2c, Frank Rowand, Florian Fainelli,
	linux-rockchip, Lee Jones, Wolfram Sang, David Airlie,
	Jiri Slaby, devicetree, Alan Tull, Suzuki K Poulose,
	Maarten Lankhorst, Rob Herring, Moritz Fischer, linux-arm-kernel,
	Mathieu Poirier, gregkh, Liam Girdwood, linux-spi, Mark Brown,
	Daniel Vetter, Peter Rosin, Heiner Kallweit

Introduce wrappers for {bus/driver/class}_find_device() to
locate devices by its of_node.

Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <maxime.ripard@bootlin.com>
Cc: dri-devel@lists.freedesktop.org
Cc: David Airlie <airlied@linux.ie>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: devicetree@vger.kernel.org
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Frank Rowand <frowand.list@gmail.com>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: linux-i2c@vger.kernel.org
Cc: linux-rockchip@lists.infradead.org
Cc: linux-spi@vger.kernel.org
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Takashi Iwai <tiwai@suse.com>
Cc: Wolfram Sang <wsa@the-dreams.de>
Cc: Alan Tull <atull@kernel.org>
Cc: Moritz Fischer <mdf@kernel.org>
Cc: linux-fpga@vger.kernel.org
Cc: Peter Rosin <peda@axentia.se>
Cc: Mark Brown <broonie@kernel.org>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Heiner Kallweit <hkallweit1@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Lee Jones <lee.jones@linaro.org>
Cc: Thor Thayer <thor.thayer@linux.intel.com>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Peter Rosin <peda@axentia.se>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 - Dropped the reviewed-by tags from Thor, Mark, Andrew and Peter as the
   patches are mereged, though there are no functional changes.
---
 drivers/amba/tegra-ahb.c              | 11 +-------
 drivers/fpga/fpga-bridge.c            |  8 +-----
 drivers/fpga/fpga-mgr.c               |  8 +-----
 drivers/gpu/drm/drm_mipi_dsi.c        |  7 +----
 drivers/i2c/i2c-core-of.c             |  7 +----
 drivers/mfd/altera-sysmgr.c           | 14 ++--------
 drivers/mux/core.c                    |  7 +----
 drivers/net/phy/mdio_bus.c            |  9 +------
 drivers/nvmem/core.c                  |  7 +----
 drivers/of/of_mdio.c                  |  8 +-----
 drivers/of/platform.c                 |  7 +----
 drivers/regulator/of_regulator.c      |  7 +----
 drivers/spi/spi.c                     | 20 +++------------
 include/linux/device.h                | 37 +++++++++++++++++++++++++++
 sound/soc/rockchip/rk3399_gru_sound.c |  9 ++-----
 15 files changed, 56 insertions(+), 110 deletions(-)

diff --git a/drivers/amba/tegra-ahb.c b/drivers/amba/tegra-ahb.c
index aa64eece77a6..57d3b2e2d007 100644
--- a/drivers/amba/tegra-ahb.c
+++ b/drivers/amba/tegra-ahb.c
@@ -134,22 +134,13 @@ static inline void gizmo_writel(struct tegra_ahb *ahb, u32 value, u32 offset)
 }
 
 #ifdef CONFIG_TEGRA_IOMMU_SMMU
-static int tegra_ahb_match_by_smmu(struct device *dev, const void *data)
-{
-	struct tegra_ahb *ahb = dev_get_drvdata(dev);
-	const struct device_node *dn = data;
-
-	return (ahb->dev->of_node == dn) ? 1 : 0;
-}
-
 int tegra_ahb_enable_smmu(struct device_node *dn)
 {
 	struct device *dev;
 	u32 val;
 	struct tegra_ahb *ahb;
 
-	dev = driver_find_device(&tegra_ahb_driver.driver, NULL, dn,
-				 tegra_ahb_match_by_smmu);
+	dev = driver_find_device_by_of_node(&tegra_ahb_driver.driver, dn);
 	if (!dev)
 		return -EPROBE_DEFER;
 	ahb = dev_get_drvdata(dev);
diff --git a/drivers/fpga/fpga-bridge.c b/drivers/fpga/fpga-bridge.c
index 80bd8f1b2aa6..4bab9028940a 100644
--- a/drivers/fpga/fpga-bridge.c
+++ b/drivers/fpga/fpga-bridge.c
@@ -19,11 +19,6 @@ static struct class *fpga_bridge_class;
 /* Lock for adding/removing bridges to linked lists*/
 static spinlock_t bridge_list_lock;
 
-static int fpga_bridge_of_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /**
  * fpga_bridge_enable - Enable transactions on the bridge
  *
@@ -104,8 +99,7 @@ struct fpga_bridge *of_fpga_bridge_get(struct device_node *np,
 {
 	struct device *dev;
 
-	dev = class_find_device(fpga_bridge_class, NULL, np,
-				fpga_bridge_of_node_match);
+	dev = class_find_device_by_of_node(fpga_bridge_class, np);
 	if (!dev)
 		return ERR_PTR(-ENODEV);
 
diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
index c3866816456a..e05104f5e40c 100644
--- a/drivers/fpga/fpga-mgr.c
+++ b/drivers/fpga/fpga-mgr.c
@@ -482,11 +482,6 @@ struct fpga_manager *fpga_mgr_get(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(fpga_mgr_get);
 
-static int fpga_mgr_of_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /**
  * of_fpga_mgr_get - Given a device node, get a reference to a fpga mgr.
  *
@@ -498,8 +493,7 @@ struct fpga_manager *of_fpga_mgr_get(struct device_node *node)
 {
 	struct device *dev;
 
-	dev = class_find_device(fpga_mgr_class, NULL, node,
-				fpga_mgr_of_node_match);
+	dev = class_find_device_by_of_node(fpga_mgr_class, node);
 	if (!dev)
 		return ERR_PTR(-ENODEV);
 
diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
index ad19df0686c9..bd2498bbd74a 100644
--- a/drivers/gpu/drm/drm_mipi_dsi.c
+++ b/drivers/gpu/drm/drm_mipi_dsi.c
@@ -93,11 +93,6 @@ static struct bus_type mipi_dsi_bus_type = {
 	.pm = &mipi_dsi_device_pm_ops,
 };
 
-static int of_device_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /**
  * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a
  *    device tree node
@@ -110,7 +105,7 @@ struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np)
 {
 	struct device *dev;
 
-	dev = bus_find_device(&mipi_dsi_bus_type, NULL, np, of_device_match);
+	dev = bus_find_device_by_of_node(&mipi_dsi_bus_type, np);
 
 	return dev ? to_mipi_dsi_device(dev) : NULL;
 }
diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
index d1c48dec7118..6f632d543fcc 100644
--- a/drivers/i2c/i2c-core-of.c
+++ b/drivers/i2c/i2c-core-of.c
@@ -113,11 +113,6 @@ void of_i2c_register_devices(struct i2c_adapter *adap)
 	of_node_put(bus);
 }
 
-static int of_dev_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 static int of_dev_or_parent_node_match(struct device *dev, const void *data)
 {
 	if (dev->of_node == data)
@@ -135,7 +130,7 @@ struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
 	struct device *dev;
 	struct i2c_client *client;
 
-	dev = bus_find_device(&i2c_bus_type, NULL, node, of_dev_node_match);
+	dev = bus_find_device_by_of_node(&i2c_bus_type, node);
 	if (!dev)
 		return NULL;
 
diff --git a/drivers/mfd/altera-sysmgr.c b/drivers/mfd/altera-sysmgr.c
index 2ee14d8a6d31..d2a13a547a3c 100644
--- a/drivers/mfd/altera-sysmgr.c
+++ b/drivers/mfd/altera-sysmgr.c
@@ -87,16 +87,6 @@ static struct regmap_config altr_sysmgr_regmap_cfg = {
 	.use_single_write = true,
 };
 
-/**
- * sysmgr_match_phandle
- * Matching function used by driver_find_device().
- * Return: True if match is found, otherwise false.
- */
-static int sysmgr_match_phandle(struct device *dev, const void *data)
-{
-	return dev->of_node == (const struct device_node *)data;
-}
-
 /**
  * altr_sysmgr_regmap_lookup_by_phandle
  * 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,
 	if (!sysmgr_np)
 		return ERR_PTR(-ENODEV);
 
-	dev = driver_find_device(&altr_sysmgr_driver.driver, NULL,
-				 (void *)sysmgr_np, sysmgr_match_phandle);
+	dev = driver_find_device_by_of_node(&altr_sysmgr_driver.driver,
+					    (void *)sysmgr_np);
 	of_node_put(sysmgr_np);
 	if (!dev)
 		return ERR_PTR(-EPROBE_DEFER);
diff --git a/drivers/mux/core.c b/drivers/mux/core.c
index d1271c1ee23c..1fb22388e7e0 100644
--- a/drivers/mux/core.c
+++ b/drivers/mux/core.c
@@ -405,17 +405,12 @@ int mux_control_deselect(struct mux_control *mux)
 }
 EXPORT_SYMBOL_GPL(mux_control_deselect);
 
-static int of_dev_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /* Note this function returns a reference to the mux_chip dev. */
 static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np)
 {
 	struct device *dev;
 
-	dev = class_find_device(&mux_class, NULL, np, of_dev_node_match);
+	dev = class_find_device_by_of_node(&mux_class, np);
 
 	return dev ? to_mux_chip(dev) : NULL;
 }
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index bd04fe762056..ce940871331e 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -262,11 +262,6 @@ static struct class mdio_bus_class = {
 };
 
 #if IS_ENABLED(CONFIG_OF_MDIO)
-/* Helper function for of_mdio_find_bus */
-static int of_mdio_bus_match(struct device *dev, const void *mdio_bus_np)
-{
-	return dev->of_node == mdio_bus_np;
-}
 /**
  * of_mdio_find_bus - Given an mii_bus node, find the mii_bus.
  * @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)
 	if (!mdio_bus_np)
 		return NULL;
 
-	d = class_find_device(&mdio_bus_class, NULL,  mdio_bus_np,
-			      of_mdio_bus_match);
-
+	d = class_find_device_by_of_node(&mdio_bus_class, mdio_bus_np);
 	return d ? to_mii_bus(d) : NULL;
 }
 EXPORT_SYMBOL(of_mdio_find_bus);
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index ac5d945be88a..057d1ff87d5d 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -76,11 +76,6 @@ static struct bus_type nvmem_bus_type = {
 	.name		= "nvmem",
 };
 
-static int of_nvmem_match(struct device *dev, const void *nvmem_np)
-{
-	return dev->of_node == nvmem_np;
-}
-
 static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)
 {
 	struct device *d;
@@ -88,7 +83,7 @@ static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)
 	if (!nvmem_np)
 		return NULL;
 
-	d = bus_find_device(&nvmem_bus_type, NULL, nvmem_np, of_nvmem_match);
+	d = bus_find_device_by_of_node(&nvmem_bus_type, nvmem_np);
 
 	if (!d)
 		return NULL;
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index 44f53496cab1..000b95787df1 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -280,12 +280,6 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
 }
 EXPORT_SYMBOL(of_mdiobus_register);
 
-/* Helper function for of_phy_find_device */
-static int of_phy_match(struct device *dev, const void *phy_np)
-{
-	return dev->of_node == phy_np;
-}
-
 /**
  * of_phy_find_device - Give a PHY node, find the phy_device
  * @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)
 	if (!phy_np)
 		return NULL;
 
-	d = bus_find_device(&mdio_bus_type, NULL, phy_np, of_phy_match);
+	d = bus_find_device_by_of_node(&mdio_bus_type, phy_np);
 	if (d) {
 		mdiodev = to_mdio_device(d);
 		if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 7801e25e6895..b47a2292fe8e 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -37,11 +37,6 @@ static const struct of_device_id of_skipped_node_table[] = {
 	{} /* Empty terminated list */
 };
 
-static int of_dev_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /**
  * of_find_device_by_node - Find the platform_device associated with a node
  * @np: Pointer to device tree node
@@ -55,7 +50,7 @@ struct platform_device *of_find_device_by_node(struct device_node *np)
 {
 	struct device *dev;
 
-	dev = bus_find_device(&platform_bus_type, NULL, np, of_dev_node_match);
+	dev = bus_find_device_by_of_node(&platform_bus_type, np);
 	return dev ? to_platform_device(dev) : NULL;
 }
 EXPORT_SYMBOL(of_find_device_by_node);
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 397918ebba55..20dcc9c03adc 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -460,16 +460,11 @@ struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
 	return NULL;
 }
 
-static int of_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 struct regulator_dev *of_find_regulator_by_node(struct device_node *np)
 {
 	struct device *dev;
 
-	dev = class_find_device(&regulator_class, NULL, np, of_node_match);
+	dev = class_find_device_by_of_node(&regulator_class, np);
 
 	return dev ? dev_to_rdev(dev) : NULL;
 }
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 75ac046cae52..a591da87981a 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -3652,37 +3652,25 @@ EXPORT_SYMBOL_GPL(spi_write_then_read);
 /*-------------------------------------------------------------------------*/
 
 #if IS_ENABLED(CONFIG_OF)
-static int __spi_of_device_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /* must call put_device() when done with returned spi_device device */
 struct spi_device *of_find_spi_device_by_node(struct device_node *node)
 {
-	struct device *dev = bus_find_device(&spi_bus_type, NULL, node,
-						__spi_of_device_match);
+	struct device *dev = bus_find_device_by_of_node(&spi_bus_type, node);
+
 	return dev ? to_spi_device(dev) : NULL;
 }
 EXPORT_SYMBOL_GPL(of_find_spi_device_by_node);
 #endif /* IS_ENABLED(CONFIG_OF) */
 
 #if IS_ENABLED(CONFIG_OF_DYNAMIC)
-static int __spi_of_controller_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /* the spi controllers are not using spi_bus, so we find it with another way */
 static struct spi_controller *of_find_spi_controller_by_node(struct device_node *node)
 {
 	struct device *dev;
 
-	dev = class_find_device(&spi_master_class, NULL, node,
-				__spi_of_controller_match);
+	dev = class_find_device_by_of_node(&spi_master_class, node);
 	if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE))
-		dev = class_find_device(&spi_slave_class, NULL, node,
-					__spi_of_controller_match);
+		dev = class_find_device_by_of_node(&spi_slave_class, node);
 	if (!dev)
 		return NULL;
 
diff --git a/include/linux/device.h b/include/linux/device.h
index 3ba376b8b456..29d8d7ad41e6 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -186,6 +186,18 @@ static inline struct device *bus_find_device_by_name(struct bus_type *bus,
 	return bus_find_device(bus, start, name, device_match_name);
 }
 
+/**
+ * bus_find_device_by_of_node : device iterator for locating a particular device
+ * matching the of_node.
+ * @bus: bus type
+ * @np: of_node of the device to match.
+ */
+static inline struct device *
+bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
+{
+	return bus_find_device(bus, NULL, np, device_match_of_node);
+}
+
 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
 					struct device *hint);
 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
@@ -366,6 +378,19 @@ static inline struct device *driver_find_device_by_name(struct device_driver *dr
 	return driver_find_device(drv, NULL, name, device_match_name);
 }
 
+/**
+ * driver_find_device_by_of_node- device iterator for locating a particular device
+ * by of_node pointer.
+ * @driver: the driver we're iterating
+ * @np: of_node pointer to match.
+ */
+static inline struct device *
+driver_find_device_by_of_node(struct device_driver *drv,
+			      const struct device_node *np)
+{
+	return driver_find_device(drv, NULL, np, device_match_of_node);
+}
+
 void driver_deferred_probe_add(struct device *dev);
 int driver_deferred_probe_check_state(struct device *dev);
 int driver_deferred_probe_check_state_continue(struct device *dev);
@@ -507,6 +532,18 @@ static inline struct device *class_find_device_by_name(struct class *class,
 	return class_find_device(class, NULL, name, device_match_name);
 }
 
+/**
+ * class_find_device_by_of_node : device iterator for locating a particular device
+ * matching the of_node.
+ * @class: class type
+ * @np: of_node of the device to match.
+ */
+static inline struct device *
+class_find_device_by_of_node(struct class *class, const struct device_node *np)
+{
+	return class_find_device(class, NULL, np, device_match_of_node);
+}
+
 struct class_attribute {
 	struct attribute attr;
 	ssize_t (*show)(struct class *class, struct class_attribute *attr,
diff --git a/sound/soc/rockchip/rk3399_gru_sound.c b/sound/soc/rockchip/rk3399_gru_sound.c
index c16b0ffe8cfc..d951100bf770 100644
--- a/sound/soc/rockchip/rk3399_gru_sound.c
+++ b/sound/soc/rockchip/rk3399_gru_sound.c
@@ -422,11 +422,6 @@ static const struct dailink_match_data dailink_match[] = {
 	},
 };
 
-static int of_dev_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 static int rockchip_sound_codec_node_match(struct device_node *np_codec)
 {
 	struct device *dev;
@@ -438,8 +433,8 @@ static int rockchip_sound_codec_node_match(struct device_node *np_codec)
 			continue;
 
 		if (dailink_match[i].bus_type) {
-			dev = bus_find_device(dailink_match[i].bus_type, NULL,
-					      np_codec, of_dev_node_match);
+			dev = bus_find_device_by_of_node(dailink_match[i].bus_type,
+							 np_codec);
 			if (!dev)
 				continue;
 			put_device(dev);
-- 
2.21.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH v3 3/7] drivers: Introduce device lookup variants by fwnode
  2019-07-23 22:18 ` Suzuki K Poulose
@ 2019-07-23 22:18   ` Suzuki K Poulose
  -1 siblings, 0 replies; 71+ messages in thread
From: Suzuki K Poulose @ 2019-07-23 22:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: gregkh, rafael, linux-arm-kernel, Suzuki K Poulose,
	David S. Miller, Doug Ledford, Heikki Krogerus, Jason Gunthorpe,
	linux-usb, Ulf Hansson, Joe Perches, Mathieu Poirier,
	Will Deacon, Robin Murphy, Joerg Roedel

Add a helper to match the firmware node handle of a device and provide
wrappers for {bus/class/driver}_find_device() APIs to avoid proliferation
of duplicate custom match functions.

Cc: "David S. Miller" <davem@davemloft.net>
Cc: Doug Ledford <dledford@redhat.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: linux-usb@vger.kernel.org
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Joe Perches <joe@perches.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Joerg Roedel <joro@8bytes.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/base/core.c                           |  6 +++
 drivers/base/devcon.c                         |  8 +---
 .../hwtracing/coresight/coresight-platform.c  | 11 +-----
 drivers/hwtracing/coresight/coresight-priv.h  |  2 -
 drivers/hwtracing/coresight/coresight.c       |  4 +-
 drivers/infiniband/hw/hns/hns_roce_hw_v1.c    |  8 +---
 drivers/iommu/arm-smmu-v3.c                   |  9 +----
 drivers/iommu/arm-smmu.c                      |  9 +----
 .../ethernet/hisilicon/hns/hns_dsaf_misc.c    |  8 +---
 drivers/usb/roles/class.c                     |  8 +---
 drivers/usb/typec/class.c                     |  8 +---
 include/linux/device.h                        | 39 +++++++++++++++++++
 12 files changed, 57 insertions(+), 63 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index fb83647d685a..e8f81a667545 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3368,3 +3368,9 @@ int device_match_of_node(struct device *dev, const void *np)
 	return dev->of_node == np;
 }
 EXPORT_SYMBOL_GPL(device_match_of_node);
+
+int device_match_fwnode(struct device *dev, const void *fwnode)
+{
+	return dev_fwnode(dev) == fwnode;
+}
+EXPORT_SYMBOL_GPL(device_match_fwnode);
diff --git a/drivers/base/devcon.c b/drivers/base/devcon.c
index 09f28479b243..1d488dc5dd0c 100644
--- a/drivers/base/devcon.c
+++ b/drivers/base/devcon.c
@@ -133,19 +133,13 @@ static struct bus_type *generic_match_buses[] = {
 	NULL,
 };
 
-static int device_fwnode_match(struct device *dev, const void *fwnode)
-{
-	return dev_fwnode(dev) == fwnode;
-}
-
 static void *device_connection_fwnode_match(struct device_connection *con)
 {
 	struct bus_type *bus;
 	struct device *dev;
 
 	for (bus = generic_match_buses[0]; bus; bus++) {
-		dev = bus_find_device(bus, NULL, (void *)con->fwnode,
-				      device_fwnode_match);
+		dev = bus_find_device_by_fwnode(bus, con->fwnode);
 		if (dev && !strncmp(dev_name(dev), con->id, strlen(con->id)))
 			return dev;
 
diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
index dad7d96c5943..3c5bee429105 100644
--- a/drivers/hwtracing/coresight/coresight-platform.c
+++ b/drivers/hwtracing/coresight/coresight-platform.c
@@ -37,11 +37,6 @@ static int coresight_alloc_conns(struct device *dev,
 	return 0;
 }
 
-int coresight_device_fwnode_match(struct device *dev, const void *fwnode)
-{
-	return dev_fwnode(dev) == fwnode;
-}
-
 static struct device *
 coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
 {
@@ -51,8 +46,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
 	 * If we have a non-configurable replicator, it will be found on the
 	 * platform bus.
 	 */
-	dev = bus_find_device(&platform_bus_type, NULL,
-			      fwnode, coresight_device_fwnode_match);
+	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
 	if (dev)
 		return dev;
 
@@ -60,8 +54,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
 	 * We have a configurable component - circle through the AMBA bus
 	 * looking for the device that matches the endpoint node.
 	 */
-	return bus_find_device(&amba_bustype, NULL,
-			       fwnode, coresight_device_fwnode_match);
+	return bus_find_device_by_fwnode(&amba_bustype, fwnode);
 }
 
 #ifdef CONFIG_OF
diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
index 7d401790dd7e..61d7f9ff054d 100644
--- a/drivers/hwtracing/coresight/coresight-priv.h
+++ b/drivers/hwtracing/coresight/coresight-priv.h
@@ -202,6 +202,4 @@ static inline void *coresight_get_uci_data(const struct amba_id *id)
 
 void coresight_release_platform_data(struct coresight_platform_data *pdata);
 
-int coresight_device_fwnode_match(struct device *dev, const void *fwnode);
-
 #endif
diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
index 55db77f6410b..6453c67a4d01 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -1046,9 +1046,7 @@ static void coresight_fixup_device_conns(struct coresight_device *csdev)
 		struct coresight_connection *conn = &csdev->pdata->conns[i];
 		struct device *dev = NULL;
 
-		dev = bus_find_device(&coresight_bustype, NULL,
-				      (void *)conn->child_fwnode,
-				      coresight_device_fwnode_match);
+		dev = bus_find_device_by_fwnode(&coresight_bustype, conn->child_fwnode);
 		if (dev) {
 			conn->child_dev = to_coresight_device(dev);
 			/* and put reference from 'bus_find_device()' */
diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
index 81e6dedb1e02..fa05e943038a 100644
--- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
+++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
@@ -4499,19 +4499,13 @@ static const struct acpi_device_id hns_roce_acpi_match[] = {
 };
 MODULE_DEVICE_TABLE(acpi, hns_roce_acpi_match);
 
-static int hns_roce_node_match(struct device *dev, const void *fwnode)
-{
-	return dev->fwnode == fwnode;
-}
-
 static struct
 platform_device *hns_roce_find_pdev(struct fwnode_handle *fwnode)
 {
 	struct device *dev;
 
 	/* get the 'device' corresponding to the matching 'fwnode' */
-	dev = bus_find_device(&platform_bus_type, NULL,
-			      fwnode, hns_roce_node_match);
+	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
 	/* get the platform device */
 	return dev ? to_platform_device(dev) : NULL;
 }
diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c
index a9a9fabd3968..6f0e13fa5e1a 100644
--- a/drivers/iommu/arm-smmu-v3.c
+++ b/drivers/iommu/arm-smmu-v3.c
@@ -2034,16 +2034,11 @@ arm_smmu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova)
 
 static struct platform_driver arm_smmu_driver;
 
-static int arm_smmu_match_node(struct device *dev, const void *data)
-{
-	return dev->fwnode == data;
-}
-
 static
 struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
 {
-	struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL,
-						fwnode, arm_smmu_match_node);
+	struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver,
+							  fwnode);
 	put_device(dev);
 	return dev ? dev_get_drvdata(dev) : NULL;
 }
diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index 64977c131ee6..aa06498f291d 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -1426,16 +1426,11 @@ static bool arm_smmu_capable(enum iommu_cap cap)
 	}
 }
 
-static int arm_smmu_match_node(struct device *dev, const void *data)
-{
-	return dev->fwnode == data;
-}
-
 static
 struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
 {
-	struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL,
-						fwnode, arm_smmu_match_node);
+	struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver,
+							  fwnode);
 	put_device(dev);
 	return dev ? dev_get_drvdata(dev) : NULL;
 }
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
index bb6586d0e5af..ed3829ae4ef1 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
@@ -754,17 +754,11 @@ struct dsaf_misc_op *hns_misc_op_get(struct dsaf_device *dsaf_dev)
 	return (void *)misc_op;
 }
 
-static int hns_dsaf_dev_match(struct device *dev, const void *fwnode)
-{
-	return dev->fwnode == fwnode;
-}
-
 struct
 platform_device *hns_dsaf_find_platform_device(struct fwnode_handle *fwnode)
 {
 	struct device *dev;
 
-	dev = bus_find_device(&platform_bus_type, NULL,
-			      fwnode, hns_dsaf_dev_match);
+	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
 	return dev ? to_platform_device(dev) : NULL;
 }
diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
index c8efe60e2465..0526efbc4922 100644
--- a/drivers/usb/roles/class.c
+++ b/drivers/usb/roles/class.c
@@ -85,11 +85,6 @@ enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw)
 }
 EXPORT_SYMBOL_GPL(usb_role_switch_get_role);
 
-static int switch_fwnode_match(struct device *dev, const void *fwnode)
-{
-	return dev_fwnode(dev) == fwnode;
-}
-
 static void *usb_role_switch_match(struct device_connection *con, int ep,
 				   void *data)
 {
@@ -99,8 +94,7 @@ static void *usb_role_switch_match(struct device_connection *con, int ep,
 		if (con->id && !fwnode_property_present(con->fwnode, con->id))
 			return NULL;
 
-		dev = class_find_device(role_class, NULL, con->fwnode,
-					switch_fwnode_match);
+		dev = class_find_device_by_fwnode(role_class, con->fwnode);
 	} else {
 		dev = class_find_device_by_name(role_class, con->endpoint[ep]);
 	}
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 9b0d15b487e5..94a3eda62add 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -205,11 +205,6 @@ static void typec_altmode_put_partner(struct altmode *altmode)
 	put_device(&adev->dev);
 }
 
-static int typec_port_fwnode_match(struct device *dev, const void *fwnode)
-{
-	return dev_fwnode(dev) == fwnode;
-}
-
 static void *typec_port_match(struct device_connection *con, int ep, void *data)
 {
 	struct device *dev;
@@ -219,8 +214,7 @@ static void *typec_port_match(struct device_connection *con, int ep, void *data)
 	 * we need to return ERR_PTR(-PROBE_DEFER) when there is no device.
 	 */
 	if (con->fwnode)
-		return class_find_device(typec_class, NULL, con->fwnode,
-					 typec_port_fwnode_match);
+		return class_find_device_by_fwnode(typec_class, con->fwnode);
 
 	dev = class_find_device_by_name(typec_class, con->endpoint[ep]);
 
diff --git a/include/linux/device.h b/include/linux/device.h
index 29d8d7ad41e6..7133fc1c285d 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -166,6 +166,7 @@ void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
 
 int device_match_name(struct device *dev, const void *name);
 int device_match_of_node(struct device *dev, const void *np);
+int device_match_fwnode(struct device *dev, const void *fwnode);
 
 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
 		     int (*fn)(struct device *dev, void *data));
@@ -198,6 +199,18 @@ bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
 	return bus_find_device(bus, NULL, np, device_match_of_node);
 }
 
+/**
+ * bus_find_device_by_fwnode : device iterator for locating a particular device
+ * matching the fwnode.
+ * @bus: bus type
+ * @fwnode: fwnode of the device to match.
+ */
+static inline struct device *
+bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwnode)
+{
+	return bus_find_device(bus, NULL, fwnode, device_match_fwnode);
+}
+
 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
 					struct device *hint);
 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
@@ -391,6 +404,19 @@ driver_find_device_by_of_node(struct device_driver *drv,
 	return driver_find_device(drv, NULL, np, device_match_of_node);
 }
 
+/**
+ * driver_find_device_by_fwnode- device iterator for locating a particular device
+ * by fwnode pointer.
+ * @driver: the driver we're iterating
+ * @fwnode: fwnode pointer to match.
+ */
+static inline struct device *
+driver_find_device_by_fwnode(struct device_driver *drv,
+			     const struct fwnode_handle *fwnode)
+{
+	return driver_find_device(drv, NULL, fwnode, device_match_fwnode);
+}
+
 void driver_deferred_probe_add(struct device *dev);
 int driver_deferred_probe_check_state(struct device *dev);
 int driver_deferred_probe_check_state_continue(struct device *dev);
@@ -544,6 +570,19 @@ class_find_device_by_of_node(struct class *class, const struct device_node *np)
 	return class_find_device(class, NULL, np, device_match_of_node);
 }
 
+/**
+ * class_find_device_by_fwnode : device iterator for locating a particular device
+ * matching the fwnode.
+ * @class: class type
+ * @fwnode: fwnode of the device to match.
+ */
+static inline struct device *
+class_find_device_by_fwnode(struct class *class,
+			    const struct fwnode_handle *fwnode)
+{
+	return class_find_device(class, NULL, fwnode, device_match_fwnode);
+}
+
 struct class_attribute {
 	struct attribute attr;
 	ssize_t (*show)(struct class *class, struct class_attribute *attr,
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH v3 3/7] drivers: Introduce device lookup variants by fwnode
@ 2019-07-23 22:18   ` Suzuki K Poulose
  0 siblings, 0 replies; 71+ messages in thread
From: Suzuki K Poulose @ 2019-07-23 22:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ulf Hansson, Heikki Krogerus, Mathieu Poirier, Suzuki K Poulose,
	gregkh, Joerg Roedel, rafael, Will Deacon, Jason Gunthorpe,
	Doug Ledford, linux-usb, Joe Perches, Robin Murphy,
	David S. Miller, linux-arm-kernel

Add a helper to match the firmware node handle of a device and provide
wrappers for {bus/class/driver}_find_device() APIs to avoid proliferation
of duplicate custom match functions.

Cc: "David S. Miller" <davem@davemloft.net>
Cc: Doug Ledford <dledford@redhat.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: linux-usb@vger.kernel.org
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Joe Perches <joe@perches.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Joerg Roedel <joro@8bytes.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/base/core.c                           |  6 +++
 drivers/base/devcon.c                         |  8 +---
 .../hwtracing/coresight/coresight-platform.c  | 11 +-----
 drivers/hwtracing/coresight/coresight-priv.h  |  2 -
 drivers/hwtracing/coresight/coresight.c       |  4 +-
 drivers/infiniband/hw/hns/hns_roce_hw_v1.c    |  8 +---
 drivers/iommu/arm-smmu-v3.c                   |  9 +----
 drivers/iommu/arm-smmu.c                      |  9 +----
 .../ethernet/hisilicon/hns/hns_dsaf_misc.c    |  8 +---
 drivers/usb/roles/class.c                     |  8 +---
 drivers/usb/typec/class.c                     |  8 +---
 include/linux/device.h                        | 39 +++++++++++++++++++
 12 files changed, 57 insertions(+), 63 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index fb83647d685a..e8f81a667545 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3368,3 +3368,9 @@ int device_match_of_node(struct device *dev, const void *np)
 	return dev->of_node == np;
 }
 EXPORT_SYMBOL_GPL(device_match_of_node);
+
+int device_match_fwnode(struct device *dev, const void *fwnode)
+{
+	return dev_fwnode(dev) == fwnode;
+}
+EXPORT_SYMBOL_GPL(device_match_fwnode);
diff --git a/drivers/base/devcon.c b/drivers/base/devcon.c
index 09f28479b243..1d488dc5dd0c 100644
--- a/drivers/base/devcon.c
+++ b/drivers/base/devcon.c
@@ -133,19 +133,13 @@ static struct bus_type *generic_match_buses[] = {
 	NULL,
 };
 
-static int device_fwnode_match(struct device *dev, const void *fwnode)
-{
-	return dev_fwnode(dev) == fwnode;
-}
-
 static void *device_connection_fwnode_match(struct device_connection *con)
 {
 	struct bus_type *bus;
 	struct device *dev;
 
 	for (bus = generic_match_buses[0]; bus; bus++) {
-		dev = bus_find_device(bus, NULL, (void *)con->fwnode,
-				      device_fwnode_match);
+		dev = bus_find_device_by_fwnode(bus, con->fwnode);
 		if (dev && !strncmp(dev_name(dev), con->id, strlen(con->id)))
 			return dev;
 
diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
index dad7d96c5943..3c5bee429105 100644
--- a/drivers/hwtracing/coresight/coresight-platform.c
+++ b/drivers/hwtracing/coresight/coresight-platform.c
@@ -37,11 +37,6 @@ static int coresight_alloc_conns(struct device *dev,
 	return 0;
 }
 
-int coresight_device_fwnode_match(struct device *dev, const void *fwnode)
-{
-	return dev_fwnode(dev) == fwnode;
-}
-
 static struct device *
 coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
 {
@@ -51,8 +46,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
 	 * If we have a non-configurable replicator, it will be found on the
 	 * platform bus.
 	 */
-	dev = bus_find_device(&platform_bus_type, NULL,
-			      fwnode, coresight_device_fwnode_match);
+	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
 	if (dev)
 		return dev;
 
@@ -60,8 +54,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
 	 * We have a configurable component - circle through the AMBA bus
 	 * looking for the device that matches the endpoint node.
 	 */
-	return bus_find_device(&amba_bustype, NULL,
-			       fwnode, coresight_device_fwnode_match);
+	return bus_find_device_by_fwnode(&amba_bustype, fwnode);
 }
 
 #ifdef CONFIG_OF
diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
index 7d401790dd7e..61d7f9ff054d 100644
--- a/drivers/hwtracing/coresight/coresight-priv.h
+++ b/drivers/hwtracing/coresight/coresight-priv.h
@@ -202,6 +202,4 @@ static inline void *coresight_get_uci_data(const struct amba_id *id)
 
 void coresight_release_platform_data(struct coresight_platform_data *pdata);
 
-int coresight_device_fwnode_match(struct device *dev, const void *fwnode);
-
 #endif
diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
index 55db77f6410b..6453c67a4d01 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -1046,9 +1046,7 @@ static void coresight_fixup_device_conns(struct coresight_device *csdev)
 		struct coresight_connection *conn = &csdev->pdata->conns[i];
 		struct device *dev = NULL;
 
-		dev = bus_find_device(&coresight_bustype, NULL,
-				      (void *)conn->child_fwnode,
-				      coresight_device_fwnode_match);
+		dev = bus_find_device_by_fwnode(&coresight_bustype, conn->child_fwnode);
 		if (dev) {
 			conn->child_dev = to_coresight_device(dev);
 			/* and put reference from 'bus_find_device()' */
diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
index 81e6dedb1e02..fa05e943038a 100644
--- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
+++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
@@ -4499,19 +4499,13 @@ static const struct acpi_device_id hns_roce_acpi_match[] = {
 };
 MODULE_DEVICE_TABLE(acpi, hns_roce_acpi_match);
 
-static int hns_roce_node_match(struct device *dev, const void *fwnode)
-{
-	return dev->fwnode == fwnode;
-}
-
 static struct
 platform_device *hns_roce_find_pdev(struct fwnode_handle *fwnode)
 {
 	struct device *dev;
 
 	/* get the 'device' corresponding to the matching 'fwnode' */
-	dev = bus_find_device(&platform_bus_type, NULL,
-			      fwnode, hns_roce_node_match);
+	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
 	/* get the platform device */
 	return dev ? to_platform_device(dev) : NULL;
 }
diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c
index a9a9fabd3968..6f0e13fa5e1a 100644
--- a/drivers/iommu/arm-smmu-v3.c
+++ b/drivers/iommu/arm-smmu-v3.c
@@ -2034,16 +2034,11 @@ arm_smmu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova)
 
 static struct platform_driver arm_smmu_driver;
 
-static int arm_smmu_match_node(struct device *dev, const void *data)
-{
-	return dev->fwnode == data;
-}
-
 static
 struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
 {
-	struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL,
-						fwnode, arm_smmu_match_node);
+	struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver,
+							  fwnode);
 	put_device(dev);
 	return dev ? dev_get_drvdata(dev) : NULL;
 }
diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index 64977c131ee6..aa06498f291d 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -1426,16 +1426,11 @@ static bool arm_smmu_capable(enum iommu_cap cap)
 	}
 }
 
-static int arm_smmu_match_node(struct device *dev, const void *data)
-{
-	return dev->fwnode == data;
-}
-
 static
 struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
 {
-	struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL,
-						fwnode, arm_smmu_match_node);
+	struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver,
+							  fwnode);
 	put_device(dev);
 	return dev ? dev_get_drvdata(dev) : NULL;
 }
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
index bb6586d0e5af..ed3829ae4ef1 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
@@ -754,17 +754,11 @@ struct dsaf_misc_op *hns_misc_op_get(struct dsaf_device *dsaf_dev)
 	return (void *)misc_op;
 }
 
-static int hns_dsaf_dev_match(struct device *dev, const void *fwnode)
-{
-	return dev->fwnode == fwnode;
-}
-
 struct
 platform_device *hns_dsaf_find_platform_device(struct fwnode_handle *fwnode)
 {
 	struct device *dev;
 
-	dev = bus_find_device(&platform_bus_type, NULL,
-			      fwnode, hns_dsaf_dev_match);
+	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
 	return dev ? to_platform_device(dev) : NULL;
 }
diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
index c8efe60e2465..0526efbc4922 100644
--- a/drivers/usb/roles/class.c
+++ b/drivers/usb/roles/class.c
@@ -85,11 +85,6 @@ enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw)
 }
 EXPORT_SYMBOL_GPL(usb_role_switch_get_role);
 
-static int switch_fwnode_match(struct device *dev, const void *fwnode)
-{
-	return dev_fwnode(dev) == fwnode;
-}
-
 static void *usb_role_switch_match(struct device_connection *con, int ep,
 				   void *data)
 {
@@ -99,8 +94,7 @@ static void *usb_role_switch_match(struct device_connection *con, int ep,
 		if (con->id && !fwnode_property_present(con->fwnode, con->id))
 			return NULL;
 
-		dev = class_find_device(role_class, NULL, con->fwnode,
-					switch_fwnode_match);
+		dev = class_find_device_by_fwnode(role_class, con->fwnode);
 	} else {
 		dev = class_find_device_by_name(role_class, con->endpoint[ep]);
 	}
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 9b0d15b487e5..94a3eda62add 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -205,11 +205,6 @@ static void typec_altmode_put_partner(struct altmode *altmode)
 	put_device(&adev->dev);
 }
 
-static int typec_port_fwnode_match(struct device *dev, const void *fwnode)
-{
-	return dev_fwnode(dev) == fwnode;
-}
-
 static void *typec_port_match(struct device_connection *con, int ep, void *data)
 {
 	struct device *dev;
@@ -219,8 +214,7 @@ static void *typec_port_match(struct device_connection *con, int ep, void *data)
 	 * we need to return ERR_PTR(-PROBE_DEFER) when there is no device.
 	 */
 	if (con->fwnode)
-		return class_find_device(typec_class, NULL, con->fwnode,
-					 typec_port_fwnode_match);
+		return class_find_device_by_fwnode(typec_class, con->fwnode);
 
 	dev = class_find_device_by_name(typec_class, con->endpoint[ep]);
 
diff --git a/include/linux/device.h b/include/linux/device.h
index 29d8d7ad41e6..7133fc1c285d 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -166,6 +166,7 @@ void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
 
 int device_match_name(struct device *dev, const void *name);
 int device_match_of_node(struct device *dev, const void *np);
+int device_match_fwnode(struct device *dev, const void *fwnode);
 
 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
 		     int (*fn)(struct device *dev, void *data));
@@ -198,6 +199,18 @@ bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
 	return bus_find_device(bus, NULL, np, device_match_of_node);
 }
 
+/**
+ * bus_find_device_by_fwnode : device iterator for locating a particular device
+ * matching the fwnode.
+ * @bus: bus type
+ * @fwnode: fwnode of the device to match.
+ */
+static inline struct device *
+bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwnode)
+{
+	return bus_find_device(bus, NULL, fwnode, device_match_fwnode);
+}
+
 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
 					struct device *hint);
 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
@@ -391,6 +404,19 @@ driver_find_device_by_of_node(struct device_driver *drv,
 	return driver_find_device(drv, NULL, np, device_match_of_node);
 }
 
+/**
+ * driver_find_device_by_fwnode- device iterator for locating a particular device
+ * by fwnode pointer.
+ * @driver: the driver we're iterating
+ * @fwnode: fwnode pointer to match.
+ */
+static inline struct device *
+driver_find_device_by_fwnode(struct device_driver *drv,
+			     const struct fwnode_handle *fwnode)
+{
+	return driver_find_device(drv, NULL, fwnode, device_match_fwnode);
+}
+
 void driver_deferred_probe_add(struct device *dev);
 int driver_deferred_probe_check_state(struct device *dev);
 int driver_deferred_probe_check_state_continue(struct device *dev);
@@ -544,6 +570,19 @@ class_find_device_by_of_node(struct class *class, const struct device_node *np)
 	return class_find_device(class, NULL, np, device_match_of_node);
 }
 
+/**
+ * class_find_device_by_fwnode : device iterator for locating a particular device
+ * matching the fwnode.
+ * @class: class type
+ * @fwnode: fwnode of the device to match.
+ */
+static inline struct device *
+class_find_device_by_fwnode(struct class *class,
+			    const struct fwnode_handle *fwnode)
+{
+	return class_find_device(class, NULL, fwnode, device_match_fwnode);
+}
+
 struct class_attribute {
 	struct attribute attr;
 	ssize_t (*show)(struct class *class, struct class_attribute *attr,
-- 
2.21.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH v3 4/7] drivers: Introduce device lookup variants by device type
  2019-07-23 22:18 ` Suzuki K Poulose
@ 2019-07-23 22:18   ` Suzuki K Poulose
  -1 siblings, 0 replies; 71+ messages in thread
From: Suzuki K Poulose @ 2019-07-23 22:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: gregkh, rafael, linux-arm-kernel, Suzuki K Poulose,
	Alexander Shishkin, Arnd Bergmann, Harald Freudenberger,
	Heiko Carstens, linux-usb, Oliver Neukum,
	Sebastian Andrzej Siewior, Tomas Winkler, Ulf Hansson,
	Joe Perches

Add a helper to match a device by its type and provide wrappers
for {bus/class/driver}_find_device() APIs.

Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Harald Freudenberger <freude@linux.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: linux-usb@vger.kernel.org
Cc: Oliver Neukum <oneukum@suse.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Tomas Winkler <tomas.winkler@intel.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/base/core.c               | 15 ++++++-------
 drivers/hwtracing/intel_th/core.c | 10 +--------
 drivers/misc/mei/main.c           |  9 +-------
 drivers/s390/crypto/zcrypt_api.c  | 11 +--------
 drivers/tty/tty_io.c              |  8 +------
 drivers/usb/core/devio.c          |  8 +------
 include/linux/device.h            | 37 +++++++++++++++++++++++++++++++
 7 files changed, 49 insertions(+), 49 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index e8f81a667545..3abc32b60c0a 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -2867,13 +2867,6 @@ struct device *device_create_with_groups(struct class *class,
 }
 EXPORT_SYMBOL_GPL(device_create_with_groups);
 
-static int __match_devt(struct device *dev, const void *data)
-{
-	const dev_t *devt = data;
-
-	return dev->devt == *devt;
-}
-
 /**
  * device_destroy - removes a device that was created with device_create()
  * @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)
 {
 	struct device *dev;
 
-	dev = class_find_device(class, NULL, &devt, __match_devt);
+	dev = class_find_device_by_devt(class, devt);
 	if (dev) {
 		put_device(dev);
 		device_unregister(dev);
@@ -3374,3 +3367,9 @@ int device_match_fwnode(struct device *dev, const void *fwnode)
 	return dev_fwnode(dev) == fwnode;
 }
 EXPORT_SYMBOL_GPL(device_match_fwnode);
+
+int device_match_devt(struct device *dev, const void *pdevt)
+{
+	return dev->devt == *(dev_t *)pdevt;
+}
+EXPORT_SYMBOL_GPL(device_match_devt);
diff --git a/drivers/hwtracing/intel_th/core.c b/drivers/hwtracing/intel_th/core.c
index 55922896d862..d5c1821b31c6 100644
--- a/drivers/hwtracing/intel_th/core.c
+++ b/drivers/hwtracing/intel_th/core.c
@@ -789,12 +789,6 @@ static int intel_th_populate(struct intel_th *th)
 	return 0;
 }
 
-static int match_devt(struct device *dev, const void *data)
-{
-	dev_t devt = (dev_t)(unsigned long)(void *)data;
-	return dev->devt == devt;
-}
-
 static int intel_th_output_open(struct inode *inode, struct file *file)
 {
 	const struct file_operations *fops;
@@ -802,9 +796,7 @@ static int intel_th_output_open(struct inode *inode, struct file *file)
 	struct device *dev;
 	int err;
 
-	dev = bus_find_device(&intel_th_bus, NULL,
-			      (void *)(unsigned long)inode->i_rdev,
-			      match_devt);
+	dev = bus_find_device_by_devt(&intel_th_bus, inode->i_rdev);
 	if (!dev || !dev->driver)
 		return -ENODEV;
 
diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c
index f894d1f8a53e..7310b476323c 100644
--- a/drivers/misc/mei/main.c
+++ b/drivers/misc/mei/main.c
@@ -858,13 +858,6 @@ static ssize_t dev_state_show(struct device *device,
 }
 static DEVICE_ATTR_RO(dev_state);
 
-static int match_devt(struct device *dev, const void *data)
-{
-	const dev_t *devt = data;
-
-	return dev->devt == *devt;
-}
-
 /**
  * dev_set_devstate: set to new device state and notify sysfs file.
  *
@@ -880,7 +873,7 @@ void mei_set_devstate(struct mei_device *dev, enum mei_dev_state state)
 
 	dev->dev_state = state;
 
-	clsdev = class_find_device(mei_class, NULL, &dev->cdev.dev, match_devt);
+	clsdev = class_find_device_by_devt(mei_class, dev->cdev.dev);
 	if (clsdev) {
 		sysfs_notify(&clsdev->kobj, NULL, "dev_state");
 		put_device(clsdev);
diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c
index 38a5a47b8c9c..150f6236c9bb 100644
--- a/drivers/s390/crypto/zcrypt_api.c
+++ b/drivers/s390/crypto/zcrypt_api.c
@@ -133,12 +133,6 @@ struct zcdn_device {
 static int zcdn_create(const char *name);
 static int zcdn_destroy(const char *name);
 
-/* helper function, matches the devt value for find_zcdndev_by_devt() */
-static int __match_zcdn_devt(struct device *dev, const void *data)
-{
-	return dev->devt == *((dev_t *) data);
-}
-
 /*
  * Find zcdn device by name.
  * Returns reference to the zcdn device which needs to be released
@@ -158,10 +152,7 @@ static inline struct zcdn_device *find_zcdndev_by_name(const char *name)
  */
 static inline struct zcdn_device *find_zcdndev_by_devt(dev_t devt)
 {
-	struct device *dev =
-		class_find_device(zcrypt_class, NULL,
-				  (void *) &devt,
-				  __match_zcdn_devt);
+	struct device *dev = class_find_device_by_devt(zcrypt_class, devt);
 
 	return dev ? to_zcdn_dev(dev) : NULL;
 }
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 566728fbaf3c..802c1210558f 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -2952,17 +2952,11 @@ void do_SAK(struct tty_struct *tty)
 
 EXPORT_SYMBOL(do_SAK);
 
-static int dev_match_devt(struct device *dev, const void *data)
-{
-	const dev_t *devt = data;
-	return dev->devt == *devt;
-}
-
 /* Must put_device() after it's unused! */
 static struct device *tty_get_device(struct tty_struct *tty)
 {
 	dev_t devt = tty_devnum(tty);
-	return class_find_device(tty_class, NULL, &devt, dev_match_devt);
+	return class_find_device_by_devt(tty_class, devt);
 }
 
 
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index b265ab5405f9..60268aee93a8 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -942,17 +942,11 @@ static int parse_usbdevfs_streams(struct usb_dev_state *ps,
 	return ret;
 }
 
-static int match_devt(struct device *dev, const void *data)
-{
-	return dev->devt == (dev_t)(unsigned long)(void *)data;
-}
-
 static struct usb_device *usbdev_lookup_by_devt(dev_t devt)
 {
 	struct device *dev;
 
-	dev = bus_find_device(&usb_bus_type, NULL,
-			      (void *) (unsigned long) devt, match_devt);
+	dev = bus_find_device_by_devt(&usb_bus_type, devt);
 	if (!dev)
 		return NULL;
 	return to_usb_device(dev);
diff --git a/include/linux/device.h b/include/linux/device.h
index 7133fc1c285d..93b2f55ef44e 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -167,6 +167,7 @@ void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
 int device_match_name(struct device *dev, const void *name);
 int device_match_of_node(struct device *dev, const void *np);
 int device_match_fwnode(struct device *dev, const void *fwnode);
+int device_match_devt(struct device *dev, const void *pdevt);
 
 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
 		     int (*fn)(struct device *dev, void *data));
@@ -211,6 +212,18 @@ bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwno
 	return bus_find_device(bus, NULL, fwnode, device_match_fwnode);
 }
 
+/**
+ * bus_find_device_by_devt : device iterator for locating a particular device
+ * matching the device type.
+ * @bus: bus type
+ * @devt: device type of the device to match.
+ */
+static inline struct device *bus_find_device_by_devt(struct bus_type *bus,
+						     dev_t devt)
+{
+	return bus_find_device(bus, NULL, &devt, device_match_devt);
+}
+
 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
 					struct device *hint);
 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
@@ -417,6 +430,18 @@ driver_find_device_by_fwnode(struct device_driver *drv,
 	return driver_find_device(drv, NULL, fwnode, device_match_fwnode);
 }
 
+/**
+ * driver_find_device_by_devt- device iterator for locating a particular device
+ * by devt.
+ * @driver: the driver we're iterating
+ * @devt: devt pointer to match.
+ */
+static inline struct device *driver_find_device_by_devt(struct device_driver *drv,
+							dev_t devt)
+{
+	return driver_find_device(drv, NULL, &devt, device_match_devt);
+}
+
 void driver_deferred_probe_add(struct device *dev);
 int driver_deferred_probe_check_state(struct device *dev);
 int driver_deferred_probe_check_state_continue(struct device *dev);
@@ -583,6 +608,18 @@ class_find_device_by_fwnode(struct class *class,
 	return class_find_device(class, NULL, fwnode, device_match_fwnode);
 }
 
+/**
+ * class_find_device_by_devt : device iterator for locating a particular device
+ * matching the device type.
+ * @class: class type
+ * @devt: device type of the device to match.
+ */
+static inline struct device *class_find_device_by_devt(struct class *class,
+						       dev_t devt)
+{
+	return class_find_device(class, NULL, &devt, device_match_devt);
+}
+
 struct class_attribute {
 	struct attribute attr;
 	ssize_t (*show)(struct class *class, struct class_attribute *attr,
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH v3 4/7] drivers: Introduce device lookup variants by device type
@ 2019-07-23 22:18   ` Suzuki K Poulose
  0 siblings, 0 replies; 71+ messages in thread
From: Suzuki K Poulose @ 2019-07-23 22:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ulf Hansson, linux-usb, Arnd Bergmann, Suzuki K Poulose,
	Alexander Shishkin, gregkh, Sebastian Andrzej Siewior, rafael,
	Heiko Carstens, Harald Freudenberger, Oliver Neukum, Joe Perches,
	Tomas Winkler, linux-arm-kernel

Add a helper to match a device by its type and provide wrappers
for {bus/class/driver}_find_device() APIs.

Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Harald Freudenberger <freude@linux.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: linux-usb@vger.kernel.org
Cc: Oliver Neukum <oneukum@suse.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Tomas Winkler <tomas.winkler@intel.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/base/core.c               | 15 ++++++-------
 drivers/hwtracing/intel_th/core.c | 10 +--------
 drivers/misc/mei/main.c           |  9 +-------
 drivers/s390/crypto/zcrypt_api.c  | 11 +--------
 drivers/tty/tty_io.c              |  8 +------
 drivers/usb/core/devio.c          |  8 +------
 include/linux/device.h            | 37 +++++++++++++++++++++++++++++++
 7 files changed, 49 insertions(+), 49 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index e8f81a667545..3abc32b60c0a 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -2867,13 +2867,6 @@ struct device *device_create_with_groups(struct class *class,
 }
 EXPORT_SYMBOL_GPL(device_create_with_groups);
 
-static int __match_devt(struct device *dev, const void *data)
-{
-	const dev_t *devt = data;
-
-	return dev->devt == *devt;
-}
-
 /**
  * device_destroy - removes a device that was created with device_create()
  * @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)
 {
 	struct device *dev;
 
-	dev = class_find_device(class, NULL, &devt, __match_devt);
+	dev = class_find_device_by_devt(class, devt);
 	if (dev) {
 		put_device(dev);
 		device_unregister(dev);
@@ -3374,3 +3367,9 @@ int device_match_fwnode(struct device *dev, const void *fwnode)
 	return dev_fwnode(dev) == fwnode;
 }
 EXPORT_SYMBOL_GPL(device_match_fwnode);
+
+int device_match_devt(struct device *dev, const void *pdevt)
+{
+	return dev->devt == *(dev_t *)pdevt;
+}
+EXPORT_SYMBOL_GPL(device_match_devt);
diff --git a/drivers/hwtracing/intel_th/core.c b/drivers/hwtracing/intel_th/core.c
index 55922896d862..d5c1821b31c6 100644
--- a/drivers/hwtracing/intel_th/core.c
+++ b/drivers/hwtracing/intel_th/core.c
@@ -789,12 +789,6 @@ static int intel_th_populate(struct intel_th *th)
 	return 0;
 }
 
-static int match_devt(struct device *dev, const void *data)
-{
-	dev_t devt = (dev_t)(unsigned long)(void *)data;
-	return dev->devt == devt;
-}
-
 static int intel_th_output_open(struct inode *inode, struct file *file)
 {
 	const struct file_operations *fops;
@@ -802,9 +796,7 @@ static int intel_th_output_open(struct inode *inode, struct file *file)
 	struct device *dev;
 	int err;
 
-	dev = bus_find_device(&intel_th_bus, NULL,
-			      (void *)(unsigned long)inode->i_rdev,
-			      match_devt);
+	dev = bus_find_device_by_devt(&intel_th_bus, inode->i_rdev);
 	if (!dev || !dev->driver)
 		return -ENODEV;
 
diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c
index f894d1f8a53e..7310b476323c 100644
--- a/drivers/misc/mei/main.c
+++ b/drivers/misc/mei/main.c
@@ -858,13 +858,6 @@ static ssize_t dev_state_show(struct device *device,
 }
 static DEVICE_ATTR_RO(dev_state);
 
-static int match_devt(struct device *dev, const void *data)
-{
-	const dev_t *devt = data;
-
-	return dev->devt == *devt;
-}
-
 /**
  * dev_set_devstate: set to new device state and notify sysfs file.
  *
@@ -880,7 +873,7 @@ void mei_set_devstate(struct mei_device *dev, enum mei_dev_state state)
 
 	dev->dev_state = state;
 
-	clsdev = class_find_device(mei_class, NULL, &dev->cdev.dev, match_devt);
+	clsdev = class_find_device_by_devt(mei_class, dev->cdev.dev);
 	if (clsdev) {
 		sysfs_notify(&clsdev->kobj, NULL, "dev_state");
 		put_device(clsdev);
diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c
index 38a5a47b8c9c..150f6236c9bb 100644
--- a/drivers/s390/crypto/zcrypt_api.c
+++ b/drivers/s390/crypto/zcrypt_api.c
@@ -133,12 +133,6 @@ struct zcdn_device {
 static int zcdn_create(const char *name);
 static int zcdn_destroy(const char *name);
 
-/* helper function, matches the devt value for find_zcdndev_by_devt() */
-static int __match_zcdn_devt(struct device *dev, const void *data)
-{
-	return dev->devt == *((dev_t *) data);
-}
-
 /*
  * Find zcdn device by name.
  * Returns reference to the zcdn device which needs to be released
@@ -158,10 +152,7 @@ static inline struct zcdn_device *find_zcdndev_by_name(const char *name)
  */
 static inline struct zcdn_device *find_zcdndev_by_devt(dev_t devt)
 {
-	struct device *dev =
-		class_find_device(zcrypt_class, NULL,
-				  (void *) &devt,
-				  __match_zcdn_devt);
+	struct device *dev = class_find_device_by_devt(zcrypt_class, devt);
 
 	return dev ? to_zcdn_dev(dev) : NULL;
 }
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 566728fbaf3c..802c1210558f 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -2952,17 +2952,11 @@ void do_SAK(struct tty_struct *tty)
 
 EXPORT_SYMBOL(do_SAK);
 
-static int dev_match_devt(struct device *dev, const void *data)
-{
-	const dev_t *devt = data;
-	return dev->devt == *devt;
-}
-
 /* Must put_device() after it's unused! */
 static struct device *tty_get_device(struct tty_struct *tty)
 {
 	dev_t devt = tty_devnum(tty);
-	return class_find_device(tty_class, NULL, &devt, dev_match_devt);
+	return class_find_device_by_devt(tty_class, devt);
 }
 
 
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index b265ab5405f9..60268aee93a8 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -942,17 +942,11 @@ static int parse_usbdevfs_streams(struct usb_dev_state *ps,
 	return ret;
 }
 
-static int match_devt(struct device *dev, const void *data)
-{
-	return dev->devt == (dev_t)(unsigned long)(void *)data;
-}
-
 static struct usb_device *usbdev_lookup_by_devt(dev_t devt)
 {
 	struct device *dev;
 
-	dev = bus_find_device(&usb_bus_type, NULL,
-			      (void *) (unsigned long) devt, match_devt);
+	dev = bus_find_device_by_devt(&usb_bus_type, devt);
 	if (!dev)
 		return NULL;
 	return to_usb_device(dev);
diff --git a/include/linux/device.h b/include/linux/device.h
index 7133fc1c285d..93b2f55ef44e 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -167,6 +167,7 @@ void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
 int device_match_name(struct device *dev, const void *name);
 int device_match_of_node(struct device *dev, const void *np);
 int device_match_fwnode(struct device *dev, const void *fwnode);
+int device_match_devt(struct device *dev, const void *pdevt);
 
 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
 		     int (*fn)(struct device *dev, void *data));
@@ -211,6 +212,18 @@ bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwno
 	return bus_find_device(bus, NULL, fwnode, device_match_fwnode);
 }
 
+/**
+ * bus_find_device_by_devt : device iterator for locating a particular device
+ * matching the device type.
+ * @bus: bus type
+ * @devt: device type of the device to match.
+ */
+static inline struct device *bus_find_device_by_devt(struct bus_type *bus,
+						     dev_t devt)
+{
+	return bus_find_device(bus, NULL, &devt, device_match_devt);
+}
+
 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
 					struct device *hint);
 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
@@ -417,6 +430,18 @@ driver_find_device_by_fwnode(struct device_driver *drv,
 	return driver_find_device(drv, NULL, fwnode, device_match_fwnode);
 }
 
+/**
+ * driver_find_device_by_devt- device iterator for locating a particular device
+ * by devt.
+ * @driver: the driver we're iterating
+ * @devt: devt pointer to match.
+ */
+static inline struct device *driver_find_device_by_devt(struct device_driver *drv,
+							dev_t devt)
+{
+	return driver_find_device(drv, NULL, &devt, device_match_devt);
+}
+
 void driver_deferred_probe_add(struct device *dev);
 int driver_deferred_probe_check_state(struct device *dev);
 int driver_deferred_probe_check_state_continue(struct device *dev);
@@ -583,6 +608,18 @@ class_find_device_by_fwnode(struct class *class,
 	return class_find_device(class, NULL, fwnode, device_match_fwnode);
 }
 
+/**
+ * class_find_device_by_devt : device iterator for locating a particular device
+ * matching the device type.
+ * @class: class type
+ * @devt: device type of the device to match.
+ */
+static inline struct device *class_find_device_by_devt(struct class *class,
+						       dev_t devt)
+{
+	return class_find_device(class, NULL, &devt, device_match_devt);
+}
+
 struct class_attribute {
 	struct attribute attr;
 	ssize_t (*show)(struct class *class, struct class_attribute *attr,
-- 
2.21.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH v3 5/7] drivers: Introduce device lookup variants by ACPI_COMPANION device
  2019-07-23 22:18 ` Suzuki K Poulose
@ 2019-07-23 22:18   ` Suzuki K Poulose
  -1 siblings, 0 replies; 71+ messages in thread
From: Suzuki K Poulose @ 2019-07-23 22:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: gregkh, rafael, linux-arm-kernel, Suzuki K Poulose, Len Brown,
	linux-acpi, linux-spi, Mark Brown, Mika Westerberg, Wolfram Sang,
	linux-i2c

Add a generic helper to match a device by the ACPI_COMPANION device
and provide wrappers for the device lookup APIs.

Cc: Len Brown <lenb@kernel.org>
Cc: linux-acpi@vger.kernel.org
Cc: linux-spi@vger.kernel.org
Cc: Mark Brown <broonie@kernel.org>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Wolfram Sang <wsa@the-dreams.de>
Cc: linux-i2c@vger.kernel.org
Cc: Mark Brown <broonie@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/base/core.c         |  6 ++++
 drivers/i2c/i2c-core-acpi.c | 11 ++-----
 drivers/spi/spi.c           |  8 +----
 include/linux/device.h      | 65 +++++++++++++++++++++++++++++++++++++
 4 files changed, 74 insertions(+), 16 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 3abc32b60c0a..57d71bc2c559 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3373,3 +3373,9 @@ int device_match_devt(struct device *dev, const void *pdevt)
 	return dev->devt == *(dev_t *)pdevt;
 }
 EXPORT_SYMBOL_GPL(device_match_devt);
+
+int device_match_acpi_dev(struct device *dev, const void *adev)
+{
+	return ACPI_COMPANION(dev) == adev;
+}
+EXPORT_SYMBOL(device_match_acpi_dev);
diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
index 4dbbc9a35f65..bc80aafb521f 100644
--- a/drivers/i2c/i2c-core-acpi.c
+++ b/drivers/i2c/i2c-core-acpi.c
@@ -354,17 +354,11 @@ static int i2c_acpi_find_match_adapter(struct device *dev, const void *data)
 	return ACPI_HANDLE(dev) == (acpi_handle)data;
 }
 
-static int i2c_acpi_find_match_device(struct device *dev, const void *data)
-{
-	return ACPI_COMPANION(dev) == data;
-}
 
 struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle)
 {
-	struct device *dev;
+	struct device *dev = bus_find_device_by_acpi_dev(&i2c_bus_type, handle);
 
-	dev = bus_find_device(&i2c_bus_type, NULL, handle,
-			      i2c_acpi_find_match_adapter);
 	return dev ? i2c_verify_adapter(dev) : NULL;
 }
 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)
 {
 	struct device *dev;
 
-	dev = bus_find_device(&i2c_bus_type, NULL, adev,
-			      i2c_acpi_find_match_device);
+	dev = bus_find_device_by_acpi_dev(&i2c_bus_type, adev);
 	return dev ? i2c_verify_client(dev) : NULL;
 }
 
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index a591da87981a..c486a6f84c2c 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -3741,11 +3741,6 @@ static int spi_acpi_controller_match(struct device *dev, const void *data)
 	return ACPI_COMPANION(dev->parent) == data;
 }
 
-static int spi_acpi_device_match(struct device *dev, const void *data)
-{
-	return ACPI_COMPANION(dev) == data;
-}
-
 static struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev)
 {
 	struct device *dev;
@@ -3765,8 +3760,7 @@ static struct spi_device *acpi_spi_find_device_by_adev(struct acpi_device *adev)
 {
 	struct device *dev;
 
-	dev = bus_find_device(&spi_bus_type, NULL, adev, spi_acpi_device_match);
-
+	dev = bus_find_device_by_acpi_dev(&spi_bus_type, adev);
 	return dev ? to_spi_device(dev) : NULL;
 }
 
diff --git a/include/linux/device.h b/include/linux/device.h
index 93b2f55ef44e..7514ef3d3f1a 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -168,6 +168,7 @@ int device_match_name(struct device *dev, const void *name);
 int device_match_of_node(struct device *dev, const void *np);
 int device_match_fwnode(struct device *dev, const void *fwnode);
 int device_match_devt(struct device *dev, const void *pdevt);
+int device_match_acpi_dev(struct device *dev, const void *adev);
 
 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
 		     int (*fn)(struct device *dev, void *data));
@@ -224,6 +225,28 @@ static inline struct device *bus_find_device_by_devt(struct bus_type *bus,
 	return bus_find_device(bus, NULL, &devt, device_match_devt);
 }
 
+#ifdef CONFIG_ACPI
+struct acpi_device;
+
+/**
+ * bus_find_device_by_acpi_dev : device iterator for locating a particular device
+ * matching the ACPI COMPANION device.
+ * @bus: bus type
+ * @adev: ACPI COMPANION device to match.
+ */
+static inline struct device *
+bus_find_device_by_acpi_dev(struct bus_type *bus, const struct acpi_device *adev)
+{
+	return bus_find_device(bus, NULL, adev, device_match_acpi_dev);
+}
+#else
+static inline struct device *
+bus_find_device_by_acpi_dev(struct bus_type *bus, const void *adev)
+{
+	return NULL;
+}
+#endif
+
 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
 					struct device *hint);
 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
@@ -442,6 +465,27 @@ static inline struct device *driver_find_device_by_devt(struct device_driver *dr
 	return driver_find_device(drv, NULL, &devt, device_match_devt);
 }
 
+#ifdef CONFIG_ACPI
+/**
+ * driver_find_device_by_acpi_dev : device iterator for locating a particular
+ * device matching the ACPI_COMPANION device.
+ * @driver: the driver we're iterating
+ * @adev: ACPI_COMPANION device to match.
+ */
+static inline struct device *
+driver_find_device_by_acpi_dev(struct device_driver *drv,
+			       const struct acpi_device *adev)
+{
+	return driver_find_device(drv, NULL, adev, device_match_acpi_dev);
+}
+#else
+static inline struct device *
+driver_find_device_by_acpi_dev(struct device_driver *drv, const void *adev)
+{
+	return NULL;
+}
+#endif
+
 void driver_deferred_probe_add(struct device *dev);
 int driver_deferred_probe_check_state(struct device *dev);
 int driver_deferred_probe_check_state_continue(struct device *dev);
@@ -620,6 +664,27 @@ static inline struct device *class_find_device_by_devt(struct class *class,
 	return class_find_device(class, NULL, &devt, device_match_devt);
 }
 
+#ifdef CONFIG_ACPI
+struct acpi_device;
+/**
+ * class_find_device_by_acpi_dev : device iterator for locating a particular
+ * device matching the ACPI_COMPANION device.
+ * @class: class type
+ * @adev: ACPI_COMPANION device to match.
+ */
+static inline struct device *
+class_find_device_by_acpi_dev(struct class *class, const struct acpi_device *adev)
+{
+	return class_find_device(class, NULL, adev, device_match_acpi_dev);
+}
+#else
+static inline struct device *
+class_find_device_by_acpi_dev(struct class *class, const void *adev)
+{
+	return NULL;
+}
+#endif
+
 struct class_attribute {
 	struct attribute attr;
 	ssize_t (*show)(struct class *class, struct class_attribute *attr,
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH v3 5/7] drivers: Introduce device lookup variants by ACPI_COMPANION device
@ 2019-07-23 22:18   ` Suzuki K Poulose
  0 siblings, 0 replies; 71+ messages in thread
From: Suzuki K Poulose @ 2019-07-23 22:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: Suzuki K Poulose, Wolfram Sang, gregkh, rafael, linux-spi,
	linux-acpi, Mark Brown, linux-i2c, Mika Westerberg,
	linux-arm-kernel, Len Brown

Add a generic helper to match a device by the ACPI_COMPANION device
and provide wrappers for the device lookup APIs.

Cc: Len Brown <lenb@kernel.org>
Cc: linux-acpi@vger.kernel.org
Cc: linux-spi@vger.kernel.org
Cc: Mark Brown <broonie@kernel.org>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Wolfram Sang <wsa@the-dreams.de>
Cc: linux-i2c@vger.kernel.org
Cc: Mark Brown <broonie@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/base/core.c         |  6 ++++
 drivers/i2c/i2c-core-acpi.c | 11 ++-----
 drivers/spi/spi.c           |  8 +----
 include/linux/device.h      | 65 +++++++++++++++++++++++++++++++++++++
 4 files changed, 74 insertions(+), 16 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 3abc32b60c0a..57d71bc2c559 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3373,3 +3373,9 @@ int device_match_devt(struct device *dev, const void *pdevt)
 	return dev->devt == *(dev_t *)pdevt;
 }
 EXPORT_SYMBOL_GPL(device_match_devt);
+
+int device_match_acpi_dev(struct device *dev, const void *adev)
+{
+	return ACPI_COMPANION(dev) == adev;
+}
+EXPORT_SYMBOL(device_match_acpi_dev);
diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
index 4dbbc9a35f65..bc80aafb521f 100644
--- a/drivers/i2c/i2c-core-acpi.c
+++ b/drivers/i2c/i2c-core-acpi.c
@@ -354,17 +354,11 @@ static int i2c_acpi_find_match_adapter(struct device *dev, const void *data)
 	return ACPI_HANDLE(dev) == (acpi_handle)data;
 }
 
-static int i2c_acpi_find_match_device(struct device *dev, const void *data)
-{
-	return ACPI_COMPANION(dev) == data;
-}
 
 struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle)
 {
-	struct device *dev;
+	struct device *dev = bus_find_device_by_acpi_dev(&i2c_bus_type, handle);
 
-	dev = bus_find_device(&i2c_bus_type, NULL, handle,
-			      i2c_acpi_find_match_adapter);
 	return dev ? i2c_verify_adapter(dev) : NULL;
 }
 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)
 {
 	struct device *dev;
 
-	dev = bus_find_device(&i2c_bus_type, NULL, adev,
-			      i2c_acpi_find_match_device);
+	dev = bus_find_device_by_acpi_dev(&i2c_bus_type, adev);
 	return dev ? i2c_verify_client(dev) : NULL;
 }
 
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index a591da87981a..c486a6f84c2c 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -3741,11 +3741,6 @@ static int spi_acpi_controller_match(struct device *dev, const void *data)
 	return ACPI_COMPANION(dev->parent) == data;
 }
 
-static int spi_acpi_device_match(struct device *dev, const void *data)
-{
-	return ACPI_COMPANION(dev) == data;
-}
-
 static struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev)
 {
 	struct device *dev;
@@ -3765,8 +3760,7 @@ static struct spi_device *acpi_spi_find_device_by_adev(struct acpi_device *adev)
 {
 	struct device *dev;
 
-	dev = bus_find_device(&spi_bus_type, NULL, adev, spi_acpi_device_match);
-
+	dev = bus_find_device_by_acpi_dev(&spi_bus_type, adev);
 	return dev ? to_spi_device(dev) : NULL;
 }
 
diff --git a/include/linux/device.h b/include/linux/device.h
index 93b2f55ef44e..7514ef3d3f1a 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -168,6 +168,7 @@ int device_match_name(struct device *dev, const void *name);
 int device_match_of_node(struct device *dev, const void *np);
 int device_match_fwnode(struct device *dev, const void *fwnode);
 int device_match_devt(struct device *dev, const void *pdevt);
+int device_match_acpi_dev(struct device *dev, const void *adev);
 
 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
 		     int (*fn)(struct device *dev, void *data));
@@ -224,6 +225,28 @@ static inline struct device *bus_find_device_by_devt(struct bus_type *bus,
 	return bus_find_device(bus, NULL, &devt, device_match_devt);
 }
 
+#ifdef CONFIG_ACPI
+struct acpi_device;
+
+/**
+ * bus_find_device_by_acpi_dev : device iterator for locating a particular device
+ * matching the ACPI COMPANION device.
+ * @bus: bus type
+ * @adev: ACPI COMPANION device to match.
+ */
+static inline struct device *
+bus_find_device_by_acpi_dev(struct bus_type *bus, const struct acpi_device *adev)
+{
+	return bus_find_device(bus, NULL, adev, device_match_acpi_dev);
+}
+#else
+static inline struct device *
+bus_find_device_by_acpi_dev(struct bus_type *bus, const void *adev)
+{
+	return NULL;
+}
+#endif
+
 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
 					struct device *hint);
 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
@@ -442,6 +465,27 @@ static inline struct device *driver_find_device_by_devt(struct device_driver *dr
 	return driver_find_device(drv, NULL, &devt, device_match_devt);
 }
 
+#ifdef CONFIG_ACPI
+/**
+ * driver_find_device_by_acpi_dev : device iterator for locating a particular
+ * device matching the ACPI_COMPANION device.
+ * @driver: the driver we're iterating
+ * @adev: ACPI_COMPANION device to match.
+ */
+static inline struct device *
+driver_find_device_by_acpi_dev(struct device_driver *drv,
+			       const struct acpi_device *adev)
+{
+	return driver_find_device(drv, NULL, adev, device_match_acpi_dev);
+}
+#else
+static inline struct device *
+driver_find_device_by_acpi_dev(struct device_driver *drv, const void *adev)
+{
+	return NULL;
+}
+#endif
+
 void driver_deferred_probe_add(struct device *dev);
 int driver_deferred_probe_check_state(struct device *dev);
 int driver_deferred_probe_check_state_continue(struct device *dev);
@@ -620,6 +664,27 @@ static inline struct device *class_find_device_by_devt(struct class *class,
 	return class_find_device(class, NULL, &devt, device_match_devt);
 }
 
+#ifdef CONFIG_ACPI
+struct acpi_device;
+/**
+ * class_find_device_by_acpi_dev : device iterator for locating a particular
+ * device matching the ACPI_COMPANION device.
+ * @class: class type
+ * @adev: ACPI_COMPANION device to match.
+ */
+static inline struct device *
+class_find_device_by_acpi_dev(struct class *class, const struct acpi_device *adev)
+{
+	return class_find_device(class, NULL, adev, device_match_acpi_dev);
+}
+#else
+static inline struct device *
+class_find_device_by_acpi_dev(struct class *class, const void *adev)
+{
+	return NULL;
+}
+#endif
+
 struct class_attribute {
 	struct attribute attr;
 	ssize_t (*show)(struct class *class, struct class_attribute *attr,
-- 
2.21.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH v3 6/7] drivers: Add generic helper to match any device
  2019-07-23 22:18 ` Suzuki K Poulose
@ 2019-07-23 22:18   ` Suzuki K Poulose
  -1 siblings, 0 replies; 71+ messages in thread
From: Suzuki K Poulose @ 2019-07-23 22:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: gregkh, rafael, linux-arm-kernel, Suzuki K Poulose,
	Bjorn Helgaas, Elie Morisse, James E.J. Bottomley,
	Martin K. Petersen, Nehal Shah, Rafael J. Wysocki,
	Shyam Sundar S K

Add a generic helper to match any/all devices. Using this
introduce new wrappers {bus/driver/class}_find_next_device().

Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Elie Morisse <syniurge@gmail.com>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Nehal Shah <nehal-bakulchandra.shah@amd.com>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Cc: Shyam Sundar S K <shyam-sundar.s-k@amd.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/base/core.c                  |  6 ++++++
 drivers/i2c/busses/i2c-amd-mp2-pci.c |  8 +-------
 drivers/pci/probe.c                  |  7 +------
 drivers/s390/cio/ccwgroup.c          |  8 +-------
 drivers/scsi/scsi_proc.c             |  9 ++-------
 include/linux/device.h               | 17 +++++++++++++++++
 6 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 57d71bc2c559..e22e29b3dc97 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3379,3 +3379,9 @@ int device_match_acpi_dev(struct device *dev, const void *adev)
 	return ACPI_COMPANION(dev) == adev;
 }
 EXPORT_SYMBOL(device_match_acpi_dev);
+
+int device_match_any(struct device *dev, const void *unused)
+{
+	return 1;
+}
+EXPORT_SYMBOL_GPL(device_match_any);
diff --git a/drivers/i2c/busses/i2c-amd-mp2-pci.c b/drivers/i2c/busses/i2c-amd-mp2-pci.c
index c7fe3b44a860..5e4800d72e00 100644
--- a/drivers/i2c/busses/i2c-amd-mp2-pci.c
+++ b/drivers/i2c/busses/i2c-amd-mp2-pci.c
@@ -457,18 +457,12 @@ static struct pci_driver amd_mp2_pci_driver = {
 };
 module_pci_driver(amd_mp2_pci_driver);
 
-static int amd_mp2_device_match(struct device *dev, const void *data)
-{
-	return 1;
-}
-
 struct amd_mp2_dev *amd_mp2_find_device(void)
 {
 	struct device *dev;
 	struct pci_dev *pci_dev;
 
-	dev = driver_find_device(&amd_mp2_pci_driver.driver, NULL, NULL,
-				 amd_mp2_device_match);
+	dev = driver_find_next_device(&amd_mp2_pci_driver.driver, NULL);
 	if (!dev)
 		return NULL;
 
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index a3c7338fad86..dbeeb385fb9f 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -64,11 +64,6 @@ static struct resource *get_pci_domain_busn_res(int domain_nr)
 	return &r->res;
 }
 
-static int find_anything(struct device *dev, const void *data)
-{
-	return 1;
-}
-
 /*
  * Some device drivers need know if PCI is initiated.
  * Basically, we think PCI is not initiated when there
@@ -79,7 +74,7 @@ int no_pci_devices(void)
 	struct device *dev;
 	int no_devices;
 
-	dev = bus_find_device(&pci_bus_type, NULL, NULL, find_anything);
+	dev = bus_find_next_device(&pci_bus_type, NULL);
 	no_devices = (dev == NULL);
 	put_device(dev);
 	return no_devices;
diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
index d843e362c167..0005ec9285aa 100644
--- a/drivers/s390/cio/ccwgroup.c
+++ b/drivers/s390/cio/ccwgroup.c
@@ -581,11 +581,6 @@ int ccwgroup_driver_register(struct ccwgroup_driver *cdriver)
 }
 EXPORT_SYMBOL(ccwgroup_driver_register);
 
-static int __ccwgroup_match_all(struct device *dev, const void *data)
-{
-	return 1;
-}
-
 /**
  * ccwgroup_driver_unregister() - deregister a ccw group driver
  * @cdriver: driver to be deregistered
@@ -597,8 +592,7 @@ void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver)
 	struct device *dev;
 
 	/* We don't want ccwgroup devices to live longer than their driver. */
-	while ((dev = driver_find_device(&cdriver->driver, NULL, NULL,
-					 __ccwgroup_match_all))) {
+	while ((dev = driver_find_next_device(&cdriver->driver, NULL))) {
 		struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
 
 		ccwgroup_ungroup(gdev);
diff --git a/drivers/scsi/scsi_proc.c b/drivers/scsi/scsi_proc.c
index c074631086a4..5b313226f11c 100644
--- a/drivers/scsi/scsi_proc.c
+++ b/drivers/scsi/scsi_proc.c
@@ -372,15 +372,10 @@ static ssize_t proc_scsi_write(struct file *file, const char __user *buf,
 	return err;
 }
 
-static int always_match(struct device *dev, const void *data)
-{
-	return 1;
-}
-
 static inline struct device *next_scsi_device(struct device *start)
 {
-	struct device *next = bus_find_device(&scsi_bus_type, start, NULL,
-					      always_match);
+	struct device *next = bus_find_next_device(&scsi_bus_type, start);
+
 	put_device(start);
 	return next;
 }
diff --git a/include/linux/device.h b/include/linux/device.h
index 7514ef3d3f1a..8ae3f4b47293 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -169,6 +169,7 @@ int device_match_of_node(struct device *dev, const void *np);
 int device_match_fwnode(struct device *dev, const void *fwnode);
 int device_match_devt(struct device *dev, const void *pdevt);
 int device_match_acpi_dev(struct device *dev, const void *adev);
+int device_match_any(struct device *dev, const void *unused);
 
 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
 		     int (*fn)(struct device *dev, void *data));
@@ -225,6 +226,16 @@ static inline struct device *bus_find_device_by_devt(struct bus_type *bus,
 	return bus_find_device(bus, NULL, &devt, device_match_devt);
 }
 
+/**
+ * bus_find_next_device - Find the next device after a given device in a
+ * given bus.
+ */
+static inline struct device *
+bus_find_next_device(struct bus_type *bus,struct device *cur)
+{
+	return bus_find_device(bus, cur, NULL, device_match_any);
+}
+
 #ifdef CONFIG_ACPI
 struct acpi_device;
 
@@ -465,6 +476,12 @@ static inline struct device *driver_find_device_by_devt(struct device_driver *dr
 	return driver_find_device(drv, NULL, &devt, device_match_devt);
 }
 
+static inline struct device *driver_find_next_device(struct device_driver *drv,
+						     struct device *start)
+{
+	return driver_find_device(drv, start, NULL, device_match_any);
+}
+
 #ifdef CONFIG_ACPI
 /**
  * driver_find_device_by_acpi_dev : device iterator for locating a particular
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH v3 6/7] drivers: Add generic helper to match any device
@ 2019-07-23 22:18   ` Suzuki K Poulose
  0 siblings, 0 replies; 71+ messages in thread
From: Suzuki K Poulose @ 2019-07-23 22:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: Rafael J. Wysocki, Shyam Sundar S K, Martin K. Petersen,
	Suzuki K Poulose, gregkh, James E.J. Bottomley, rafael,
	Elie Morisse, Bjorn Helgaas, Nehal Shah, linux-arm-kernel

Add a generic helper to match any/all devices. Using this
introduce new wrappers {bus/driver/class}_find_next_device().

Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Elie Morisse <syniurge@gmail.com>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Nehal Shah <nehal-bakulchandra.shah@amd.com>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Cc: Shyam Sundar S K <shyam-sundar.s-k@amd.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/base/core.c                  |  6 ++++++
 drivers/i2c/busses/i2c-amd-mp2-pci.c |  8 +-------
 drivers/pci/probe.c                  |  7 +------
 drivers/s390/cio/ccwgroup.c          |  8 +-------
 drivers/scsi/scsi_proc.c             |  9 ++-------
 include/linux/device.h               | 17 +++++++++++++++++
 6 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 57d71bc2c559..e22e29b3dc97 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3379,3 +3379,9 @@ int device_match_acpi_dev(struct device *dev, const void *adev)
 	return ACPI_COMPANION(dev) == adev;
 }
 EXPORT_SYMBOL(device_match_acpi_dev);
+
+int device_match_any(struct device *dev, const void *unused)
+{
+	return 1;
+}
+EXPORT_SYMBOL_GPL(device_match_any);
diff --git a/drivers/i2c/busses/i2c-amd-mp2-pci.c b/drivers/i2c/busses/i2c-amd-mp2-pci.c
index c7fe3b44a860..5e4800d72e00 100644
--- a/drivers/i2c/busses/i2c-amd-mp2-pci.c
+++ b/drivers/i2c/busses/i2c-amd-mp2-pci.c
@@ -457,18 +457,12 @@ static struct pci_driver amd_mp2_pci_driver = {
 };
 module_pci_driver(amd_mp2_pci_driver);
 
-static int amd_mp2_device_match(struct device *dev, const void *data)
-{
-	return 1;
-}
-
 struct amd_mp2_dev *amd_mp2_find_device(void)
 {
 	struct device *dev;
 	struct pci_dev *pci_dev;
 
-	dev = driver_find_device(&amd_mp2_pci_driver.driver, NULL, NULL,
-				 amd_mp2_device_match);
+	dev = driver_find_next_device(&amd_mp2_pci_driver.driver, NULL);
 	if (!dev)
 		return NULL;
 
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index a3c7338fad86..dbeeb385fb9f 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -64,11 +64,6 @@ static struct resource *get_pci_domain_busn_res(int domain_nr)
 	return &r->res;
 }
 
-static int find_anything(struct device *dev, const void *data)
-{
-	return 1;
-}
-
 /*
  * Some device drivers need know if PCI is initiated.
  * Basically, we think PCI is not initiated when there
@@ -79,7 +74,7 @@ int no_pci_devices(void)
 	struct device *dev;
 	int no_devices;
 
-	dev = bus_find_device(&pci_bus_type, NULL, NULL, find_anything);
+	dev = bus_find_next_device(&pci_bus_type, NULL);
 	no_devices = (dev == NULL);
 	put_device(dev);
 	return no_devices;
diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
index d843e362c167..0005ec9285aa 100644
--- a/drivers/s390/cio/ccwgroup.c
+++ b/drivers/s390/cio/ccwgroup.c
@@ -581,11 +581,6 @@ int ccwgroup_driver_register(struct ccwgroup_driver *cdriver)
 }
 EXPORT_SYMBOL(ccwgroup_driver_register);
 
-static int __ccwgroup_match_all(struct device *dev, const void *data)
-{
-	return 1;
-}
-
 /**
  * ccwgroup_driver_unregister() - deregister a ccw group driver
  * @cdriver: driver to be deregistered
@@ -597,8 +592,7 @@ void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver)
 	struct device *dev;
 
 	/* We don't want ccwgroup devices to live longer than their driver. */
-	while ((dev = driver_find_device(&cdriver->driver, NULL, NULL,
-					 __ccwgroup_match_all))) {
+	while ((dev = driver_find_next_device(&cdriver->driver, NULL))) {
 		struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
 
 		ccwgroup_ungroup(gdev);
diff --git a/drivers/scsi/scsi_proc.c b/drivers/scsi/scsi_proc.c
index c074631086a4..5b313226f11c 100644
--- a/drivers/scsi/scsi_proc.c
+++ b/drivers/scsi/scsi_proc.c
@@ -372,15 +372,10 @@ static ssize_t proc_scsi_write(struct file *file, const char __user *buf,
 	return err;
 }
 
-static int always_match(struct device *dev, const void *data)
-{
-	return 1;
-}
-
 static inline struct device *next_scsi_device(struct device *start)
 {
-	struct device *next = bus_find_device(&scsi_bus_type, start, NULL,
-					      always_match);
+	struct device *next = bus_find_next_device(&scsi_bus_type, start);
+
 	put_device(start);
 	return next;
 }
diff --git a/include/linux/device.h b/include/linux/device.h
index 7514ef3d3f1a..8ae3f4b47293 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -169,6 +169,7 @@ int device_match_of_node(struct device *dev, const void *np);
 int device_match_fwnode(struct device *dev, const void *fwnode);
 int device_match_devt(struct device *dev, const void *pdevt);
 int device_match_acpi_dev(struct device *dev, const void *adev);
+int device_match_any(struct device *dev, const void *unused);
 
 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
 		     int (*fn)(struct device *dev, void *data));
@@ -225,6 +226,16 @@ static inline struct device *bus_find_device_by_devt(struct bus_type *bus,
 	return bus_find_device(bus, NULL, &devt, device_match_devt);
 }
 
+/**
+ * bus_find_next_device - Find the next device after a given device in a
+ * given bus.
+ */
+static inline struct device *
+bus_find_next_device(struct bus_type *bus,struct device *cur)
+{
+	return bus_find_device(bus, cur, NULL, device_match_any);
+}
+
 #ifdef CONFIG_ACPI
 struct acpi_device;
 
@@ -465,6 +476,12 @@ static inline struct device *driver_find_device_by_devt(struct device_driver *dr
 	return driver_find_device(drv, NULL, &devt, device_match_devt);
 }
 
+static inline struct device *driver_find_next_device(struct device_driver *drv,
+						     struct device *start)
+{
+	return driver_find_device(drv, start, NULL, device_match_any);
+}
+
 #ifdef CONFIG_ACPI
 /**
  * driver_find_device_by_acpi_dev : device iterator for locating a particular
-- 
2.21.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH v3 7/7] platform: Add platform_find_device_by_driver() helper
  2019-07-23 22:18 ` Suzuki K Poulose
@ 2019-07-23 22:18   ` Suzuki K Poulose
  -1 siblings, 0 replies; 71+ messages in thread
From: Suzuki K Poulose @ 2019-07-23 22:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: gregkh, rafael, linux-arm-kernel, Suzuki K Poulose, Eric Anholt,
	Heiko Stübner, Inki Dae, Sandy Huang, Seung-Woo Kim

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


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH v3 7/7] platform: Add platform_find_device_by_driver() helper
@ 2019-07-23 22:18   ` Suzuki K Poulose
  0 siblings, 0 replies; 71+ messages in thread
From: Suzuki K Poulose @ 2019-07-23 22:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: Heiko Stübner, Suzuki K Poulose, gregkh, rafael,
	Seung-Woo Kim, Sandy Huang, Inki Dae, Eric Anholt,
	linux-arm-kernel

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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 6/7] drivers: Add generic helper to match any device
  2019-07-23 22:18   ` Suzuki K Poulose
@ 2019-07-23 22:24     ` Bjorn Helgaas
  -1 siblings, 0 replies; 71+ messages in thread
From: Bjorn Helgaas @ 2019-07-23 22:24 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Linux Kernel Mailing List, Greg Kroah-Hartman, Rafael J. Wysocki,
	linux-arm, Elie Morisse, James E.J. Bottomley,
	Martin K. Petersen, Nehal Shah, Rafael J. Wysocki,
	Shyam Sundar S K

On Tue, Jul 23, 2019 at 5:19 PM Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
>
> Add a generic helper to match any/all devices. Using this
> introduce new wrappers {bus/driver/class}_find_next_device().
>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: Elie Morisse <syniurge@gmail.com>
> Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
> Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
> Cc: Nehal Shah <nehal-bakulchandra.shah@amd.com>
> Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> Cc: Shyam Sundar S K <shyam-sundar.s-k@amd.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>

Acked-by: Bjorn Helgaas <bhelgaas@google.com> # PCI

> ---
>  drivers/base/core.c                  |  6 ++++++
>  drivers/i2c/busses/i2c-amd-mp2-pci.c |  8 +-------
>  drivers/pci/probe.c                  |  7 +------
>  drivers/s390/cio/ccwgroup.c          |  8 +-------
>  drivers/scsi/scsi_proc.c             |  9 ++-------
>  include/linux/device.h               | 17 +++++++++++++++++
>  6 files changed, 28 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 57d71bc2c559..e22e29b3dc97 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -3379,3 +3379,9 @@ int device_match_acpi_dev(struct device *dev, const void *adev)
>         return ACPI_COMPANION(dev) == adev;
>  }
>  EXPORT_SYMBOL(device_match_acpi_dev);
> +
> +int device_match_any(struct device *dev, const void *unused)
> +{
> +       return 1;
> +}
> +EXPORT_SYMBOL_GPL(device_match_any);
> diff --git a/drivers/i2c/busses/i2c-amd-mp2-pci.c b/drivers/i2c/busses/i2c-amd-mp2-pci.c
> index c7fe3b44a860..5e4800d72e00 100644
> --- a/drivers/i2c/busses/i2c-amd-mp2-pci.c
> +++ b/drivers/i2c/busses/i2c-amd-mp2-pci.c
> @@ -457,18 +457,12 @@ static struct pci_driver amd_mp2_pci_driver = {
>  };
>  module_pci_driver(amd_mp2_pci_driver);
>
> -static int amd_mp2_device_match(struct device *dev, const void *data)
> -{
> -       return 1;
> -}
> -
>  struct amd_mp2_dev *amd_mp2_find_device(void)
>  {
>         struct device *dev;
>         struct pci_dev *pci_dev;
>
> -       dev = driver_find_device(&amd_mp2_pci_driver.driver, NULL, NULL,
> -                                amd_mp2_device_match);
> +       dev = driver_find_next_device(&amd_mp2_pci_driver.driver, NULL);
>         if (!dev)
>                 return NULL;
>
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index a3c7338fad86..dbeeb385fb9f 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -64,11 +64,6 @@ static struct resource *get_pci_domain_busn_res(int domain_nr)
>         return &r->res;
>  }
>
> -static int find_anything(struct device *dev, const void *data)
> -{
> -       return 1;
> -}
> -
>  /*
>   * Some device drivers need know if PCI is initiated.
>   * Basically, we think PCI is not initiated when there
> @@ -79,7 +74,7 @@ int no_pci_devices(void)
>         struct device *dev;
>         int no_devices;
>
> -       dev = bus_find_device(&pci_bus_type, NULL, NULL, find_anything);
> +       dev = bus_find_next_device(&pci_bus_type, NULL);
>         no_devices = (dev == NULL);
>         put_device(dev);
>         return no_devices;
> diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
> index d843e362c167..0005ec9285aa 100644
> --- a/drivers/s390/cio/ccwgroup.c
> +++ b/drivers/s390/cio/ccwgroup.c
> @@ -581,11 +581,6 @@ int ccwgroup_driver_register(struct ccwgroup_driver *cdriver)
>  }
>  EXPORT_SYMBOL(ccwgroup_driver_register);
>
> -static int __ccwgroup_match_all(struct device *dev, const void *data)
> -{
> -       return 1;
> -}
> -
>  /**
>   * ccwgroup_driver_unregister() - deregister a ccw group driver
>   * @cdriver: driver to be deregistered
> @@ -597,8 +592,7 @@ void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver)
>         struct device *dev;
>
>         /* We don't want ccwgroup devices to live longer than their driver. */
> -       while ((dev = driver_find_device(&cdriver->driver, NULL, NULL,
> -                                        __ccwgroup_match_all))) {
> +       while ((dev = driver_find_next_device(&cdriver->driver, NULL))) {
>                 struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
>
>                 ccwgroup_ungroup(gdev);
> diff --git a/drivers/scsi/scsi_proc.c b/drivers/scsi/scsi_proc.c
> index c074631086a4..5b313226f11c 100644
> --- a/drivers/scsi/scsi_proc.c
> +++ b/drivers/scsi/scsi_proc.c
> @@ -372,15 +372,10 @@ static ssize_t proc_scsi_write(struct file *file, const char __user *buf,
>         return err;
>  }
>
> -static int always_match(struct device *dev, const void *data)
> -{
> -       return 1;
> -}
> -
>  static inline struct device *next_scsi_device(struct device *start)
>  {
> -       struct device *next = bus_find_device(&scsi_bus_type, start, NULL,
> -                                             always_match);
> +       struct device *next = bus_find_next_device(&scsi_bus_type, start);
> +
>         put_device(start);
>         return next;
>  }
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 7514ef3d3f1a..8ae3f4b47293 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -169,6 +169,7 @@ int device_match_of_node(struct device *dev, const void *np);
>  int device_match_fwnode(struct device *dev, const void *fwnode);
>  int device_match_devt(struct device *dev, const void *pdevt);
>  int device_match_acpi_dev(struct device *dev, const void *adev);
> +int device_match_any(struct device *dev, const void *unused);
>
>  int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
>                      int (*fn)(struct device *dev, void *data));
> @@ -225,6 +226,16 @@ static inline struct device *bus_find_device_by_devt(struct bus_type *bus,
>         return bus_find_device(bus, NULL, &devt, device_match_devt);
>  }
>
> +/**
> + * bus_find_next_device - Find the next device after a given device in a
> + * given bus.
> + */
> +static inline struct device *
> +bus_find_next_device(struct bus_type *bus,struct device *cur)
> +{
> +       return bus_find_device(bus, cur, NULL, device_match_any);
> +}
> +
>  #ifdef CONFIG_ACPI
>  struct acpi_device;
>
> @@ -465,6 +476,12 @@ static inline struct device *driver_find_device_by_devt(struct device_driver *dr
>         return driver_find_device(drv, NULL, &devt, device_match_devt);
>  }
>
> +static inline struct device *driver_find_next_device(struct device_driver *drv,
> +                                                    struct device *start)
> +{
> +       return driver_find_device(drv, start, NULL, device_match_any);
> +}
> +
>  #ifdef CONFIG_ACPI
>  /**
>   * driver_find_device_by_acpi_dev : device iterator for locating a particular
> --
> 2.21.0
>

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 6/7] drivers: Add generic helper to match any device
@ 2019-07-23 22:24     ` Bjorn Helgaas
  0 siblings, 0 replies; 71+ messages in thread
From: Bjorn Helgaas @ 2019-07-23 22:24 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Shyam Sundar S K, Martin K. Petersen, Rafael J. Wysocki,
	Greg Kroah-Hartman, James E.J. Bottomley, Rafael J. Wysocki,
	Linux Kernel Mailing List, Elie Morisse, Nehal Shah, linux-arm

On Tue, Jul 23, 2019 at 5:19 PM Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
>
> Add a generic helper to match any/all devices. Using this
> introduce new wrappers {bus/driver/class}_find_next_device().
>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: Elie Morisse <syniurge@gmail.com>
> Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
> Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
> Cc: Nehal Shah <nehal-bakulchandra.shah@amd.com>
> Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> Cc: Shyam Sundar S K <shyam-sundar.s-k@amd.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>

Acked-by: Bjorn Helgaas <bhelgaas@google.com> # PCI

> ---
>  drivers/base/core.c                  |  6 ++++++
>  drivers/i2c/busses/i2c-amd-mp2-pci.c |  8 +-------
>  drivers/pci/probe.c                  |  7 +------
>  drivers/s390/cio/ccwgroup.c          |  8 +-------
>  drivers/scsi/scsi_proc.c             |  9 ++-------
>  include/linux/device.h               | 17 +++++++++++++++++
>  6 files changed, 28 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 57d71bc2c559..e22e29b3dc97 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -3379,3 +3379,9 @@ int device_match_acpi_dev(struct device *dev, const void *adev)
>         return ACPI_COMPANION(dev) == adev;
>  }
>  EXPORT_SYMBOL(device_match_acpi_dev);
> +
> +int device_match_any(struct device *dev, const void *unused)
> +{
> +       return 1;
> +}
> +EXPORT_SYMBOL_GPL(device_match_any);
> diff --git a/drivers/i2c/busses/i2c-amd-mp2-pci.c b/drivers/i2c/busses/i2c-amd-mp2-pci.c
> index c7fe3b44a860..5e4800d72e00 100644
> --- a/drivers/i2c/busses/i2c-amd-mp2-pci.c
> +++ b/drivers/i2c/busses/i2c-amd-mp2-pci.c
> @@ -457,18 +457,12 @@ static struct pci_driver amd_mp2_pci_driver = {
>  };
>  module_pci_driver(amd_mp2_pci_driver);
>
> -static int amd_mp2_device_match(struct device *dev, const void *data)
> -{
> -       return 1;
> -}
> -
>  struct amd_mp2_dev *amd_mp2_find_device(void)
>  {
>         struct device *dev;
>         struct pci_dev *pci_dev;
>
> -       dev = driver_find_device(&amd_mp2_pci_driver.driver, NULL, NULL,
> -                                amd_mp2_device_match);
> +       dev = driver_find_next_device(&amd_mp2_pci_driver.driver, NULL);
>         if (!dev)
>                 return NULL;
>
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index a3c7338fad86..dbeeb385fb9f 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -64,11 +64,6 @@ static struct resource *get_pci_domain_busn_res(int domain_nr)
>         return &r->res;
>  }
>
> -static int find_anything(struct device *dev, const void *data)
> -{
> -       return 1;
> -}
> -
>  /*
>   * Some device drivers need know if PCI is initiated.
>   * Basically, we think PCI is not initiated when there
> @@ -79,7 +74,7 @@ int no_pci_devices(void)
>         struct device *dev;
>         int no_devices;
>
> -       dev = bus_find_device(&pci_bus_type, NULL, NULL, find_anything);
> +       dev = bus_find_next_device(&pci_bus_type, NULL);
>         no_devices = (dev == NULL);
>         put_device(dev);
>         return no_devices;
> diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
> index d843e362c167..0005ec9285aa 100644
> --- a/drivers/s390/cio/ccwgroup.c
> +++ b/drivers/s390/cio/ccwgroup.c
> @@ -581,11 +581,6 @@ int ccwgroup_driver_register(struct ccwgroup_driver *cdriver)
>  }
>  EXPORT_SYMBOL(ccwgroup_driver_register);
>
> -static int __ccwgroup_match_all(struct device *dev, const void *data)
> -{
> -       return 1;
> -}
> -
>  /**
>   * ccwgroup_driver_unregister() - deregister a ccw group driver
>   * @cdriver: driver to be deregistered
> @@ -597,8 +592,7 @@ void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver)
>         struct device *dev;
>
>         /* We don't want ccwgroup devices to live longer than their driver. */
> -       while ((dev = driver_find_device(&cdriver->driver, NULL, NULL,
> -                                        __ccwgroup_match_all))) {
> +       while ((dev = driver_find_next_device(&cdriver->driver, NULL))) {
>                 struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
>
>                 ccwgroup_ungroup(gdev);
> diff --git a/drivers/scsi/scsi_proc.c b/drivers/scsi/scsi_proc.c
> index c074631086a4..5b313226f11c 100644
> --- a/drivers/scsi/scsi_proc.c
> +++ b/drivers/scsi/scsi_proc.c
> @@ -372,15 +372,10 @@ static ssize_t proc_scsi_write(struct file *file, const char __user *buf,
>         return err;
>  }
>
> -static int always_match(struct device *dev, const void *data)
> -{
> -       return 1;
> -}
> -
>  static inline struct device *next_scsi_device(struct device *start)
>  {
> -       struct device *next = bus_find_device(&scsi_bus_type, start, NULL,
> -                                             always_match);
> +       struct device *next = bus_find_next_device(&scsi_bus_type, start);
> +
>         put_device(start);
>         return next;
>  }
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 7514ef3d3f1a..8ae3f4b47293 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -169,6 +169,7 @@ int device_match_of_node(struct device *dev, const void *np);
>  int device_match_fwnode(struct device *dev, const void *fwnode);
>  int device_match_devt(struct device *dev, const void *pdevt);
>  int device_match_acpi_dev(struct device *dev, const void *adev);
> +int device_match_any(struct device *dev, const void *unused);
>
>  int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
>                      int (*fn)(struct device *dev, void *data));
> @@ -225,6 +226,16 @@ static inline struct device *bus_find_device_by_devt(struct bus_type *bus,
>         return bus_find_device(bus, NULL, &devt, device_match_devt);
>  }
>
> +/**
> + * bus_find_next_device - Find the next device after a given device in a
> + * given bus.
> + */
> +static inline struct device *
> +bus_find_next_device(struct bus_type *bus,struct device *cur)
> +{
> +       return bus_find_device(bus, cur, NULL, device_match_any);
> +}
> +
>  #ifdef CONFIG_ACPI
>  struct acpi_device;
>
> @@ -465,6 +476,12 @@ static inline struct device *driver_find_device_by_devt(struct device_driver *dr
>         return driver_find_device(drv, NULL, &devt, device_match_devt);
>  }
>
> +static inline struct device *driver_find_next_device(struct device_driver *drv,
> +                                                    struct device *start)
> +{
> +       return driver_find_device(drv, start, NULL, device_match_any);
> +}
> +
>  #ifdef CONFIG_ACPI
>  /**
>   * driver_find_device_by_acpi_dev : device iterator for locating a particular
> --
> 2.21.0
>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 3/7] drivers: Introduce device lookup variants by fwnode
  2019-07-23 22:18   ` Suzuki K Poulose
@ 2019-07-24 10:16     ` Robin Murphy
  -1 siblings, 0 replies; 71+ messages in thread
From: Robin Murphy @ 2019-07-24 10:16 UTC (permalink / raw)
  To: Suzuki K Poulose, linux-kernel
  Cc: gregkh, rafael, linux-arm-kernel, David S. Miller, Doug Ledford,
	Heikki Krogerus, Jason Gunthorpe, linux-usb, Ulf Hansson,
	Joe Perches, Mathieu Poirier, Will Deacon, Joerg Roedel

On 23/07/2019 23:18, Suzuki K Poulose wrote:
> Add a helper to match the firmware node handle of a device and provide
> wrappers for {bus/class/driver}_find_device() APIs to avoid proliferation
> of duplicate custom match functions.
> 
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Doug Ledford <dledford@redhat.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: linux-usb@vger.kernel.org
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: Joe Perches <joe@perches.com>
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Joerg Roedel <joro@8bytes.org>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>   drivers/base/core.c                           |  6 +++
>   drivers/base/devcon.c                         |  8 +---
>   .../hwtracing/coresight/coresight-platform.c  | 11 +-----
>   drivers/hwtracing/coresight/coresight-priv.h  |  2 -
>   drivers/hwtracing/coresight/coresight.c       |  4 +-
>   drivers/infiniband/hw/hns/hns_roce_hw_v1.c    |  8 +---
>   drivers/iommu/arm-smmu-v3.c                   |  9 +----
>   drivers/iommu/arm-smmu.c                      |  9 +----

For the Arm SMMU drivers,

Acked-by: Robin Murphy <robin.murphy@arm.com>

>   .../ethernet/hisilicon/hns/hns_dsaf_misc.c    |  8 +---
>   drivers/usb/roles/class.c                     |  8 +---
>   drivers/usb/typec/class.c                     |  8 +---
>   include/linux/device.h                        | 39 +++++++++++++++++++
>   12 files changed, 57 insertions(+), 63 deletions(-)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index fb83647d685a..e8f81a667545 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -3368,3 +3368,9 @@ int device_match_of_node(struct device *dev, const void *np)
>   	return dev->of_node == np;
>   }
>   EXPORT_SYMBOL_GPL(device_match_of_node);
> +
> +int device_match_fwnode(struct device *dev, const void *fwnode)
> +{
> +	return dev_fwnode(dev) == fwnode;
> +}
> +EXPORT_SYMBOL_GPL(device_match_fwnode);
> diff --git a/drivers/base/devcon.c b/drivers/base/devcon.c
> index 09f28479b243..1d488dc5dd0c 100644
> --- a/drivers/base/devcon.c
> +++ b/drivers/base/devcon.c
> @@ -133,19 +133,13 @@ static struct bus_type *generic_match_buses[] = {
>   	NULL,
>   };
>   
> -static int device_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>   static void *device_connection_fwnode_match(struct device_connection *con)
>   {
>   	struct bus_type *bus;
>   	struct device *dev;
>   
>   	for (bus = generic_match_buses[0]; bus; bus++) {
> -		dev = bus_find_device(bus, NULL, (void *)con->fwnode,
> -				      device_fwnode_match);
> +		dev = bus_find_device_by_fwnode(bus, con->fwnode);
>   		if (dev && !strncmp(dev_name(dev), con->id, strlen(con->id)))
>   			return dev;
>   
> diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
> index dad7d96c5943..3c5bee429105 100644
> --- a/drivers/hwtracing/coresight/coresight-platform.c
> +++ b/drivers/hwtracing/coresight/coresight-platform.c
> @@ -37,11 +37,6 @@ static int coresight_alloc_conns(struct device *dev,
>   	return 0;
>   }
>   
> -int coresight_device_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>   static struct device *
>   coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
>   {
> @@ -51,8 +46,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
>   	 * If we have a non-configurable replicator, it will be found on the
>   	 * platform bus.
>   	 */
> -	dev = bus_find_device(&platform_bus_type, NULL,
> -			      fwnode, coresight_device_fwnode_match);
> +	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
>   	if (dev)
>   		return dev;
>   
> @@ -60,8 +54,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
>   	 * We have a configurable component - circle through the AMBA bus
>   	 * looking for the device that matches the endpoint node.
>   	 */
> -	return bus_find_device(&amba_bustype, NULL,
> -			       fwnode, coresight_device_fwnode_match);
> +	return bus_find_device_by_fwnode(&amba_bustype, fwnode);
>   }
>   
>   #ifdef CONFIG_OF
> diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
> index 7d401790dd7e..61d7f9ff054d 100644
> --- a/drivers/hwtracing/coresight/coresight-priv.h
> +++ b/drivers/hwtracing/coresight/coresight-priv.h
> @@ -202,6 +202,4 @@ static inline void *coresight_get_uci_data(const struct amba_id *id)
>   
>   void coresight_release_platform_data(struct coresight_platform_data *pdata);
>   
> -int coresight_device_fwnode_match(struct device *dev, const void *fwnode);
> -
>   #endif
> diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
> index 55db77f6410b..6453c67a4d01 100644
> --- a/drivers/hwtracing/coresight/coresight.c
> +++ b/drivers/hwtracing/coresight/coresight.c
> @@ -1046,9 +1046,7 @@ static void coresight_fixup_device_conns(struct coresight_device *csdev)
>   		struct coresight_connection *conn = &csdev->pdata->conns[i];
>   		struct device *dev = NULL;
>   
> -		dev = bus_find_device(&coresight_bustype, NULL,
> -				      (void *)conn->child_fwnode,
> -				      coresight_device_fwnode_match);
> +		dev = bus_find_device_by_fwnode(&coresight_bustype, conn->child_fwnode);
>   		if (dev) {
>   			conn->child_dev = to_coresight_device(dev);
>   			/* and put reference from 'bus_find_device()' */
> diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> index 81e6dedb1e02..fa05e943038a 100644
> --- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> @@ -4499,19 +4499,13 @@ static const struct acpi_device_id hns_roce_acpi_match[] = {
>   };
>   MODULE_DEVICE_TABLE(acpi, hns_roce_acpi_match);
>   
> -static int hns_roce_node_match(struct device *dev, const void *fwnode)
> -{
> -	return dev->fwnode == fwnode;
> -}
> -
>   static struct
>   platform_device *hns_roce_find_pdev(struct fwnode_handle *fwnode)
>   {
>   	struct device *dev;
>   
>   	/* get the 'device' corresponding to the matching 'fwnode' */
> -	dev = bus_find_device(&platform_bus_type, NULL,
> -			      fwnode, hns_roce_node_match);
> +	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
>   	/* get the platform device */
>   	return dev ? to_platform_device(dev) : NULL;
>   }
> diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c
> index a9a9fabd3968..6f0e13fa5e1a 100644
> --- a/drivers/iommu/arm-smmu-v3.c
> +++ b/drivers/iommu/arm-smmu-v3.c
> @@ -2034,16 +2034,11 @@ arm_smmu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova)
>   
>   static struct platform_driver arm_smmu_driver;
>   
> -static int arm_smmu_match_node(struct device *dev, const void *data)
> -{
> -	return dev->fwnode == data;
> -}
> -
>   static
>   struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
>   {
> -	struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL,
> -						fwnode, arm_smmu_match_node);
> +	struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver,
> +							  fwnode);
>   	put_device(dev);
>   	return dev ? dev_get_drvdata(dev) : NULL;
>   }
> diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
> index 64977c131ee6..aa06498f291d 100644
> --- a/drivers/iommu/arm-smmu.c
> +++ b/drivers/iommu/arm-smmu.c
> @@ -1426,16 +1426,11 @@ static bool arm_smmu_capable(enum iommu_cap cap)
>   	}
>   }
>   
> -static int arm_smmu_match_node(struct device *dev, const void *data)
> -{
> -	return dev->fwnode == data;
> -}
> -
>   static
>   struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
>   {
> -	struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL,
> -						fwnode, arm_smmu_match_node);
> +	struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver,
> +							  fwnode);
>   	put_device(dev);
>   	return dev ? dev_get_drvdata(dev) : NULL;
>   }
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
> index bb6586d0e5af..ed3829ae4ef1 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
> @@ -754,17 +754,11 @@ struct dsaf_misc_op *hns_misc_op_get(struct dsaf_device *dsaf_dev)
>   	return (void *)misc_op;
>   }
>   
> -static int hns_dsaf_dev_match(struct device *dev, const void *fwnode)
> -{
> -	return dev->fwnode == fwnode;
> -}
> -
>   struct
>   platform_device *hns_dsaf_find_platform_device(struct fwnode_handle *fwnode)
>   {
>   	struct device *dev;
>   
> -	dev = bus_find_device(&platform_bus_type, NULL,
> -			      fwnode, hns_dsaf_dev_match);
> +	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
>   	return dev ? to_platform_device(dev) : NULL;
>   }
> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
> index c8efe60e2465..0526efbc4922 100644
> --- a/drivers/usb/roles/class.c
> +++ b/drivers/usb/roles/class.c
> @@ -85,11 +85,6 @@ enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw)
>   }
>   EXPORT_SYMBOL_GPL(usb_role_switch_get_role);
>   
> -static int switch_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>   static void *usb_role_switch_match(struct device_connection *con, int ep,
>   				   void *data)
>   {
> @@ -99,8 +94,7 @@ static void *usb_role_switch_match(struct device_connection *con, int ep,
>   		if (con->id && !fwnode_property_present(con->fwnode, con->id))
>   			return NULL;
>   
> -		dev = class_find_device(role_class, NULL, con->fwnode,
> -					switch_fwnode_match);
> +		dev = class_find_device_by_fwnode(role_class, con->fwnode);
>   	} else {
>   		dev = class_find_device_by_name(role_class, con->endpoint[ep]);
>   	}
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 9b0d15b487e5..94a3eda62add 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -205,11 +205,6 @@ static void typec_altmode_put_partner(struct altmode *altmode)
>   	put_device(&adev->dev);
>   }
>   
> -static int typec_port_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>   static void *typec_port_match(struct device_connection *con, int ep, void *data)
>   {
>   	struct device *dev;
> @@ -219,8 +214,7 @@ static void *typec_port_match(struct device_connection *con, int ep, void *data)
>   	 * we need to return ERR_PTR(-PROBE_DEFER) when there is no device.
>   	 */
>   	if (con->fwnode)
> -		return class_find_device(typec_class, NULL, con->fwnode,
> -					 typec_port_fwnode_match);
> +		return class_find_device_by_fwnode(typec_class, con->fwnode);
>   
>   	dev = class_find_device_by_name(typec_class, con->endpoint[ep]);
>   
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 29d8d7ad41e6..7133fc1c285d 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -166,6 +166,7 @@ void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
>   
>   int device_match_name(struct device *dev, const void *name);
>   int device_match_of_node(struct device *dev, const void *np);
> +int device_match_fwnode(struct device *dev, const void *fwnode);
>   
>   int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
>   		     int (*fn)(struct device *dev, void *data));
> @@ -198,6 +199,18 @@ bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
>   	return bus_find_device(bus, NULL, np, device_match_of_node);
>   }
>   
> +/**
> + * bus_find_device_by_fwnode : device iterator for locating a particular device
> + * matching the fwnode.
> + * @bus: bus type
> + * @fwnode: fwnode of the device to match.
> + */
> +static inline struct device *
> +bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwnode)
> +{
> +	return bus_find_device(bus, NULL, fwnode, device_match_fwnode);
> +}
> +
>   struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
>   					struct device *hint);
>   int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
> @@ -391,6 +404,19 @@ driver_find_device_by_of_node(struct device_driver *drv,
>   	return driver_find_device(drv, NULL, np, device_match_of_node);
>   }
>   
> +/**
> + * driver_find_device_by_fwnode- device iterator for locating a particular device
> + * by fwnode pointer.
> + * @driver: the driver we're iterating
> + * @fwnode: fwnode pointer to match.
> + */
> +static inline struct device *
> +driver_find_device_by_fwnode(struct device_driver *drv,
> +			     const struct fwnode_handle *fwnode)
> +{
> +	return driver_find_device(drv, NULL, fwnode, device_match_fwnode);
> +}
> +
>   void driver_deferred_probe_add(struct device *dev);
>   int driver_deferred_probe_check_state(struct device *dev);
>   int driver_deferred_probe_check_state_continue(struct device *dev);
> @@ -544,6 +570,19 @@ class_find_device_by_of_node(struct class *class, const struct device_node *np)
>   	return class_find_device(class, NULL, np, device_match_of_node);
>   }
>   
> +/**
> + * class_find_device_by_fwnode : device iterator for locating a particular device
> + * matching the fwnode.
> + * @class: class type
> + * @fwnode: fwnode of the device to match.
> + */
> +static inline struct device *
> +class_find_device_by_fwnode(struct class *class,
> +			    const struct fwnode_handle *fwnode)
> +{
> +	return class_find_device(class, NULL, fwnode, device_match_fwnode);
> +}
> +
>   struct class_attribute {
>   	struct attribute attr;
>   	ssize_t (*show)(struct class *class, struct class_attribute *attr,
> 

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 3/7] drivers: Introduce device lookup variants by fwnode
@ 2019-07-24 10:16     ` Robin Murphy
  0 siblings, 0 replies; 71+ messages in thread
From: Robin Murphy @ 2019-07-24 10:16 UTC (permalink / raw)
  To: Suzuki K Poulose, linux-kernel
  Cc: Ulf Hansson, Heikki Krogerus, Mathieu Poirier, rafael, gregkh,
	Joerg Roedel, linux-usb, Will Deacon, Jason Gunthorpe,
	Doug Ledford, Joe Perches, David S. Miller, linux-arm-kernel

On 23/07/2019 23:18, Suzuki K Poulose wrote:
> Add a helper to match the firmware node handle of a device and provide
> wrappers for {bus/class/driver}_find_device() APIs to avoid proliferation
> of duplicate custom match functions.
> 
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Doug Ledford <dledford@redhat.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: linux-usb@vger.kernel.org
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: Joe Perches <joe@perches.com>
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Joerg Roedel <joro@8bytes.org>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>   drivers/base/core.c                           |  6 +++
>   drivers/base/devcon.c                         |  8 +---
>   .../hwtracing/coresight/coresight-platform.c  | 11 +-----
>   drivers/hwtracing/coresight/coresight-priv.h  |  2 -
>   drivers/hwtracing/coresight/coresight.c       |  4 +-
>   drivers/infiniband/hw/hns/hns_roce_hw_v1.c    |  8 +---
>   drivers/iommu/arm-smmu-v3.c                   |  9 +----
>   drivers/iommu/arm-smmu.c                      |  9 +----

For the Arm SMMU drivers,

Acked-by: Robin Murphy <robin.murphy@arm.com>

>   .../ethernet/hisilicon/hns/hns_dsaf_misc.c    |  8 +---
>   drivers/usb/roles/class.c                     |  8 +---
>   drivers/usb/typec/class.c                     |  8 +---
>   include/linux/device.h                        | 39 +++++++++++++++++++
>   12 files changed, 57 insertions(+), 63 deletions(-)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index fb83647d685a..e8f81a667545 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -3368,3 +3368,9 @@ int device_match_of_node(struct device *dev, const void *np)
>   	return dev->of_node == np;
>   }
>   EXPORT_SYMBOL_GPL(device_match_of_node);
> +
> +int device_match_fwnode(struct device *dev, const void *fwnode)
> +{
> +	return dev_fwnode(dev) == fwnode;
> +}
> +EXPORT_SYMBOL_GPL(device_match_fwnode);
> diff --git a/drivers/base/devcon.c b/drivers/base/devcon.c
> index 09f28479b243..1d488dc5dd0c 100644
> --- a/drivers/base/devcon.c
> +++ b/drivers/base/devcon.c
> @@ -133,19 +133,13 @@ static struct bus_type *generic_match_buses[] = {
>   	NULL,
>   };
>   
> -static int device_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>   static void *device_connection_fwnode_match(struct device_connection *con)
>   {
>   	struct bus_type *bus;
>   	struct device *dev;
>   
>   	for (bus = generic_match_buses[0]; bus; bus++) {
> -		dev = bus_find_device(bus, NULL, (void *)con->fwnode,
> -				      device_fwnode_match);
> +		dev = bus_find_device_by_fwnode(bus, con->fwnode);
>   		if (dev && !strncmp(dev_name(dev), con->id, strlen(con->id)))
>   			return dev;
>   
> diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
> index dad7d96c5943..3c5bee429105 100644
> --- a/drivers/hwtracing/coresight/coresight-platform.c
> +++ b/drivers/hwtracing/coresight/coresight-platform.c
> @@ -37,11 +37,6 @@ static int coresight_alloc_conns(struct device *dev,
>   	return 0;
>   }
>   
> -int coresight_device_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>   static struct device *
>   coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
>   {
> @@ -51,8 +46,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
>   	 * If we have a non-configurable replicator, it will be found on the
>   	 * platform bus.
>   	 */
> -	dev = bus_find_device(&platform_bus_type, NULL,
> -			      fwnode, coresight_device_fwnode_match);
> +	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
>   	if (dev)
>   		return dev;
>   
> @@ -60,8 +54,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
>   	 * We have a configurable component - circle through the AMBA bus
>   	 * looking for the device that matches the endpoint node.
>   	 */
> -	return bus_find_device(&amba_bustype, NULL,
> -			       fwnode, coresight_device_fwnode_match);
> +	return bus_find_device_by_fwnode(&amba_bustype, fwnode);
>   }
>   
>   #ifdef CONFIG_OF
> diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
> index 7d401790dd7e..61d7f9ff054d 100644
> --- a/drivers/hwtracing/coresight/coresight-priv.h
> +++ b/drivers/hwtracing/coresight/coresight-priv.h
> @@ -202,6 +202,4 @@ static inline void *coresight_get_uci_data(const struct amba_id *id)
>   
>   void coresight_release_platform_data(struct coresight_platform_data *pdata);
>   
> -int coresight_device_fwnode_match(struct device *dev, const void *fwnode);
> -
>   #endif
> diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
> index 55db77f6410b..6453c67a4d01 100644
> --- a/drivers/hwtracing/coresight/coresight.c
> +++ b/drivers/hwtracing/coresight/coresight.c
> @@ -1046,9 +1046,7 @@ static void coresight_fixup_device_conns(struct coresight_device *csdev)
>   		struct coresight_connection *conn = &csdev->pdata->conns[i];
>   		struct device *dev = NULL;
>   
> -		dev = bus_find_device(&coresight_bustype, NULL,
> -				      (void *)conn->child_fwnode,
> -				      coresight_device_fwnode_match);
> +		dev = bus_find_device_by_fwnode(&coresight_bustype, conn->child_fwnode);
>   		if (dev) {
>   			conn->child_dev = to_coresight_device(dev);
>   			/* and put reference from 'bus_find_device()' */
> diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> index 81e6dedb1e02..fa05e943038a 100644
> --- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> @@ -4499,19 +4499,13 @@ static const struct acpi_device_id hns_roce_acpi_match[] = {
>   };
>   MODULE_DEVICE_TABLE(acpi, hns_roce_acpi_match);
>   
> -static int hns_roce_node_match(struct device *dev, const void *fwnode)
> -{
> -	return dev->fwnode == fwnode;
> -}
> -
>   static struct
>   platform_device *hns_roce_find_pdev(struct fwnode_handle *fwnode)
>   {
>   	struct device *dev;
>   
>   	/* get the 'device' corresponding to the matching 'fwnode' */
> -	dev = bus_find_device(&platform_bus_type, NULL,
> -			      fwnode, hns_roce_node_match);
> +	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
>   	/* get the platform device */
>   	return dev ? to_platform_device(dev) : NULL;
>   }
> diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c
> index a9a9fabd3968..6f0e13fa5e1a 100644
> --- a/drivers/iommu/arm-smmu-v3.c
> +++ b/drivers/iommu/arm-smmu-v3.c
> @@ -2034,16 +2034,11 @@ arm_smmu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova)
>   
>   static struct platform_driver arm_smmu_driver;
>   
> -static int arm_smmu_match_node(struct device *dev, const void *data)
> -{
> -	return dev->fwnode == data;
> -}
> -
>   static
>   struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
>   {
> -	struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL,
> -						fwnode, arm_smmu_match_node);
> +	struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver,
> +							  fwnode);
>   	put_device(dev);
>   	return dev ? dev_get_drvdata(dev) : NULL;
>   }
> diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
> index 64977c131ee6..aa06498f291d 100644
> --- a/drivers/iommu/arm-smmu.c
> +++ b/drivers/iommu/arm-smmu.c
> @@ -1426,16 +1426,11 @@ static bool arm_smmu_capable(enum iommu_cap cap)
>   	}
>   }
>   
> -static int arm_smmu_match_node(struct device *dev, const void *data)
> -{
> -	return dev->fwnode == data;
> -}
> -
>   static
>   struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
>   {
> -	struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL,
> -						fwnode, arm_smmu_match_node);
> +	struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver,
> +							  fwnode);
>   	put_device(dev);
>   	return dev ? dev_get_drvdata(dev) : NULL;
>   }
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
> index bb6586d0e5af..ed3829ae4ef1 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
> @@ -754,17 +754,11 @@ struct dsaf_misc_op *hns_misc_op_get(struct dsaf_device *dsaf_dev)
>   	return (void *)misc_op;
>   }
>   
> -static int hns_dsaf_dev_match(struct device *dev, const void *fwnode)
> -{
> -	return dev->fwnode == fwnode;
> -}
> -
>   struct
>   platform_device *hns_dsaf_find_platform_device(struct fwnode_handle *fwnode)
>   {
>   	struct device *dev;
>   
> -	dev = bus_find_device(&platform_bus_type, NULL,
> -			      fwnode, hns_dsaf_dev_match);
> +	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
>   	return dev ? to_platform_device(dev) : NULL;
>   }
> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
> index c8efe60e2465..0526efbc4922 100644
> --- a/drivers/usb/roles/class.c
> +++ b/drivers/usb/roles/class.c
> @@ -85,11 +85,6 @@ enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw)
>   }
>   EXPORT_SYMBOL_GPL(usb_role_switch_get_role);
>   
> -static int switch_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>   static void *usb_role_switch_match(struct device_connection *con, int ep,
>   				   void *data)
>   {
> @@ -99,8 +94,7 @@ static void *usb_role_switch_match(struct device_connection *con, int ep,
>   		if (con->id && !fwnode_property_present(con->fwnode, con->id))
>   			return NULL;
>   
> -		dev = class_find_device(role_class, NULL, con->fwnode,
> -					switch_fwnode_match);
> +		dev = class_find_device_by_fwnode(role_class, con->fwnode);
>   	} else {
>   		dev = class_find_device_by_name(role_class, con->endpoint[ep]);
>   	}
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 9b0d15b487e5..94a3eda62add 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -205,11 +205,6 @@ static void typec_altmode_put_partner(struct altmode *altmode)
>   	put_device(&adev->dev);
>   }
>   
> -static int typec_port_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>   static void *typec_port_match(struct device_connection *con, int ep, void *data)
>   {
>   	struct device *dev;
> @@ -219,8 +214,7 @@ static void *typec_port_match(struct device_connection *con, int ep, void *data)
>   	 * we need to return ERR_PTR(-PROBE_DEFER) when there is no device.
>   	 */
>   	if (con->fwnode)
> -		return class_find_device(typec_class, NULL, con->fwnode,
> -					 typec_port_fwnode_match);
> +		return class_find_device_by_fwnode(typec_class, con->fwnode);
>   
>   	dev = class_find_device_by_name(typec_class, con->endpoint[ep]);
>   
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 29d8d7ad41e6..7133fc1c285d 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -166,6 +166,7 @@ void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
>   
>   int device_match_name(struct device *dev, const void *name);
>   int device_match_of_node(struct device *dev, const void *np);
> +int device_match_fwnode(struct device *dev, const void *fwnode);
>   
>   int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
>   		     int (*fn)(struct device *dev, void *data));
> @@ -198,6 +199,18 @@ bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
>   	return bus_find_device(bus, NULL, np, device_match_of_node);
>   }
>   
> +/**
> + * bus_find_device_by_fwnode : device iterator for locating a particular device
> + * matching the fwnode.
> + * @bus: bus type
> + * @fwnode: fwnode of the device to match.
> + */
> +static inline struct device *
> +bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwnode)
> +{
> +	return bus_find_device(bus, NULL, fwnode, device_match_fwnode);
> +}
> +
>   struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
>   					struct device *hint);
>   int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
> @@ -391,6 +404,19 @@ driver_find_device_by_of_node(struct device_driver *drv,
>   	return driver_find_device(drv, NULL, np, device_match_of_node);
>   }
>   
> +/**
> + * driver_find_device_by_fwnode- device iterator for locating a particular device
> + * by fwnode pointer.
> + * @driver: the driver we're iterating
> + * @fwnode: fwnode pointer to match.
> + */
> +static inline struct device *
> +driver_find_device_by_fwnode(struct device_driver *drv,
> +			     const struct fwnode_handle *fwnode)
> +{
> +	return driver_find_device(drv, NULL, fwnode, device_match_fwnode);
> +}
> +
>   void driver_deferred_probe_add(struct device *dev);
>   int driver_deferred_probe_check_state(struct device *dev);
>   int driver_deferred_probe_check_state_continue(struct device *dev);
> @@ -544,6 +570,19 @@ class_find_device_by_of_node(struct class *class, const struct device_node *np)
>   	return class_find_device(class, NULL, np, device_match_of_node);
>   }
>   
> +/**
> + * class_find_device_by_fwnode : device iterator for locating a particular device
> + * matching the fwnode.
> + * @class: class type
> + * @fwnode: fwnode of the device to match.
> + */
> +static inline struct device *
> +class_find_device_by_fwnode(struct class *class,
> +			    const struct fwnode_handle *fwnode)
> +{
> +	return class_find_device(class, NULL, fwnode, device_match_fwnode);
> +}
> +
>   struct class_attribute {
>   	struct attribute attr;
>   	ssize_t (*show)(struct class *class, struct class_attribute *attr,
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 7/7] platform: Add platform_find_device_by_driver() helper
  2019-07-23 22:18   ` Suzuki K Poulose
@ 2019-07-24 10:44     ` Robin Murphy
  -1 siblings, 0 replies; 71+ messages in thread
From: Robin Murphy @ 2019-07-24 10:44 UTC (permalink / raw)
  To: Suzuki K Poulose, linux-kernel
  Cc: Heiko Stübner, gregkh, rafael, Seung-Woo Kim, Sandy Huang,
	Inki Dae, Eric Anholt, linux-arm-kernel

On 23/07/2019 23:18, Suzuki K Poulose wrote:
> Provide a helper to lookup platform devices by matching device
> driver in order to avoid drivers trying to use platform bus
> internals.

FWIW, this whole drm_match_add idiom really looks like it deserves 
factoring out into an of_platform_populate-style helper, but I guess 
aligning those subtle little differences is a non-trivial challenge.

[and I am well aware of just how much of a big messy can of worms DRM 
device probing is in general]

> 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

Nit: "with" is easy to misinterpret there - my initial reaction to 
looking at this was "so why not just use driver_find_device()?". Maybe 
"which would match" might make it a bit clearer?

Robin.

> + * 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);
> 

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 7/7] platform: Add platform_find_device_by_driver() helper
@ 2019-07-24 10:44     ` Robin Murphy
  0 siblings, 0 replies; 71+ messages in thread
From: Robin Murphy @ 2019-07-24 10:44 UTC (permalink / raw)
  To: Suzuki K Poulose, linux-kernel
  Cc: Heiko Stübner, rafael, gregkh, Seung-Woo Kim, Sandy Huang,
	Inki Dae, Eric Anholt, linux-arm-kernel

On 23/07/2019 23:18, Suzuki K Poulose wrote:
> Provide a helper to lookup platform devices by matching device
> driver in order to avoid drivers trying to use platform bus
> internals.

FWIW, this whole drm_match_add idiom really looks like it deserves 
factoring out into an of_platform_populate-style helper, but I guess 
aligning those subtle little differences is a non-trivial challenge.

[and I am well aware of just how much of a big messy can of worms DRM 
device probing is in general]

> 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

Nit: "with" is easy to misinterpret there - my initial reaction to 
looking at this was "so why not just use driver_find_device()?". Maybe 
"which would match" might make it a bit clearer?

Robin.

> + * 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);
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
  2019-07-23 22:18   ` Suzuki K Poulose
  (?)
@ 2019-07-25 13:54     ` Lee Jones
  -1 siblings, 0 replies; 71+ messages in thread
From: Lee Jones @ 2019-07-25 13:54 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: linux-kernel, gregkh, rafael, linux-arm-kernel,
	Maarten Lankhorst, Maxime Ripard, dri-devel, David Airlie,
	Daniel Vetter, devicetree, Florian Fainelli, Frank Rowand,
	Heiko Stuebner, Liam Girdwood, linux-i2c, linux-rockchip,
	linux-spi, Mathieu Poirier, Rob Herring, Srinivas Kandagatla,
	Takashi Iwai, Wolfram Sang, Alan Tull, Moritz Fischer,
	linux-fpga, Peter Rosin, Mark Brown, Heiner Kallweit,
	David S. Miller, Andrew Lunn, Thor Thayer, Jiri Slaby

On Tue, 23 Jul 2019, Suzuki K Poulose wrote:

> Introduce wrappers for {bus/driver/class}_find_device() to
> locate devices by its of_node.
> 
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <maxime.ripard@bootlin.com>
> Cc: dri-devel@lists.freedesktop.org
> Cc: David Airlie <airlied@linux.ie>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: devicetree@vger.kernel.org
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Frank Rowand <frowand.list@gmail.com>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: linux-i2c@vger.kernel.org
> Cc: linux-rockchip@lists.infradead.org
> Cc: linux-spi@vger.kernel.org
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> Cc: Takashi Iwai <tiwai@suse.com>
> Cc: Wolfram Sang <wsa@the-dreams.de>
> Cc: Alan Tull <atull@kernel.org>
> Cc: Moritz Fischer <mdf@kernel.org>
> Cc: linux-fpga@vger.kernel.org
> Cc: Peter Rosin <peda@axentia.se>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Heiner Kallweit <hkallweit1@gmail.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Lee Jones <lee.jones@linaro.org>
> Cc: Thor Thayer <thor.thayer@linux.intel.com>
> Cc: Jiri Slaby <jslaby@suse.com>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Peter Rosin <peda@axentia.se>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>  - Dropped the reviewed-by tags from Thor, Mark, Andrew and Peter as the
>    patches are mereged, though there are no functional changes.
> ---
>  drivers/amba/tegra-ahb.c              | 11 +-------
>  drivers/fpga/fpga-bridge.c            |  8 +-----
>  drivers/fpga/fpga-mgr.c               |  8 +-----
>  drivers/gpu/drm/drm_mipi_dsi.c        |  7 +----
>  drivers/i2c/i2c-core-of.c             |  7 +----
>  drivers/mfd/altera-sysmgr.c           | 14 ++--------

For my own reference:
  Acked-for-MFD-by: Lee Jones <lee.jones@linaro.org>

What's the merge plan for this patch?

Is anyone prepared to create an immutable branch for us to pull from?
I'm happy to do it if no one else steps up.

>  drivers/mux/core.c                    |  7 +----
>  drivers/net/phy/mdio_bus.c            |  9 +------
>  drivers/nvmem/core.c                  |  7 +----
>  drivers/of/of_mdio.c                  |  8 +-----
>  drivers/of/platform.c                 |  7 +----
>  drivers/regulator/of_regulator.c      |  7 +----
>  drivers/spi/spi.c                     | 20 +++------------
>  include/linux/device.h                | 37 +++++++++++++++++++++++++++
>  sound/soc/rockchip/rk3399_gru_sound.c |  9 ++-----
>  15 files changed, 56 insertions(+), 110 deletions(-)

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
@ 2019-07-25 13:54     ` Lee Jones
  0 siblings, 0 replies; 71+ messages in thread
From: Lee Jones @ 2019-07-25 13:54 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Andrew Lunn, Thor Thayer, rafael, Maxime Ripard, linux-fpga,
	dri-devel, linux-kernel, David S. Miller, Srinivas Kandagatla,
	linux-i2c, Frank Rowand, Florian Fainelli, linux-rockchip,
	Wolfram Sang, David Airlie, Jiri Slaby, devicetree, Alan Tull,
	Liam Girdwood, Rob Herring, Moritz Fischer, linux-arm-kernel,
	Mathieu Poirier, gregkh, Takashi Iwai, linux-spi

On Tue, 23 Jul 2019, Suzuki K Poulose wrote:

> Introduce wrappers for {bus/driver/class}_find_device() to
> locate devices by its of_node.
> 
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <maxime.ripard@bootlin.com>
> Cc: dri-devel@lists.freedesktop.org
> Cc: David Airlie <airlied@linux.ie>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: devicetree@vger.kernel.org
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Frank Rowand <frowand.list@gmail.com>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: linux-i2c@vger.kernel.org
> Cc: linux-rockchip@lists.infradead.org
> Cc: linux-spi@vger.kernel.org
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> Cc: Takashi Iwai <tiwai@suse.com>
> Cc: Wolfram Sang <wsa@the-dreams.de>
> Cc: Alan Tull <atull@kernel.org>
> Cc: Moritz Fischer <mdf@kernel.org>
> Cc: linux-fpga@vger.kernel.org
> Cc: Peter Rosin <peda@axentia.se>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Heiner Kallweit <hkallweit1@gmail.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Lee Jones <lee.jones@linaro.org>
> Cc: Thor Thayer <thor.thayer@linux.intel.com>
> Cc: Jiri Slaby <jslaby@suse.com>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Peter Rosin <peda@axentia.se>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>  - Dropped the reviewed-by tags from Thor, Mark, Andrew and Peter as the
>    patches are mereged, though there are no functional changes.
> ---
>  drivers/amba/tegra-ahb.c              | 11 +-------
>  drivers/fpga/fpga-bridge.c            |  8 +-----
>  drivers/fpga/fpga-mgr.c               |  8 +-----
>  drivers/gpu/drm/drm_mipi_dsi.c        |  7 +----
>  drivers/i2c/i2c-core-of.c             |  7 +----
>  drivers/mfd/altera-sysmgr.c           | 14 ++--------

For my own reference:
  Acked-for-MFD-by: Lee Jones <lee.jones@linaro.org>

What's the merge plan for this patch?

Is anyone prepared to create an immutable branch for us to pull from?
I'm happy to do it if no one else steps up.

>  drivers/mux/core.c                    |  7 +----
>  drivers/net/phy/mdio_bus.c            |  9 +------
>  drivers/nvmem/core.c                  |  7 +----
>  drivers/of/of_mdio.c                  |  8 +-----
>  drivers/of/platform.c                 |  7 +----
>  drivers/regulator/of_regulator.c      |  7 +----
>  drivers/spi/spi.c                     | 20 +++------------
>  include/linux/device.h                | 37 +++++++++++++++++++++++++++
>  sound/soc/rockchip/rk3399_gru_sound.c |  9 ++-----
>  15 files changed, 56 insertions(+), 110 deletions(-)

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
@ 2019-07-25 13:54     ` Lee Jones
  0 siblings, 0 replies; 71+ messages in thread
From: Lee Jones @ 2019-07-25 13:54 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Andrew Lunn, Thor Thayer, Heiko Stuebner, rafael, Maxime Ripard,
	linux-fpga, dri-devel, linux-kernel, David S. Miller,
	Srinivas Kandagatla, linux-i2c, Frank Rowand, Florian Fainelli,
	linux-rockchip, Wolfram Sang, David Airlie, Jiri Slaby,
	devicetree, Alan Tull, Liam Girdwood, Maarten Lankhorst,
	Rob Herring, Moritz Fischer, linux-arm-kernel, Mathieu Poirier,
	gregkh, Takashi Iwai, linux-spi, Mark Brown, Daniel Vetter,
	Peter Rosin, Heiner Kallweit

On Tue, 23 Jul 2019, Suzuki K Poulose wrote:

> Introduce wrappers for {bus/driver/class}_find_device() to
> locate devices by its of_node.
> 
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <maxime.ripard@bootlin.com>
> Cc: dri-devel@lists.freedesktop.org
> Cc: David Airlie <airlied@linux.ie>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: devicetree@vger.kernel.org
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Frank Rowand <frowand.list@gmail.com>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: linux-i2c@vger.kernel.org
> Cc: linux-rockchip@lists.infradead.org
> Cc: linux-spi@vger.kernel.org
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> Cc: Takashi Iwai <tiwai@suse.com>
> Cc: Wolfram Sang <wsa@the-dreams.de>
> Cc: Alan Tull <atull@kernel.org>
> Cc: Moritz Fischer <mdf@kernel.org>
> Cc: linux-fpga@vger.kernel.org
> Cc: Peter Rosin <peda@axentia.se>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Heiner Kallweit <hkallweit1@gmail.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Lee Jones <lee.jones@linaro.org>
> Cc: Thor Thayer <thor.thayer@linux.intel.com>
> Cc: Jiri Slaby <jslaby@suse.com>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Peter Rosin <peda@axentia.se>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>  - Dropped the reviewed-by tags from Thor, Mark, Andrew and Peter as the
>    patches are mereged, though there are no functional changes.
> ---
>  drivers/amba/tegra-ahb.c              | 11 +-------
>  drivers/fpga/fpga-bridge.c            |  8 +-----
>  drivers/fpga/fpga-mgr.c               |  8 +-----
>  drivers/gpu/drm/drm_mipi_dsi.c        |  7 +----
>  drivers/i2c/i2c-core-of.c             |  7 +----
>  drivers/mfd/altera-sysmgr.c           | 14 ++--------

For my own reference:
  Acked-for-MFD-by: Lee Jones <lee.jones@linaro.org>

What's the merge plan for this patch?

Is anyone prepared to create an immutable branch for us to pull from?
I'm happy to do it if no one else steps up.

>  drivers/mux/core.c                    |  7 +----
>  drivers/net/phy/mdio_bus.c            |  9 +------
>  drivers/nvmem/core.c                  |  7 +----
>  drivers/of/of_mdio.c                  |  8 +-----
>  drivers/of/platform.c                 |  7 +----
>  drivers/regulator/of_regulator.c      |  7 +----
>  drivers/spi/spi.c                     | 20 +++------------
>  include/linux/device.h                | 37 +++++++++++++++++++++++++++
>  sound/soc/rockchip/rk3399_gru_sound.c |  9 ++-----
>  15 files changed, 56 insertions(+), 110 deletions(-)

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 0/7] drivers: Add generic device lookup helpers
  2019-07-23 22:18 ` Suzuki K Poulose
  (?)
@ 2019-07-25 14:10   ` Greg KH
  -1 siblings, 0 replies; 71+ messages in thread
From: Greg KH @ 2019-07-25 14:10 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Andrew Lunn, Alexander Aring, Heikki Krogerus, Jacek Anaszewski,
	rafael, Alexander Shishkin, linux-fpga, Heiko Carstens,
	Alexandre Belloni, dri-devel, Liam Girdwood, Elie Morisse,
	Srinivas Kandagatla, linux-i2c, Pavel Machek, Shyam Sundar S K,
	Frank Rowand, linux-leds, linux-rtc, Maxime Ripard,
	Florian Fainelli, linux-acpi, Jason Gunthorpe, Lee Jones

On Tue, Jul 23, 2019 at 11:18:31PM +0100, Suzuki K Poulose wrote:
> We have device iterators to find a particular device matching a criteria
> for a given bus/class/driver. i.e, {bus,class,driver}_find_device()
> APIs. The matching criteria is a function pointer for the APIs. Often the
> lookup is based on a generic property of a device (e.g, name, fwnode, of node
> pointer or device type) rather than a driver specific information. However, each
> driver writes up its own "match" function, spilling the similar match functions
> all over the driver subsystems.
> 
> This series adds device match helpers by generic device properties of a device.
> Using these generic match functions, introduce wrappers to the existing
>  *_find_device() helpers and converts the existing users to use the new wrappers.
>  i.e,
> 	{bus/class/driver}_find_device_by_name()
> 	{bus/class/driver}_find_device_by_fwnode()
> 	{bus/class/driver}_find_device_by_devt()
> 	{bus/class/driver}_find_device_by_acpi_dev()
> 
> Also adds a wrapper for finding a platform device by driver, to avoid
> spilling the platform_bus internals in the individual drivers. Applies
> on 5.3-rc1.
> 
>    [0] git://linux-arm.org/linux-skp.git driver-cleanup/v3
> RFC[1] https://marc.info/?i=1559577023-558-1-git-send-email-suzuki.poulose@arm.com
> V1 [2] https://marc.info/?i=1559747630-28065-1-git-send-email-suzuki.poulose@arm.com
> V2 [3] https://marc.info/?i=1560534863-15115-1-git-send-email-suzuki.poulose@arm.com
> 
> Changes since v2:
>  - Merge the device match helper introduction patch with the variants
>    of the helpers, for better review.
>  - Use platform_find_device_by_driver for mcde drm driver.

This looks good to me at first glance, thanks for doing this work.

I'll wait a few days to collect acks from various subsystem maintainers
before taking the series in my tree.

thanks,

greg k-h
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 0/7] drivers: Add generic device lookup helpers
@ 2019-07-25 14:10   ` Greg KH
  0 siblings, 0 replies; 71+ messages in thread
From: Greg KH @ 2019-07-25 14:10 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Andrew Lunn, Alexander Aring, Heikki Krogerus, Jacek Anaszewski,
	rafael, Alexander Shishkin, linux-fpga, Heiko Carstens,
	Alexandre Belloni, dri-devel, Liam Girdwood, Elie Morisse,
	Srinivas Kandagatla, linux-i2c, Pavel Machek, Shyam Sundar S K,
	Frank Rowand, linux-leds, linux-rtc, Maxime Ripard,
	Florian Fainelli, linux-acpi, Jason Gunthorpe, Lee Jones

On Tue, Jul 23, 2019 at 11:18:31PM +0100, Suzuki K Poulose wrote:
> We have device iterators to find a particular device matching a criteria
> for a given bus/class/driver. i.e, {bus,class,driver}_find_device()
> APIs. The matching criteria is a function pointer for the APIs. Often the
> lookup is based on a generic property of a device (e.g, name, fwnode, of node
> pointer or device type) rather than a driver specific information. However, each
> driver writes up its own "match" function, spilling the similar match functions
> all over the driver subsystems.
> 
> This series adds device match helpers by generic device properties of a device.
> Using these generic match functions, introduce wrappers to the existing
>  *_find_device() helpers and converts the existing users to use the new wrappers.
>  i.e,
> 	{bus/class/driver}_find_device_by_name()
> 	{bus/class/driver}_find_device_by_fwnode()
> 	{bus/class/driver}_find_device_by_devt()
> 	{bus/class/driver}_find_device_by_acpi_dev()
> 
> Also adds a wrapper for finding a platform device by driver, to avoid
> spilling the platform_bus internals in the individual drivers. Applies
> on 5.3-rc1.
> 
>    [0] git://linux-arm.org/linux-skp.git driver-cleanup/v3
> RFC[1] https://marc.info/?i=1559577023-558-1-git-send-email-suzuki.poulose@arm.com
> V1 [2] https://marc.info/?i=1559747630-28065-1-git-send-email-suzuki.poulose@arm.com
> V2 [3] https://marc.info/?i=1560534863-15115-1-git-send-email-suzuki.poulose@arm.com
> 
> Changes since v2:
>  - Merge the device match helper introduction patch with the variants
>    of the helpers, for better review.
>  - Use platform_find_device_by_driver for mcde drm driver.

This looks good to me at first glance, thanks for doing this work.

I'll wait a few days to collect acks from various subsystem maintainers
before taking the series in my tree.

thanks,

greg k-h
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 0/7] drivers: Add generic device lookup helpers
@ 2019-07-25 14:10   ` Greg KH
  0 siblings, 0 replies; 71+ messages in thread
From: Greg KH @ 2019-07-25 14:10 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: linux-kernel, rafael, linux-arm-kernel, Alan Tull,
	Alessandro Zummo, Alexander Aring, Alexander Shishkin,
	Alexandre Belloni, Andrew Lunn, Arnd Bergmann, Bjorn Helgaas,
	Daniel Vetter, Dan Murphy, David Airlie, David S. Miller,
	devicetree, Doug Ledford, dri-devel, Elie Morisse, Eric Anholt,
	Florian Fainelli, Frank Rowand, Harald Freudenberger,
	Heikki Krogerus, Heiko Carstens, Heiko Stübner,
	Heiner Kallweit, Inki Dae, Jacek Anaszewski,
	James E.J. Bottomley, Jason Gunthorpe, Jiri Slaby, Joe Perches,
	Joerg Roedel, Lee Jones, Len Brown, Liam Girdwood, linux-acpi,
	linux-fpga, linux-i2c, linux-leds, linux-rockchip, linux-rtc,
	linux-spi, linux-usb, linux-wpan, Maarten Lankhorst, Mark Brown,
	Martin K. Petersen, Mathieu Poirier, Maxime Coquelin,
	Maxime Ripard, Mika Westerberg, Moritz Fischer, Nehal Shah,
	Oliver Neukum, Pavel Machek, Peter Oberparleiter, Peter Rosin,
	Rafael J. Wysocki, Rob Herring, Robin Murphy, Sandy Huang,
	Sebastian Andrzej Siewior, Seung-Woo Kim, Shyam Sundar S K,
	Srinivas Kandagatla, Stefan Schmidt, Takashi Iwai, Thor Thayer,
	Tomas Winkler, Ulf Hansson, Will Deacon, Wolfram Sang

On Tue, Jul 23, 2019 at 11:18:31PM +0100, Suzuki K Poulose wrote:
> We have device iterators to find a particular device matching a criteria
> for a given bus/class/driver. i.e, {bus,class,driver}_find_device()
> APIs. The matching criteria is a function pointer for the APIs. Often the
> lookup is based on a generic property of a device (e.g, name, fwnode, of node
> pointer or device type) rather than a driver specific information. However, each
> driver writes up its own "match" function, spilling the similar match functions
> all over the driver subsystems.
> 
> This series adds device match helpers by generic device properties of a device.
> Using these generic match functions, introduce wrappers to the existing
>  *_find_device() helpers and converts the existing users to use the new wrappers.
>  i.e,
> 	{bus/class/driver}_find_device_by_name()
> 	{bus/class/driver}_find_device_by_fwnode()
> 	{bus/class/driver}_find_device_by_devt()
> 	{bus/class/driver}_find_device_by_acpi_dev()
> 
> Also adds a wrapper for finding a platform device by driver, to avoid
> spilling the platform_bus internals in the individual drivers. Applies
> on 5.3-rc1.
> 
>    [0] git://linux-arm.org/linux-skp.git driver-cleanup/v3
> RFC[1] https://marc.info/?i=1559577023-558-1-git-send-email-suzuki.poulose@arm.com
> V1 [2] https://marc.info/?i=1559747630-28065-1-git-send-email-suzuki.poulose@arm.com
> V2 [3] https://marc.info/?i=1560534863-15115-1-git-send-email-suzuki.poulose@arm.com
> 
> Changes since v2:
>  - Merge the device match helper introduction patch with the variants
>    of the helpers, for better review.
>  - Use platform_find_device_by_driver for mcde drm driver.

This looks good to me at first glance, thanks for doing this work.

I'll wait a few days to collect acks from various subsystem maintainers
before taking the series in my tree.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 1/7] drivers: Introduce device lookup variants by name
  2019-07-23 22:18   ` Suzuki K Poulose
@ 2019-07-25 15:42     ` Alexandre Belloni
  -1 siblings, 0 replies; 71+ messages in thread
From: Alexandre Belloni @ 2019-07-25 15:42 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: linux-kernel, gregkh, rafael, linux-arm-kernel, Alessandro Zummo,
	Alexander Aring, Alexander Shishkin, Arnd Bergmann, Dan Murphy,
	Harald Freudenberger, Heikki Krogerus, Heiko Carstens,
	Jacek Anaszewski, Lee Jones, linux-leds, linux-rtc, linux-usb,
	linux-wpan, Maxime Coquelin, Pavel Machek, Peter Oberparleiter,
	Stefan Schmidt, Rafael J. Wysocki

On 23/07/2019 23:18:32+0100, Suzuki K Poulose wrote:
> Add a helper to match the device name for device lookup. Also
> reuse this generic exported helper for the existing bus_find_device_by_name().
> and add similar variants for driver/class.
> 
> Cc: Alessandro Zummo <a.zummo@towertech.it>
> Cc: Alexander Aring <alex.aring@gmail.com>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Dan Murphy <dmurphy@ti.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Harald Freudenberger <freude@linux.ibm.com>
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
> Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com>
> Cc: Lee Jones <lee.jones@linaro.org>
> Cc: linux-leds@vger.kernel.org
> Cc: linux-rtc@vger.kernel.org
> Cc: linux-usb@vger.kernel.org
> Cc: linux-wpan@vger.kernel.org
> Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
> Cc: Pavel Machek <pavel@ucw.cz>
> Cc: Peter Oberparleiter <oberpar@linux.ibm.com>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Stefan Schmidt <stefan@datenfreihafen.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

> ---
>  drivers/base/bus.c               | 24 ------------------
>  drivers/base/core.c              |  6 +++++
>  drivers/hwtracing/stm/core.c     |  9 +------
>  drivers/leds/led-class.c         |  9 +------
>  drivers/rtc/interface.c          | 11 +--------
>  drivers/s390/cio/ccwgroup.c      | 10 +-------
>  drivers/s390/cio/device.c        | 15 +-----------
>  drivers/s390/crypto/zcrypt_api.c | 11 +--------
>  drivers/usb/roles/class.c        |  8 +-----
>  drivers/usb/typec/class.c        |  8 +-----
>  include/linux/device.h           | 42 +++++++++++++++++++++++++++++---
>  net/ieee802154/core.c            |  7 +-----
>  12 files changed, 54 insertions(+), 106 deletions(-)
> 
> diff --git a/drivers/base/bus.c b/drivers/base/bus.c
> index df3cac739813..a1d1e8256324 100644
> --- a/drivers/base/bus.c
> +++ b/drivers/base/bus.c
> @@ -342,30 +342,6 @@ struct device *bus_find_device(struct bus_type *bus,
>  }
>  EXPORT_SYMBOL_GPL(bus_find_device);
>  
> -static int match_name(struct device *dev, const void *data)
> -{
> -	const char *name = data;
> -
> -	return sysfs_streq(name, dev_name(dev));
> -}
> -
> -/**
> - * bus_find_device_by_name - device iterator for locating a particular device of a specific name
> - * @bus: bus type
> - * @start: Device to begin with
> - * @name: name of the device to match
> - *
> - * This is similar to the bus_find_device() function above, but it handles
> - * searching by a name automatically, no need to write another strcmp matching
> - * function.
> - */
> -struct device *bus_find_device_by_name(struct bus_type *bus,
> -				       struct device *start, const char *name)
> -{
> -	return bus_find_device(bus, start, (void *)name, match_name);
> -}
> -EXPORT_SYMBOL_GPL(bus_find_device_by_name);
> -
>  /**
>   * subsys_find_device_by_id - find a device with a specific enumeration number
>   * @subsys: subsystem
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index da84a73f2ba6..fb83647d685a 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -3357,6 +3357,12 @@ void device_set_of_node_from_dev(struct device *dev, const struct device *dev2)
>  }
>  EXPORT_SYMBOL_GPL(device_set_of_node_from_dev);
>  
> +int device_match_name(struct device *dev, const void *name)
> +{
> +	return sysfs_streq(dev_name(dev), name);
> +}
> +EXPORT_SYMBOL_GPL(device_match_name);
> +
>  int device_match_of_node(struct device *dev, const void *np)
>  {
>  	return dev->of_node == np;
> diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
> index e55b902560de..2b6bd42632e8 100644
> --- a/drivers/hwtracing/stm/core.c
> +++ b/drivers/hwtracing/stm/core.c
> @@ -89,13 +89,6 @@ static struct class stm_class = {
>  	.dev_groups	= stm_groups,
>  };
>  
> -static int stm_dev_match(struct device *dev, const void *data)
> -{
> -	const char *name = data;
> -
> -	return sysfs_streq(name, dev_name(dev));
> -}
> -
>  /**
>   * stm_find_device() - find stm device by name
>   * @buf:	character buffer containing the name
> @@ -116,7 +109,7 @@ struct stm_device *stm_find_device(const char *buf)
>  	if (!stm_core_up)
>  		return NULL;
>  
> -	dev = class_find_device(&stm_class, NULL, buf, stm_dev_match);
> +	dev = class_find_device_by_name(&stm_class, buf);
>  	if (!dev)
>  		return NULL;
>  
> diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
> index 4793e77808e2..d54c8e4d8954 100644
> --- a/drivers/leds/led-class.c
> +++ b/drivers/leds/led-class.c
> @@ -213,13 +213,6 @@ static int led_resume(struct device *dev)
>  
>  static SIMPLE_DEV_PM_OPS(leds_class_dev_pm_ops, led_suspend, led_resume);
>  
> -static int match_name(struct device *dev, const void *data)
> -{
> -	if (!dev_name(dev))
> -		return 0;
> -	return !strcmp(dev_name(dev), (char *)data);
> -}
> -
>  static int led_classdev_next_name(const char *init_name, char *name,
>  				  size_t len)
>  {
> @@ -230,7 +223,7 @@ static int led_classdev_next_name(const char *init_name, char *name,
>  	strlcpy(name, init_name, len);
>  
>  	while ((ret < len) &&
> -	       (dev = class_find_device(leds_class, NULL, name, match_name))) {
> +	       (dev = class_find_device_by_name(leds_class, name))) {
>  		put_device(dev);
>  		ret = snprintf(name, len, "%s_%u", init_name, ++i);
>  	}
> diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
> index 72b7ddc43116..c93ef33b01d3 100644
> --- a/drivers/rtc/interface.c
> +++ b/drivers/rtc/interface.c
> @@ -663,21 +663,12 @@ void rtc_update_irq(struct rtc_device *rtc,
>  }
>  EXPORT_SYMBOL_GPL(rtc_update_irq);
>  
> -static int __rtc_match(struct device *dev, const void *data)
> -{
> -	const char *name = data;
> -
> -	if (strcmp(dev_name(dev), name) == 0)
> -		return 1;
> -	return 0;
> -}
> -
>  struct rtc_device *rtc_class_open(const char *name)
>  {
>  	struct device *dev;
>  	struct rtc_device *rtc = NULL;
>  
> -	dev = class_find_device(rtc_class, NULL, name, __rtc_match);
> +	dev = class_find_device_by_name(rtc_class, name);
>  	if (dev)
>  		rtc = to_rtc_device(dev);
>  
> diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
> index c522e9313c50..d843e362c167 100644
> --- a/drivers/s390/cio/ccwgroup.c
> +++ b/drivers/s390/cio/ccwgroup.c
> @@ -608,13 +608,6 @@ void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver)
>  }
>  EXPORT_SYMBOL(ccwgroup_driver_unregister);
>  
> -static int __ccwgroupdev_check_busid(struct device *dev, const void *id)
> -{
> -	const char *bus_id = id;
> -
> -	return (strcmp(bus_id, dev_name(dev)) == 0);
> -}
> -
>  /**
>   * get_ccwgroupdev_by_busid() - obtain device from a bus id
>   * @gdrv: driver the device is owned by
> @@ -631,8 +624,7 @@ struct ccwgroup_device *get_ccwgroupdev_by_busid(struct ccwgroup_driver *gdrv,
>  {
>  	struct device *dev;
>  
> -	dev = driver_find_device(&gdrv->driver, NULL, bus_id,
> -				 __ccwgroupdev_check_busid);
> +	dev = driver_find_device_by_name(&gdrv->driver, bus_id);
>  
>  	return dev ? to_ccwgroupdev(dev) : NULL;
>  }
> diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
> index c421899be20f..131430bd48d9 100644
> --- a/drivers/s390/cio/device.c
> +++ b/drivers/s390/cio/device.c
> @@ -1695,18 +1695,6 @@ int ccw_device_force_console(struct ccw_device *cdev)
>  EXPORT_SYMBOL_GPL(ccw_device_force_console);
>  #endif
>  
> -/*
> - * get ccw_device matching the busid, but only if owned by cdrv
> - */
> -static int
> -__ccwdev_check_busid(struct device *dev, const void *id)
> -{
> -	const char *bus_id = id;
> -
> -	return (strcmp(bus_id, dev_name(dev)) == 0);
> -}
> -
> -
>  /**
>   * get_ccwdev_by_busid() - obtain device from a bus id
>   * @cdrv: driver the device is owned by
> @@ -1723,8 +1711,7 @@ struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
>  {
>  	struct device *dev;
>  
> -	dev = driver_find_device(&cdrv->driver, NULL, (void *)bus_id,
> -				 __ccwdev_check_busid);
> +	dev = driver_find_device_by_name(&cdrv->driver, bus_id);
>  
>  	return dev ? to_ccwdev(dev) : NULL;
>  }
> diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c
> index 1058b4b5cc1e..38a5a47b8c9c 100644
> --- a/drivers/s390/crypto/zcrypt_api.c
> +++ b/drivers/s390/crypto/zcrypt_api.c
> @@ -133,12 +133,6 @@ struct zcdn_device {
>  static int zcdn_create(const char *name);
>  static int zcdn_destroy(const char *name);
>  
> -/* helper function, matches the name for find_zcdndev_by_name() */
> -static int __match_zcdn_name(struct device *dev, const void *data)
> -{
> -	return strcmp(dev_name(dev), (const char *)data) == 0;
> -}
> -
>  /* helper function, matches the devt value for find_zcdndev_by_devt() */
>  static int __match_zcdn_devt(struct device *dev, const void *data)
>  {
> @@ -152,10 +146,7 @@ static int __match_zcdn_devt(struct device *dev, const void *data)
>   */
>  static inline struct zcdn_device *find_zcdndev_by_name(const char *name)
>  {
> -	struct device *dev =
> -		class_find_device(zcrypt_class, NULL,
> -				  (void *) name,
> -				  __match_zcdn_name);
> +	struct device *dev = class_find_device_by_name(zcrypt_class, name);
>  
>  	return dev ? to_zcdn_dev(dev) : NULL;
>  }
> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
> index 86defca6623e..c8efe60e2465 100644
> --- a/drivers/usb/roles/class.c
> +++ b/drivers/usb/roles/class.c
> @@ -90,11 +90,6 @@ static int switch_fwnode_match(struct device *dev, const void *fwnode)
>  	return dev_fwnode(dev) == fwnode;
>  }
>  
> -static int switch_name_match(struct device *dev, const void *name)
> -{
> -	return !strcmp((const char *)name, dev_name(dev));
> -}
> -
>  static void *usb_role_switch_match(struct device_connection *con, int ep,
>  				   void *data)
>  {
> @@ -107,8 +102,7 @@ static void *usb_role_switch_match(struct device_connection *con, int ep,
>  		dev = class_find_device(role_class, NULL, con->fwnode,
>  					switch_fwnode_match);
>  	} else {
> -		dev = class_find_device(role_class, NULL, con->endpoint[ep],
> -					switch_name_match);
> +		dev = class_find_device_by_name(role_class, con->endpoint[ep]);
>  	}
>  
>  	return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index a18285a990a8..9b0d15b487e5 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -210,11 +210,6 @@ static int typec_port_fwnode_match(struct device *dev, const void *fwnode)
>  	return dev_fwnode(dev) == fwnode;
>  }
>  
> -static int typec_port_name_match(struct device *dev, const void *name)
> -{
> -	return !strcmp((const char *)name, dev_name(dev));
> -}
> -
>  static void *typec_port_match(struct device_connection *con, int ep, void *data)
>  {
>  	struct device *dev;
> @@ -227,8 +222,7 @@ static void *typec_port_match(struct device_connection *con, int ep, void *data)
>  		return class_find_device(typec_class, NULL, con->fwnode,
>  					 typec_port_fwnode_match);
>  
> -	dev = class_find_device(typec_class, NULL, con->endpoint[ep],
> -				typec_port_name_match);
> +	dev = class_find_device_by_name(typec_class, con->endpoint[ep]);
>  
>  	return dev ? dev : ERR_PTR(-EPROBE_DEFER);
>  }
> diff --git a/include/linux/device.h b/include/linux/device.h
> index c330b75c6c57..3ba376b8b456 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -164,6 +164,7 @@ void subsys_dev_iter_init(struct subsys_dev_iter *iter,
>  struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter);
>  void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
>  
> +int device_match_name(struct device *dev, const void *name);
>  int device_match_of_node(struct device *dev, const void *np);
>  
>  int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
> @@ -171,9 +172,20 @@ int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
>  struct device *bus_find_device(struct bus_type *bus, struct device *start,
>  			       const void *data,
>  			       int (*match)(struct device *dev, const void *data));
> -struct device *bus_find_device_by_name(struct bus_type *bus,
> -				       struct device *start,
> -				       const char *name);
> +/**
> + * bus_find_device_by_name - device iterator for locating a particular device
> + * of a specific name.
> + * @bus: bus type
> + * @start: Device to begin with
> + * @name: name of the device to match
> + */
> +static inline struct device *bus_find_device_by_name(struct bus_type *bus,
> +						     struct device *start,
> +						     const char *name)
> +{
> +	return bus_find_device(bus, start, name, device_match_name);
> +}
> +
>  struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
>  					struct device *hint);
>  int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
> @@ -342,6 +354,18 @@ struct device *driver_find_device(struct device_driver *drv,
>  				  struct device *start, const void *data,
>  				  int (*match)(struct device *dev, const void *data));
>  
> +/**
> + * driver_find_device_by_name - device iterator for locating a particular device
> + * of a specific name.
> + * @driver: the driver we're iterating
> + * @name: name of the device to match
> + */
> +static inline struct device *driver_find_device_by_name(struct device_driver *drv,
> +							const char *name)
> +{
> +	return driver_find_device(drv, NULL, name, device_match_name);
> +}
> +
>  void driver_deferred_probe_add(struct device *dev);
>  int driver_deferred_probe_check_state(struct device *dev);
>  int driver_deferred_probe_check_state_continue(struct device *dev);
> @@ -471,6 +495,18 @@ extern struct device *class_find_device(struct class *class,
>  					struct device *start, const void *data,
>  					int (*match)(struct device *, const void *));
>  
> +/**
> + * class_find_device_by_name - device iterator for locating a particular device
> + * of a specific name.
> + * @class: class type
> + * @name: name of the device to match
> + */
> +static inline struct device *class_find_device_by_name(struct class *class,
> +						       const char *name)
> +{
> +	return class_find_device(class, NULL, name, device_match_name);
> +}
> +
>  struct class_attribute {
>  	struct attribute attr;
>  	ssize_t (*show)(struct class *class, struct class_attribute *attr,
> diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
> index 60b7ac56a1f5..de259b5170ab 100644
> --- a/net/ieee802154/core.c
> +++ b/net/ieee802154/core.c
> @@ -23,11 +23,6 @@
>  LIST_HEAD(cfg802154_rdev_list);
>  int cfg802154_rdev_list_generation;
>  
> -static int wpan_phy_match(struct device *dev, const void *data)
> -{
> -	return !strcmp(dev_name(dev), (const char *)data);
> -}
> -
>  struct wpan_phy *wpan_phy_find(const char *str)
>  {
>  	struct device *dev;
> @@ -35,7 +30,7 @@ struct wpan_phy *wpan_phy_find(const char *str)
>  	if (WARN_ON(!str))
>  		return NULL;
>  
> -	dev = class_find_device(&wpan_phy_class, NULL, str, wpan_phy_match);
> +	dev = class_find_device_by_name(&wpan_phy_class, str);
>  	if (!dev)
>  		return NULL;
>  
> -- 
> 2.21.0
> 

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 1/7] drivers: Introduce device lookup variants by name
@ 2019-07-25 15:42     ` Alexandre Belloni
  0 siblings, 0 replies; 71+ messages in thread
From: Alexandre Belloni @ 2019-07-25 15:42 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Alexander Aring, Heikki Krogerus, rafael, Alexander Shishkin,
	Heiko Carstens, Peter Oberparleiter, Pavel Machek, Lee Jones,
	linux-leds, linux-rtc, Rafael J. Wysocki, Stefan Schmidt,
	Arnd Bergmann, Harald Freudenberger, Dan Murphy,
	linux-arm-kernel, Alessandro Zummo, gregkh, linux-usb,
	linux-kernel, Maxime Coquelin, linux-wpan, Jacek Anaszewski

On 23/07/2019 23:18:32+0100, Suzuki K Poulose wrote:
> Add a helper to match the device name for device lookup. Also
> reuse this generic exported helper for the existing bus_find_device_by_name().
> and add similar variants for driver/class.
> 
> Cc: Alessandro Zummo <a.zummo@towertech.it>
> Cc: Alexander Aring <alex.aring@gmail.com>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Dan Murphy <dmurphy@ti.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Harald Freudenberger <freude@linux.ibm.com>
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
> Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com>
> Cc: Lee Jones <lee.jones@linaro.org>
> Cc: linux-leds@vger.kernel.org
> Cc: linux-rtc@vger.kernel.org
> Cc: linux-usb@vger.kernel.org
> Cc: linux-wpan@vger.kernel.org
> Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
> Cc: Pavel Machek <pavel@ucw.cz>
> Cc: Peter Oberparleiter <oberpar@linux.ibm.com>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Stefan Schmidt <stefan@datenfreihafen.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

> ---
>  drivers/base/bus.c               | 24 ------------------
>  drivers/base/core.c              |  6 +++++
>  drivers/hwtracing/stm/core.c     |  9 +------
>  drivers/leds/led-class.c         |  9 +------
>  drivers/rtc/interface.c          | 11 +--------
>  drivers/s390/cio/ccwgroup.c      | 10 +-------
>  drivers/s390/cio/device.c        | 15 +-----------
>  drivers/s390/crypto/zcrypt_api.c | 11 +--------
>  drivers/usb/roles/class.c        |  8 +-----
>  drivers/usb/typec/class.c        |  8 +-----
>  include/linux/device.h           | 42 +++++++++++++++++++++++++++++---
>  net/ieee802154/core.c            |  7 +-----
>  12 files changed, 54 insertions(+), 106 deletions(-)
> 
> diff --git a/drivers/base/bus.c b/drivers/base/bus.c
> index df3cac739813..a1d1e8256324 100644
> --- a/drivers/base/bus.c
> +++ b/drivers/base/bus.c
> @@ -342,30 +342,6 @@ struct device *bus_find_device(struct bus_type *bus,
>  }
>  EXPORT_SYMBOL_GPL(bus_find_device);
>  
> -static int match_name(struct device *dev, const void *data)
> -{
> -	const char *name = data;
> -
> -	return sysfs_streq(name, dev_name(dev));
> -}
> -
> -/**
> - * bus_find_device_by_name - device iterator for locating a particular device of a specific name
> - * @bus: bus type
> - * @start: Device to begin with
> - * @name: name of the device to match
> - *
> - * This is similar to the bus_find_device() function above, but it handles
> - * searching by a name automatically, no need to write another strcmp matching
> - * function.
> - */
> -struct device *bus_find_device_by_name(struct bus_type *bus,
> -				       struct device *start, const char *name)
> -{
> -	return bus_find_device(bus, start, (void *)name, match_name);
> -}
> -EXPORT_SYMBOL_GPL(bus_find_device_by_name);
> -
>  /**
>   * subsys_find_device_by_id - find a device with a specific enumeration number
>   * @subsys: subsystem
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index da84a73f2ba6..fb83647d685a 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -3357,6 +3357,12 @@ void device_set_of_node_from_dev(struct device *dev, const struct device *dev2)
>  }
>  EXPORT_SYMBOL_GPL(device_set_of_node_from_dev);
>  
> +int device_match_name(struct device *dev, const void *name)
> +{
> +	return sysfs_streq(dev_name(dev), name);
> +}
> +EXPORT_SYMBOL_GPL(device_match_name);
> +
>  int device_match_of_node(struct device *dev, const void *np)
>  {
>  	return dev->of_node == np;
> diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
> index e55b902560de..2b6bd42632e8 100644
> --- a/drivers/hwtracing/stm/core.c
> +++ b/drivers/hwtracing/stm/core.c
> @@ -89,13 +89,6 @@ static struct class stm_class = {
>  	.dev_groups	= stm_groups,
>  };
>  
> -static int stm_dev_match(struct device *dev, const void *data)
> -{
> -	const char *name = data;
> -
> -	return sysfs_streq(name, dev_name(dev));
> -}
> -
>  /**
>   * stm_find_device() - find stm device by name
>   * @buf:	character buffer containing the name
> @@ -116,7 +109,7 @@ struct stm_device *stm_find_device(const char *buf)
>  	if (!stm_core_up)
>  		return NULL;
>  
> -	dev = class_find_device(&stm_class, NULL, buf, stm_dev_match);
> +	dev = class_find_device_by_name(&stm_class, buf);
>  	if (!dev)
>  		return NULL;
>  
> diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
> index 4793e77808e2..d54c8e4d8954 100644
> --- a/drivers/leds/led-class.c
> +++ b/drivers/leds/led-class.c
> @@ -213,13 +213,6 @@ static int led_resume(struct device *dev)
>  
>  static SIMPLE_DEV_PM_OPS(leds_class_dev_pm_ops, led_suspend, led_resume);
>  
> -static int match_name(struct device *dev, const void *data)
> -{
> -	if (!dev_name(dev))
> -		return 0;
> -	return !strcmp(dev_name(dev), (char *)data);
> -}
> -
>  static int led_classdev_next_name(const char *init_name, char *name,
>  				  size_t len)
>  {
> @@ -230,7 +223,7 @@ static int led_classdev_next_name(const char *init_name, char *name,
>  	strlcpy(name, init_name, len);
>  
>  	while ((ret < len) &&
> -	       (dev = class_find_device(leds_class, NULL, name, match_name))) {
> +	       (dev = class_find_device_by_name(leds_class, name))) {
>  		put_device(dev);
>  		ret = snprintf(name, len, "%s_%u", init_name, ++i);
>  	}
> diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
> index 72b7ddc43116..c93ef33b01d3 100644
> --- a/drivers/rtc/interface.c
> +++ b/drivers/rtc/interface.c
> @@ -663,21 +663,12 @@ void rtc_update_irq(struct rtc_device *rtc,
>  }
>  EXPORT_SYMBOL_GPL(rtc_update_irq);
>  
> -static int __rtc_match(struct device *dev, const void *data)
> -{
> -	const char *name = data;
> -
> -	if (strcmp(dev_name(dev), name) == 0)
> -		return 1;
> -	return 0;
> -}
> -
>  struct rtc_device *rtc_class_open(const char *name)
>  {
>  	struct device *dev;
>  	struct rtc_device *rtc = NULL;
>  
> -	dev = class_find_device(rtc_class, NULL, name, __rtc_match);
> +	dev = class_find_device_by_name(rtc_class, name);
>  	if (dev)
>  		rtc = to_rtc_device(dev);
>  
> diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
> index c522e9313c50..d843e362c167 100644
> --- a/drivers/s390/cio/ccwgroup.c
> +++ b/drivers/s390/cio/ccwgroup.c
> @@ -608,13 +608,6 @@ void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver)
>  }
>  EXPORT_SYMBOL(ccwgroup_driver_unregister);
>  
> -static int __ccwgroupdev_check_busid(struct device *dev, const void *id)
> -{
> -	const char *bus_id = id;
> -
> -	return (strcmp(bus_id, dev_name(dev)) == 0);
> -}
> -
>  /**
>   * get_ccwgroupdev_by_busid() - obtain device from a bus id
>   * @gdrv: driver the device is owned by
> @@ -631,8 +624,7 @@ struct ccwgroup_device *get_ccwgroupdev_by_busid(struct ccwgroup_driver *gdrv,
>  {
>  	struct device *dev;
>  
> -	dev = driver_find_device(&gdrv->driver, NULL, bus_id,
> -				 __ccwgroupdev_check_busid);
> +	dev = driver_find_device_by_name(&gdrv->driver, bus_id);
>  
>  	return dev ? to_ccwgroupdev(dev) : NULL;
>  }
> diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
> index c421899be20f..131430bd48d9 100644
> --- a/drivers/s390/cio/device.c
> +++ b/drivers/s390/cio/device.c
> @@ -1695,18 +1695,6 @@ int ccw_device_force_console(struct ccw_device *cdev)
>  EXPORT_SYMBOL_GPL(ccw_device_force_console);
>  #endif
>  
> -/*
> - * get ccw_device matching the busid, but only if owned by cdrv
> - */
> -static int
> -__ccwdev_check_busid(struct device *dev, const void *id)
> -{
> -	const char *bus_id = id;
> -
> -	return (strcmp(bus_id, dev_name(dev)) == 0);
> -}
> -
> -
>  /**
>   * get_ccwdev_by_busid() - obtain device from a bus id
>   * @cdrv: driver the device is owned by
> @@ -1723,8 +1711,7 @@ struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
>  {
>  	struct device *dev;
>  
> -	dev = driver_find_device(&cdrv->driver, NULL, (void *)bus_id,
> -				 __ccwdev_check_busid);
> +	dev = driver_find_device_by_name(&cdrv->driver, bus_id);
>  
>  	return dev ? to_ccwdev(dev) : NULL;
>  }
> diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c
> index 1058b4b5cc1e..38a5a47b8c9c 100644
> --- a/drivers/s390/crypto/zcrypt_api.c
> +++ b/drivers/s390/crypto/zcrypt_api.c
> @@ -133,12 +133,6 @@ struct zcdn_device {
>  static int zcdn_create(const char *name);
>  static int zcdn_destroy(const char *name);
>  
> -/* helper function, matches the name for find_zcdndev_by_name() */
> -static int __match_zcdn_name(struct device *dev, const void *data)
> -{
> -	return strcmp(dev_name(dev), (const char *)data) == 0;
> -}
> -
>  /* helper function, matches the devt value for find_zcdndev_by_devt() */
>  static int __match_zcdn_devt(struct device *dev, const void *data)
>  {
> @@ -152,10 +146,7 @@ static int __match_zcdn_devt(struct device *dev, const void *data)
>   */
>  static inline struct zcdn_device *find_zcdndev_by_name(const char *name)
>  {
> -	struct device *dev =
> -		class_find_device(zcrypt_class, NULL,
> -				  (void *) name,
> -				  __match_zcdn_name);
> +	struct device *dev = class_find_device_by_name(zcrypt_class, name);
>  
>  	return dev ? to_zcdn_dev(dev) : NULL;
>  }
> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
> index 86defca6623e..c8efe60e2465 100644
> --- a/drivers/usb/roles/class.c
> +++ b/drivers/usb/roles/class.c
> @@ -90,11 +90,6 @@ static int switch_fwnode_match(struct device *dev, const void *fwnode)
>  	return dev_fwnode(dev) == fwnode;
>  }
>  
> -static int switch_name_match(struct device *dev, const void *name)
> -{
> -	return !strcmp((const char *)name, dev_name(dev));
> -}
> -
>  static void *usb_role_switch_match(struct device_connection *con, int ep,
>  				   void *data)
>  {
> @@ -107,8 +102,7 @@ static void *usb_role_switch_match(struct device_connection *con, int ep,
>  		dev = class_find_device(role_class, NULL, con->fwnode,
>  					switch_fwnode_match);
>  	} else {
> -		dev = class_find_device(role_class, NULL, con->endpoint[ep],
> -					switch_name_match);
> +		dev = class_find_device_by_name(role_class, con->endpoint[ep]);
>  	}
>  
>  	return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index a18285a990a8..9b0d15b487e5 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -210,11 +210,6 @@ static int typec_port_fwnode_match(struct device *dev, const void *fwnode)
>  	return dev_fwnode(dev) == fwnode;
>  }
>  
> -static int typec_port_name_match(struct device *dev, const void *name)
> -{
> -	return !strcmp((const char *)name, dev_name(dev));
> -}
> -
>  static void *typec_port_match(struct device_connection *con, int ep, void *data)
>  {
>  	struct device *dev;
> @@ -227,8 +222,7 @@ static void *typec_port_match(struct device_connection *con, int ep, void *data)
>  		return class_find_device(typec_class, NULL, con->fwnode,
>  					 typec_port_fwnode_match);
>  
> -	dev = class_find_device(typec_class, NULL, con->endpoint[ep],
> -				typec_port_name_match);
> +	dev = class_find_device_by_name(typec_class, con->endpoint[ep]);
>  
>  	return dev ? dev : ERR_PTR(-EPROBE_DEFER);
>  }
> diff --git a/include/linux/device.h b/include/linux/device.h
> index c330b75c6c57..3ba376b8b456 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -164,6 +164,7 @@ void subsys_dev_iter_init(struct subsys_dev_iter *iter,
>  struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter);
>  void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
>  
> +int device_match_name(struct device *dev, const void *name);
>  int device_match_of_node(struct device *dev, const void *np);
>  
>  int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
> @@ -171,9 +172,20 @@ int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
>  struct device *bus_find_device(struct bus_type *bus, struct device *start,
>  			       const void *data,
>  			       int (*match)(struct device *dev, const void *data));
> -struct device *bus_find_device_by_name(struct bus_type *bus,
> -				       struct device *start,
> -				       const char *name);
> +/**
> + * bus_find_device_by_name - device iterator for locating a particular device
> + * of a specific name.
> + * @bus: bus type
> + * @start: Device to begin with
> + * @name: name of the device to match
> + */
> +static inline struct device *bus_find_device_by_name(struct bus_type *bus,
> +						     struct device *start,
> +						     const char *name)
> +{
> +	return bus_find_device(bus, start, name, device_match_name);
> +}
> +
>  struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
>  					struct device *hint);
>  int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
> @@ -342,6 +354,18 @@ struct device *driver_find_device(struct device_driver *drv,
>  				  struct device *start, const void *data,
>  				  int (*match)(struct device *dev, const void *data));
>  
> +/**
> + * driver_find_device_by_name - device iterator for locating a particular device
> + * of a specific name.
> + * @driver: the driver we're iterating
> + * @name: name of the device to match
> + */
> +static inline struct device *driver_find_device_by_name(struct device_driver *drv,
> +							const char *name)
> +{
> +	return driver_find_device(drv, NULL, name, device_match_name);
> +}
> +
>  void driver_deferred_probe_add(struct device *dev);
>  int driver_deferred_probe_check_state(struct device *dev);
>  int driver_deferred_probe_check_state_continue(struct device *dev);
> @@ -471,6 +495,18 @@ extern struct device *class_find_device(struct class *class,
>  					struct device *start, const void *data,
>  					int (*match)(struct device *, const void *));
>  
> +/**
> + * class_find_device_by_name - device iterator for locating a particular device
> + * of a specific name.
> + * @class: class type
> + * @name: name of the device to match
> + */
> +static inline struct device *class_find_device_by_name(struct class *class,
> +						       const char *name)
> +{
> +	return class_find_device(class, NULL, name, device_match_name);
> +}
> +
>  struct class_attribute {
>  	struct attribute attr;
>  	ssize_t (*show)(struct class *class, struct class_attribute *attr,
> diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
> index 60b7ac56a1f5..de259b5170ab 100644
> --- a/net/ieee802154/core.c
> +++ b/net/ieee802154/core.c
> @@ -23,11 +23,6 @@
>  LIST_HEAD(cfg802154_rdev_list);
>  int cfg802154_rdev_list_generation;
>  
> -static int wpan_phy_match(struct device *dev, const void *data)
> -{
> -	return !strcmp(dev_name(dev), (const char *)data);
> -}
> -
>  struct wpan_phy *wpan_phy_find(const char *str)
>  {
>  	struct device *dev;
> @@ -35,7 +30,7 @@ struct wpan_phy *wpan_phy_find(const char *str)
>  	if (WARN_ON(!str))
>  		return NULL;
>  
> -	dev = class_find_device(&wpan_phy_class, NULL, str, wpan_phy_match);
> +	dev = class_find_device_by_name(&wpan_phy_class, str);
>  	if (!dev)
>  		return NULL;
>  
> -- 
> 2.21.0
> 

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 3/7] drivers: Introduce device lookup variants by fwnode
  2019-07-23 22:18   ` Suzuki K Poulose
@ 2019-07-25 17:10     ` Mathieu Poirier
  -1 siblings, 0 replies; 71+ messages in thread
From: Mathieu Poirier @ 2019-07-25 17:10 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: linux-kernel, gregkh, rafael, linux-arm-kernel, David S. Miller,
	Doug Ledford, Heikki Krogerus, Jason Gunthorpe, linux-usb,
	Ulf Hansson, Joe Perches, Will Deacon, Robin Murphy,
	Joerg Roedel

On Tue, Jul 23, 2019 at 11:18:34PM +0100, Suzuki K Poulose wrote:
> Add a helper to match the firmware node handle of a device and provide
> wrappers for {bus/class/driver}_find_device() APIs to avoid proliferation
> of duplicate custom match functions.
> 
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Doug Ledford <dledford@redhat.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: linux-usb@vger.kernel.org
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: Joe Perches <joe@perches.com>
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Joerg Roedel <joro@8bytes.org>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>  drivers/base/core.c                           |  6 +++
>  drivers/base/devcon.c                         |  8 +---

>  .../hwtracing/coresight/coresight-platform.c  | 11 +-----
>  drivers/hwtracing/coresight/coresight-priv.h  |  2 -
>  drivers/hwtracing/coresight/coresight.c       |  4 +-

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

>  drivers/infiniband/hw/hns/hns_roce_hw_v1.c    |  8 +---
>  drivers/iommu/arm-smmu-v3.c                   |  9 +----
>  drivers/iommu/arm-smmu.c                      |  9 +----
>  .../ethernet/hisilicon/hns/hns_dsaf_misc.c    |  8 +---
>  drivers/usb/roles/class.c                     |  8 +---
>  drivers/usb/typec/class.c                     |  8 +---
>  include/linux/device.h                        | 39 +++++++++++++++++++
>  12 files changed, 57 insertions(+), 63 deletions(-)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index fb83647d685a..e8f81a667545 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -3368,3 +3368,9 @@ int device_match_of_node(struct device *dev, const void *np)
>  	return dev->of_node == np;
>  }
>  EXPORT_SYMBOL_GPL(device_match_of_node);
> +
> +int device_match_fwnode(struct device *dev, const void *fwnode)
> +{
> +	return dev_fwnode(dev) == fwnode;
> +}
> +EXPORT_SYMBOL_GPL(device_match_fwnode);
> diff --git a/drivers/base/devcon.c b/drivers/base/devcon.c
> index 09f28479b243..1d488dc5dd0c 100644
> --- a/drivers/base/devcon.c
> +++ b/drivers/base/devcon.c
> @@ -133,19 +133,13 @@ static struct bus_type *generic_match_buses[] = {
>  	NULL,
>  };
>  
> -static int device_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>  static void *device_connection_fwnode_match(struct device_connection *con)
>  {
>  	struct bus_type *bus;
>  	struct device *dev;
>  
>  	for (bus = generic_match_buses[0]; bus; bus++) {
> -		dev = bus_find_device(bus, NULL, (void *)con->fwnode,
> -				      device_fwnode_match);
> +		dev = bus_find_device_by_fwnode(bus, con->fwnode);
>  		if (dev && !strncmp(dev_name(dev), con->id, strlen(con->id)))
>  			return dev;
>  
> diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
> index dad7d96c5943..3c5bee429105 100644
> --- a/drivers/hwtracing/coresight/coresight-platform.c
> +++ b/drivers/hwtracing/coresight/coresight-platform.c
> @@ -37,11 +37,6 @@ static int coresight_alloc_conns(struct device *dev,
>  	return 0;
>  }
>  
> -int coresight_device_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>  static struct device *
>  coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
>  {
> @@ -51,8 +46,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
>  	 * If we have a non-configurable replicator, it will be found on the
>  	 * platform bus.
>  	 */
> -	dev = bus_find_device(&platform_bus_type, NULL,
> -			      fwnode, coresight_device_fwnode_match);
> +	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
>  	if (dev)
>  		return dev;
>  
> @@ -60,8 +54,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
>  	 * We have a configurable component - circle through the AMBA bus
>  	 * looking for the device that matches the endpoint node.
>  	 */
> -	return bus_find_device(&amba_bustype, NULL,
> -			       fwnode, coresight_device_fwnode_match);
> +	return bus_find_device_by_fwnode(&amba_bustype, fwnode);
>  }
>  
>  #ifdef CONFIG_OF
> diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
> index 7d401790dd7e..61d7f9ff054d 100644
> --- a/drivers/hwtracing/coresight/coresight-priv.h
> +++ b/drivers/hwtracing/coresight/coresight-priv.h
> @@ -202,6 +202,4 @@ static inline void *coresight_get_uci_data(const struct amba_id *id)
>  
>  void coresight_release_platform_data(struct coresight_platform_data *pdata);
>  
> -int coresight_device_fwnode_match(struct device *dev, const void *fwnode);
> -
>  #endif
> diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
> index 55db77f6410b..6453c67a4d01 100644
> --- a/drivers/hwtracing/coresight/coresight.c
> +++ b/drivers/hwtracing/coresight/coresight.c
> @@ -1046,9 +1046,7 @@ static void coresight_fixup_device_conns(struct coresight_device *csdev)
>  		struct coresight_connection *conn = &csdev->pdata->conns[i];
>  		struct device *dev = NULL;
>  
> -		dev = bus_find_device(&coresight_bustype, NULL,
> -				      (void *)conn->child_fwnode,
> -				      coresight_device_fwnode_match);
> +		dev = bus_find_device_by_fwnode(&coresight_bustype, conn->child_fwnode);
>  		if (dev) {
>  			conn->child_dev = to_coresight_device(dev);
>  			/* and put reference from 'bus_find_device()' */
> diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> index 81e6dedb1e02..fa05e943038a 100644
> --- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> @@ -4499,19 +4499,13 @@ static const struct acpi_device_id hns_roce_acpi_match[] = {
>  };
>  MODULE_DEVICE_TABLE(acpi, hns_roce_acpi_match);
>  
> -static int hns_roce_node_match(struct device *dev, const void *fwnode)
> -{
> -	return dev->fwnode == fwnode;
> -}
> -
>  static struct
>  platform_device *hns_roce_find_pdev(struct fwnode_handle *fwnode)
>  {
>  	struct device *dev;
>  
>  	/* get the 'device' corresponding to the matching 'fwnode' */
> -	dev = bus_find_device(&platform_bus_type, NULL,
> -			      fwnode, hns_roce_node_match);
> +	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
>  	/* get the platform device */
>  	return dev ? to_platform_device(dev) : NULL;
>  }
> diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c
> index a9a9fabd3968..6f0e13fa5e1a 100644
> --- a/drivers/iommu/arm-smmu-v3.c
> +++ b/drivers/iommu/arm-smmu-v3.c
> @@ -2034,16 +2034,11 @@ arm_smmu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova)
>  
>  static struct platform_driver arm_smmu_driver;
>  
> -static int arm_smmu_match_node(struct device *dev, const void *data)
> -{
> -	return dev->fwnode == data;
> -}
> -
>  static
>  struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
>  {
> -	struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL,
> -						fwnode, arm_smmu_match_node);
> +	struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver,
> +							  fwnode);
>  	put_device(dev);
>  	return dev ? dev_get_drvdata(dev) : NULL;
>  }
> diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
> index 64977c131ee6..aa06498f291d 100644
> --- a/drivers/iommu/arm-smmu.c
> +++ b/drivers/iommu/arm-smmu.c
> @@ -1426,16 +1426,11 @@ static bool arm_smmu_capable(enum iommu_cap cap)
>  	}
>  }
>  
> -static int arm_smmu_match_node(struct device *dev, const void *data)
> -{
> -	return dev->fwnode == data;
> -}
> -
>  static
>  struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
>  {
> -	struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL,
> -						fwnode, arm_smmu_match_node);
> +	struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver,
> +							  fwnode);
>  	put_device(dev);
>  	return dev ? dev_get_drvdata(dev) : NULL;
>  }
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
> index bb6586d0e5af..ed3829ae4ef1 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
> @@ -754,17 +754,11 @@ struct dsaf_misc_op *hns_misc_op_get(struct dsaf_device *dsaf_dev)
>  	return (void *)misc_op;
>  }
>  
> -static int hns_dsaf_dev_match(struct device *dev, const void *fwnode)
> -{
> -	return dev->fwnode == fwnode;
> -}
> -
>  struct
>  platform_device *hns_dsaf_find_platform_device(struct fwnode_handle *fwnode)
>  {
>  	struct device *dev;
>  
> -	dev = bus_find_device(&platform_bus_type, NULL,
> -			      fwnode, hns_dsaf_dev_match);
> +	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
>  	return dev ? to_platform_device(dev) : NULL;
>  }
> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
> index c8efe60e2465..0526efbc4922 100644
> --- a/drivers/usb/roles/class.c
> +++ b/drivers/usb/roles/class.c
> @@ -85,11 +85,6 @@ enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw)
>  }
>  EXPORT_SYMBOL_GPL(usb_role_switch_get_role);
>  
> -static int switch_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>  static void *usb_role_switch_match(struct device_connection *con, int ep,
>  				   void *data)
>  {
> @@ -99,8 +94,7 @@ static void *usb_role_switch_match(struct device_connection *con, int ep,
>  		if (con->id && !fwnode_property_present(con->fwnode, con->id))
>  			return NULL;
>  
> -		dev = class_find_device(role_class, NULL, con->fwnode,
> -					switch_fwnode_match);
> +		dev = class_find_device_by_fwnode(role_class, con->fwnode);
>  	} else {
>  		dev = class_find_device_by_name(role_class, con->endpoint[ep]);
>  	}
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 9b0d15b487e5..94a3eda62add 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -205,11 +205,6 @@ static void typec_altmode_put_partner(struct altmode *altmode)
>  	put_device(&adev->dev);
>  }
>  
> -static int typec_port_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>  static void *typec_port_match(struct device_connection *con, int ep, void *data)
>  {
>  	struct device *dev;
> @@ -219,8 +214,7 @@ static void *typec_port_match(struct device_connection *con, int ep, void *data)
>  	 * we need to return ERR_PTR(-PROBE_DEFER) when there is no device.
>  	 */
>  	if (con->fwnode)
> -		return class_find_device(typec_class, NULL, con->fwnode,
> -					 typec_port_fwnode_match);
> +		return class_find_device_by_fwnode(typec_class, con->fwnode);
>  
>  	dev = class_find_device_by_name(typec_class, con->endpoint[ep]);
>  
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 29d8d7ad41e6..7133fc1c285d 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -166,6 +166,7 @@ void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
>  
>  int device_match_name(struct device *dev, const void *name);
>  int device_match_of_node(struct device *dev, const void *np);
> +int device_match_fwnode(struct device *dev, const void *fwnode);
>  
>  int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
>  		     int (*fn)(struct device *dev, void *data));
> @@ -198,6 +199,18 @@ bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
>  	return bus_find_device(bus, NULL, np, device_match_of_node);
>  }
>  
> +/**
> + * bus_find_device_by_fwnode : device iterator for locating a particular device
> + * matching the fwnode.
> + * @bus: bus type
> + * @fwnode: fwnode of the device to match.
> + */
> +static inline struct device *
> +bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwnode)
> +{
> +	return bus_find_device(bus, NULL, fwnode, device_match_fwnode);
> +}
> +
>  struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
>  					struct device *hint);
>  int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
> @@ -391,6 +404,19 @@ driver_find_device_by_of_node(struct device_driver *drv,
>  	return driver_find_device(drv, NULL, np, device_match_of_node);
>  }
>  
> +/**
> + * driver_find_device_by_fwnode- device iterator for locating a particular device
> + * by fwnode pointer.
> + * @driver: the driver we're iterating
> + * @fwnode: fwnode pointer to match.
> + */
> +static inline struct device *
> +driver_find_device_by_fwnode(struct device_driver *drv,
> +			     const struct fwnode_handle *fwnode)
> +{
> +	return driver_find_device(drv, NULL, fwnode, device_match_fwnode);
> +}
> +
>  void driver_deferred_probe_add(struct device *dev);
>  int driver_deferred_probe_check_state(struct device *dev);
>  int driver_deferred_probe_check_state_continue(struct device *dev);
> @@ -544,6 +570,19 @@ class_find_device_by_of_node(struct class *class, const struct device_node *np)
>  	return class_find_device(class, NULL, np, device_match_of_node);
>  }
>  
> +/**
> + * class_find_device_by_fwnode : device iterator for locating a particular device
> + * matching the fwnode.
> + * @class: class type
> + * @fwnode: fwnode of the device to match.
> + */
> +static inline struct device *
> +class_find_device_by_fwnode(struct class *class,
> +			    const struct fwnode_handle *fwnode)
> +{
> +	return class_find_device(class, NULL, fwnode, device_match_fwnode);
> +}
> +
>  struct class_attribute {
>  	struct attribute attr;
>  	ssize_t (*show)(struct class *class, struct class_attribute *attr,
> -- 
> 2.21.0
> 

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 3/7] drivers: Introduce device lookup variants by fwnode
@ 2019-07-25 17:10     ` Mathieu Poirier
  0 siblings, 0 replies; 71+ messages in thread
From: Mathieu Poirier @ 2019-07-25 17:10 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Ulf Hansson, Heikki Krogerus, rafael, gregkh, Joerg Roedel,
	linux-usb, Will Deacon, linux-kernel, Jason Gunthorpe,
	Doug Ledford, Joe Perches, Robin Murphy, David S. Miller,
	linux-arm-kernel

On Tue, Jul 23, 2019 at 11:18:34PM +0100, Suzuki K Poulose wrote:
> Add a helper to match the firmware node handle of a device and provide
> wrappers for {bus/class/driver}_find_device() APIs to avoid proliferation
> of duplicate custom match functions.
> 
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Doug Ledford <dledford@redhat.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: linux-usb@vger.kernel.org
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: Joe Perches <joe@perches.com>
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Joerg Roedel <joro@8bytes.org>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>  drivers/base/core.c                           |  6 +++
>  drivers/base/devcon.c                         |  8 +---

>  .../hwtracing/coresight/coresight-platform.c  | 11 +-----
>  drivers/hwtracing/coresight/coresight-priv.h  |  2 -
>  drivers/hwtracing/coresight/coresight.c       |  4 +-

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

>  drivers/infiniband/hw/hns/hns_roce_hw_v1.c    |  8 +---
>  drivers/iommu/arm-smmu-v3.c                   |  9 +----
>  drivers/iommu/arm-smmu.c                      |  9 +----
>  .../ethernet/hisilicon/hns/hns_dsaf_misc.c    |  8 +---
>  drivers/usb/roles/class.c                     |  8 +---
>  drivers/usb/typec/class.c                     |  8 +---
>  include/linux/device.h                        | 39 +++++++++++++++++++
>  12 files changed, 57 insertions(+), 63 deletions(-)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index fb83647d685a..e8f81a667545 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -3368,3 +3368,9 @@ int device_match_of_node(struct device *dev, const void *np)
>  	return dev->of_node == np;
>  }
>  EXPORT_SYMBOL_GPL(device_match_of_node);
> +
> +int device_match_fwnode(struct device *dev, const void *fwnode)
> +{
> +	return dev_fwnode(dev) == fwnode;
> +}
> +EXPORT_SYMBOL_GPL(device_match_fwnode);
> diff --git a/drivers/base/devcon.c b/drivers/base/devcon.c
> index 09f28479b243..1d488dc5dd0c 100644
> --- a/drivers/base/devcon.c
> +++ b/drivers/base/devcon.c
> @@ -133,19 +133,13 @@ static struct bus_type *generic_match_buses[] = {
>  	NULL,
>  };
>  
> -static int device_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>  static void *device_connection_fwnode_match(struct device_connection *con)
>  {
>  	struct bus_type *bus;
>  	struct device *dev;
>  
>  	for (bus = generic_match_buses[0]; bus; bus++) {
> -		dev = bus_find_device(bus, NULL, (void *)con->fwnode,
> -				      device_fwnode_match);
> +		dev = bus_find_device_by_fwnode(bus, con->fwnode);
>  		if (dev && !strncmp(dev_name(dev), con->id, strlen(con->id)))
>  			return dev;
>  
> diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
> index dad7d96c5943..3c5bee429105 100644
> --- a/drivers/hwtracing/coresight/coresight-platform.c
> +++ b/drivers/hwtracing/coresight/coresight-platform.c
> @@ -37,11 +37,6 @@ static int coresight_alloc_conns(struct device *dev,
>  	return 0;
>  }
>  
> -int coresight_device_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>  static struct device *
>  coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
>  {
> @@ -51,8 +46,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
>  	 * If we have a non-configurable replicator, it will be found on the
>  	 * platform bus.
>  	 */
> -	dev = bus_find_device(&platform_bus_type, NULL,
> -			      fwnode, coresight_device_fwnode_match);
> +	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
>  	if (dev)
>  		return dev;
>  
> @@ -60,8 +54,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
>  	 * We have a configurable component - circle through the AMBA bus
>  	 * looking for the device that matches the endpoint node.
>  	 */
> -	return bus_find_device(&amba_bustype, NULL,
> -			       fwnode, coresight_device_fwnode_match);
> +	return bus_find_device_by_fwnode(&amba_bustype, fwnode);
>  }
>  
>  #ifdef CONFIG_OF
> diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
> index 7d401790dd7e..61d7f9ff054d 100644
> --- a/drivers/hwtracing/coresight/coresight-priv.h
> +++ b/drivers/hwtracing/coresight/coresight-priv.h
> @@ -202,6 +202,4 @@ static inline void *coresight_get_uci_data(const struct amba_id *id)
>  
>  void coresight_release_platform_data(struct coresight_platform_data *pdata);
>  
> -int coresight_device_fwnode_match(struct device *dev, const void *fwnode);
> -
>  #endif
> diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
> index 55db77f6410b..6453c67a4d01 100644
> --- a/drivers/hwtracing/coresight/coresight.c
> +++ b/drivers/hwtracing/coresight/coresight.c
> @@ -1046,9 +1046,7 @@ static void coresight_fixup_device_conns(struct coresight_device *csdev)
>  		struct coresight_connection *conn = &csdev->pdata->conns[i];
>  		struct device *dev = NULL;
>  
> -		dev = bus_find_device(&coresight_bustype, NULL,
> -				      (void *)conn->child_fwnode,
> -				      coresight_device_fwnode_match);
> +		dev = bus_find_device_by_fwnode(&coresight_bustype, conn->child_fwnode);
>  		if (dev) {
>  			conn->child_dev = to_coresight_device(dev);
>  			/* and put reference from 'bus_find_device()' */
> diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> index 81e6dedb1e02..fa05e943038a 100644
> --- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> @@ -4499,19 +4499,13 @@ static const struct acpi_device_id hns_roce_acpi_match[] = {
>  };
>  MODULE_DEVICE_TABLE(acpi, hns_roce_acpi_match);
>  
> -static int hns_roce_node_match(struct device *dev, const void *fwnode)
> -{
> -	return dev->fwnode == fwnode;
> -}
> -
>  static struct
>  platform_device *hns_roce_find_pdev(struct fwnode_handle *fwnode)
>  {
>  	struct device *dev;
>  
>  	/* get the 'device' corresponding to the matching 'fwnode' */
> -	dev = bus_find_device(&platform_bus_type, NULL,
> -			      fwnode, hns_roce_node_match);
> +	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
>  	/* get the platform device */
>  	return dev ? to_platform_device(dev) : NULL;
>  }
> diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c
> index a9a9fabd3968..6f0e13fa5e1a 100644
> --- a/drivers/iommu/arm-smmu-v3.c
> +++ b/drivers/iommu/arm-smmu-v3.c
> @@ -2034,16 +2034,11 @@ arm_smmu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova)
>  
>  static struct platform_driver arm_smmu_driver;
>  
> -static int arm_smmu_match_node(struct device *dev, const void *data)
> -{
> -	return dev->fwnode == data;
> -}
> -
>  static
>  struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
>  {
> -	struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL,
> -						fwnode, arm_smmu_match_node);
> +	struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver,
> +							  fwnode);
>  	put_device(dev);
>  	return dev ? dev_get_drvdata(dev) : NULL;
>  }
> diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
> index 64977c131ee6..aa06498f291d 100644
> --- a/drivers/iommu/arm-smmu.c
> +++ b/drivers/iommu/arm-smmu.c
> @@ -1426,16 +1426,11 @@ static bool arm_smmu_capable(enum iommu_cap cap)
>  	}
>  }
>  
> -static int arm_smmu_match_node(struct device *dev, const void *data)
> -{
> -	return dev->fwnode == data;
> -}
> -
>  static
>  struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
>  {
> -	struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL,
> -						fwnode, arm_smmu_match_node);
> +	struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver,
> +							  fwnode);
>  	put_device(dev);
>  	return dev ? dev_get_drvdata(dev) : NULL;
>  }
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
> index bb6586d0e5af..ed3829ae4ef1 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
> @@ -754,17 +754,11 @@ struct dsaf_misc_op *hns_misc_op_get(struct dsaf_device *dsaf_dev)
>  	return (void *)misc_op;
>  }
>  
> -static int hns_dsaf_dev_match(struct device *dev, const void *fwnode)
> -{
> -	return dev->fwnode == fwnode;
> -}
> -
>  struct
>  platform_device *hns_dsaf_find_platform_device(struct fwnode_handle *fwnode)
>  {
>  	struct device *dev;
>  
> -	dev = bus_find_device(&platform_bus_type, NULL,
> -			      fwnode, hns_dsaf_dev_match);
> +	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
>  	return dev ? to_platform_device(dev) : NULL;
>  }
> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
> index c8efe60e2465..0526efbc4922 100644
> --- a/drivers/usb/roles/class.c
> +++ b/drivers/usb/roles/class.c
> @@ -85,11 +85,6 @@ enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw)
>  }
>  EXPORT_SYMBOL_GPL(usb_role_switch_get_role);
>  
> -static int switch_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>  static void *usb_role_switch_match(struct device_connection *con, int ep,
>  				   void *data)
>  {
> @@ -99,8 +94,7 @@ static void *usb_role_switch_match(struct device_connection *con, int ep,
>  		if (con->id && !fwnode_property_present(con->fwnode, con->id))
>  			return NULL;
>  
> -		dev = class_find_device(role_class, NULL, con->fwnode,
> -					switch_fwnode_match);
> +		dev = class_find_device_by_fwnode(role_class, con->fwnode);
>  	} else {
>  		dev = class_find_device_by_name(role_class, con->endpoint[ep]);
>  	}
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 9b0d15b487e5..94a3eda62add 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -205,11 +205,6 @@ static void typec_altmode_put_partner(struct altmode *altmode)
>  	put_device(&adev->dev);
>  }
>  
> -static int typec_port_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>  static void *typec_port_match(struct device_connection *con, int ep, void *data)
>  {
>  	struct device *dev;
> @@ -219,8 +214,7 @@ static void *typec_port_match(struct device_connection *con, int ep, void *data)
>  	 * we need to return ERR_PTR(-PROBE_DEFER) when there is no device.
>  	 */
>  	if (con->fwnode)
> -		return class_find_device(typec_class, NULL, con->fwnode,
> -					 typec_port_fwnode_match);
> +		return class_find_device_by_fwnode(typec_class, con->fwnode);
>  
>  	dev = class_find_device_by_name(typec_class, con->endpoint[ep]);
>  
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 29d8d7ad41e6..7133fc1c285d 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -166,6 +166,7 @@ void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
>  
>  int device_match_name(struct device *dev, const void *name);
>  int device_match_of_node(struct device *dev, const void *np);
> +int device_match_fwnode(struct device *dev, const void *fwnode);
>  
>  int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
>  		     int (*fn)(struct device *dev, void *data));
> @@ -198,6 +199,18 @@ bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
>  	return bus_find_device(bus, NULL, np, device_match_of_node);
>  }
>  
> +/**
> + * bus_find_device_by_fwnode : device iterator for locating a particular device
> + * matching the fwnode.
> + * @bus: bus type
> + * @fwnode: fwnode of the device to match.
> + */
> +static inline struct device *
> +bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwnode)
> +{
> +	return bus_find_device(bus, NULL, fwnode, device_match_fwnode);
> +}
> +
>  struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
>  					struct device *hint);
>  int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
> @@ -391,6 +404,19 @@ driver_find_device_by_of_node(struct device_driver *drv,
>  	return driver_find_device(drv, NULL, np, device_match_of_node);
>  }
>  
> +/**
> + * driver_find_device_by_fwnode- device iterator for locating a particular device
> + * by fwnode pointer.
> + * @driver: the driver we're iterating
> + * @fwnode: fwnode pointer to match.
> + */
> +static inline struct device *
> +driver_find_device_by_fwnode(struct device_driver *drv,
> +			     const struct fwnode_handle *fwnode)
> +{
> +	return driver_find_device(drv, NULL, fwnode, device_match_fwnode);
> +}
> +
>  void driver_deferred_probe_add(struct device *dev);
>  int driver_deferred_probe_check_state(struct device *dev);
>  int driver_deferred_probe_check_state_continue(struct device *dev);
> @@ -544,6 +570,19 @@ class_find_device_by_of_node(struct class *class, const struct device_node *np)
>  	return class_find_device(class, NULL, np, device_match_of_node);
>  }
>  
> +/**
> + * class_find_device_by_fwnode : device iterator for locating a particular device
> + * matching the fwnode.
> + * @class: class type
> + * @fwnode: fwnode of the device to match.
> + */
> +static inline struct device *
> +class_find_device_by_fwnode(struct class *class,
> +			    const struct fwnode_handle *fwnode)
> +{
> +	return class_find_device(class, NULL, fwnode, device_match_fwnode);
> +}
> +
>  struct class_attribute {
>  	struct attribute attr;
>  	ssize_t (*show)(struct class *class, struct class_attribute *attr,
> -- 
> 2.21.0
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
  2019-07-23 22:18   ` Suzuki K Poulose
  (?)
  (?)
@ 2019-07-25 19:25     ` Wolfram Sang
  -1 siblings, 0 replies; 71+ messages in thread
From: Wolfram Sang @ 2019-07-25 19:25 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: linux-kernel, gregkh, rafael, linux-arm-kernel,
	Maarten Lankhorst, Maxime Ripard, dri-devel, David Airlie,
	Daniel Vetter, devicetree, Florian Fainelli, Frank Rowand,
	Heiko Stuebner, Liam Girdwood, linux-i2c, linux-rockchip,
	linux-spi, Mathieu Poirier, Rob Herring, Srinivas Kandagatla,
	Takashi Iwai, Alan Tull, Moritz Fischer, linux-fpga, Peter Rosin,
	Mark Brown, Heiner Kallweit, David S. Miller, Andrew Lunn,
	Lee Jones, Thor Thayer, Jiri Slaby

[-- Attachment #1: Type: text/plain, Size: 1952 bytes --]

On Tue, Jul 23, 2019 at 11:18:33PM +0100, Suzuki K Poulose wrote:
> Introduce wrappers for {bus/driver/class}_find_device() to
> locate devices by its of_node.
> 
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <maxime.ripard@bootlin.com>
> Cc: dri-devel@lists.freedesktop.org
> Cc: David Airlie <airlied@linux.ie>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: devicetree@vger.kernel.org
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Frank Rowand <frowand.list@gmail.com>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: linux-i2c@vger.kernel.org
> Cc: linux-rockchip@lists.infradead.org
> Cc: linux-spi@vger.kernel.org
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> Cc: Takashi Iwai <tiwai@suse.com>
> Cc: Wolfram Sang <wsa@the-dreams.de>
> Cc: Alan Tull <atull@kernel.org>
> Cc: Moritz Fischer <mdf@kernel.org>
> Cc: linux-fpga@vger.kernel.org
> Cc: Peter Rosin <peda@axentia.se>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Heiner Kallweit <hkallweit1@gmail.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Lee Jones <lee.jones@linaro.org>
> Cc: Thor Thayer <thor.thayer@linux.intel.com>
> Cc: Jiri Slaby <jslaby@suse.com>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Peter Rosin <peda@axentia.se>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>  - Dropped the reviewed-by tags from Thor, Mark, Andrew and Peter as the
>    patches are mereged, though there are no functional changes.

Acked-by: Wolfram Sang <wsa@the-dreams.de> # I2C part


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
@ 2019-07-25 19:25     ` Wolfram Sang
  0 siblings, 0 replies; 71+ messages in thread
From: Wolfram Sang @ 2019-07-25 19:25 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: linux-kernel, gregkh, rafael, linux-arm-kernel,
	Maarten Lankhorst, Maxime Ripard, dri-devel, David Airlie,
	Daniel Vetter, devicetree, Florian Fainelli, Frank Rowand,
	Heiko Stuebner, Liam Girdwood, linux-i2c, linux-rockchip,
	linux-spi, Mathieu Poirier, Rob Herring, Srinivas Kandagatla,
	Takashi Iwai, Alan Tull

[-- Attachment #1: Type: text/plain, Size: 1952 bytes --]

On Tue, Jul 23, 2019 at 11:18:33PM +0100, Suzuki K Poulose wrote:
> Introduce wrappers for {bus/driver/class}_find_device() to
> locate devices by its of_node.
> 
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <maxime.ripard@bootlin.com>
> Cc: dri-devel@lists.freedesktop.org
> Cc: David Airlie <airlied@linux.ie>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: devicetree@vger.kernel.org
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Frank Rowand <frowand.list@gmail.com>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: linux-i2c@vger.kernel.org
> Cc: linux-rockchip@lists.infradead.org
> Cc: linux-spi@vger.kernel.org
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> Cc: Takashi Iwai <tiwai@suse.com>
> Cc: Wolfram Sang <wsa@the-dreams.de>
> Cc: Alan Tull <atull@kernel.org>
> Cc: Moritz Fischer <mdf@kernel.org>
> Cc: linux-fpga@vger.kernel.org
> Cc: Peter Rosin <peda@axentia.se>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Heiner Kallweit <hkallweit1@gmail.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Lee Jones <lee.jones@linaro.org>
> Cc: Thor Thayer <thor.thayer@linux.intel.com>
> Cc: Jiri Slaby <jslaby@suse.com>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Peter Rosin <peda@axentia.se>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>  - Dropped the reviewed-by tags from Thor, Mark, Andrew and Peter as the
>    patches are mereged, though there are no functional changes.

Acked-by: Wolfram Sang <wsa@the-dreams.de> # I2C part


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
@ 2019-07-25 19:25     ` Wolfram Sang
  0 siblings, 0 replies; 71+ messages in thread
From: Wolfram Sang @ 2019-07-25 19:25 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: linux-kernel, gregkh, rafael, linux-arm-kernel,
	Maarten Lankhorst, Maxime Ripard, dri-devel, David Airlie,
	Daniel Vetter, devicetree, Florian Fainelli, Frank Rowand,
	Heiko Stuebner, Liam Girdwood, linux-i2c, linux-rockchip,
	linux-spi, Mathieu Poirier, Rob Herring, Srinivas Kandagatla,
	Takashi Iwai, Alan Tull

[-- Attachment #1: Type: text/plain, Size: 1952 bytes --]

On Tue, Jul 23, 2019 at 11:18:33PM +0100, Suzuki K Poulose wrote:
> Introduce wrappers for {bus/driver/class}_find_device() to
> locate devices by its of_node.
> 
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <maxime.ripard@bootlin.com>
> Cc: dri-devel@lists.freedesktop.org
> Cc: David Airlie <airlied@linux.ie>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: devicetree@vger.kernel.org
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Frank Rowand <frowand.list@gmail.com>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: linux-i2c@vger.kernel.org
> Cc: linux-rockchip@lists.infradead.org
> Cc: linux-spi@vger.kernel.org
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> Cc: Takashi Iwai <tiwai@suse.com>
> Cc: Wolfram Sang <wsa@the-dreams.de>
> Cc: Alan Tull <atull@kernel.org>
> Cc: Moritz Fischer <mdf@kernel.org>
> Cc: linux-fpga@vger.kernel.org
> Cc: Peter Rosin <peda@axentia.se>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Heiner Kallweit <hkallweit1@gmail.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Lee Jones <lee.jones@linaro.org>
> Cc: Thor Thayer <thor.thayer@linux.intel.com>
> Cc: Jiri Slaby <jslaby@suse.com>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Peter Rosin <peda@axentia.se>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>  - Dropped the reviewed-by tags from Thor, Mark, Andrew and Peter as the
>    patches are mereged, though there are no functional changes.

Acked-by: Wolfram Sang <wsa@the-dreams.de> # I2C part


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
@ 2019-07-25 19:25     ` Wolfram Sang
  0 siblings, 0 replies; 71+ messages in thread
From: Wolfram Sang @ 2019-07-25 19:25 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Andrew Lunn, Thor Thayer, Heiko Stuebner, rafael, Maxime Ripard,
	linux-fpga, dri-devel, linux-kernel, David S. Miller,
	Srinivas Kandagatla, linux-i2c, Frank Rowand, Florian Fainelli,
	linux-rockchip, Lee Jones, David Airlie, Jiri Slaby, devicetree,
	Alan Tull, Liam Girdwood, Maarten Lankhorst, Rob Herring,
	Moritz Fischer, linux-arm-kernel, Mathieu Poirier, gregkh,
	Takashi Iwai, linux-spi, Mark Brown, Daniel Vetter, Peter Rosin,
	Heiner Kallweit


[-- Attachment #1.1: Type: text/plain, Size: 1952 bytes --]

On Tue, Jul 23, 2019 at 11:18:33PM +0100, Suzuki K Poulose wrote:
> Introduce wrappers for {bus/driver/class}_find_device() to
> locate devices by its of_node.
> 
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <maxime.ripard@bootlin.com>
> Cc: dri-devel@lists.freedesktop.org
> Cc: David Airlie <airlied@linux.ie>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: devicetree@vger.kernel.org
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Frank Rowand <frowand.list@gmail.com>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: linux-i2c@vger.kernel.org
> Cc: linux-rockchip@lists.infradead.org
> Cc: linux-spi@vger.kernel.org
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> Cc: Takashi Iwai <tiwai@suse.com>
> Cc: Wolfram Sang <wsa@the-dreams.de>
> Cc: Alan Tull <atull@kernel.org>
> Cc: Moritz Fischer <mdf@kernel.org>
> Cc: linux-fpga@vger.kernel.org
> Cc: Peter Rosin <peda@axentia.se>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Heiner Kallweit <hkallweit1@gmail.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Lee Jones <lee.jones@linaro.org>
> Cc: Thor Thayer <thor.thayer@linux.intel.com>
> Cc: Jiri Slaby <jslaby@suse.com>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Peter Rosin <peda@axentia.se>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>  - Dropped the reviewed-by tags from Thor, Mark, Andrew and Peter as the
>    patches are mereged, though there are no functional changes.

Acked-by: Wolfram Sang <wsa@the-dreams.de> # I2C part


[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
  2019-07-23 22:18   ` Suzuki K Poulose
  (?)
  (?)
@ 2019-07-25 21:01     ` Moritz Fischer
  -1 siblings, 0 replies; 71+ messages in thread
From: Moritz Fischer @ 2019-07-25 21:01 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: linux-kernel, gregkh, rafael, linux-arm-kernel,
	Maarten Lankhorst, Maxime Ripard, dri-devel, David Airlie,
	Daniel Vetter, devicetree, Florian Fainelli, Frank Rowand,
	Heiko Stuebner, Liam Girdwood, linux-i2c, linux-rockchip,
	linux-spi, Mathieu Poirier, Rob Herring, Srinivas Kandagatla,
	Takashi Iwai, Wolfram Sang, Alan Tull, Moritz Fischer,
	linux-fpga, Peter Rosin, Mark Brown, Heiner Kallweit,
	David S. Miller, Andrew Lunn, Lee Jones, Thor Thayer, Jiri Slaby

On Tue, Jul 23, 2019 at 11:18:33PM +0100, Suzuki K Poulose wrote:
> Introduce wrappers for {bus/driver/class}_find_device() to
> locate devices by its of_node.
> 
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <maxime.ripard@bootlin.com>
> Cc: dri-devel@lists.freedesktop.org
> Cc: David Airlie <airlied@linux.ie>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: devicetree@vger.kernel.org
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Frank Rowand <frowand.list@gmail.com>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: linux-i2c@vger.kernel.org
> Cc: linux-rockchip@lists.infradead.org
> Cc: linux-spi@vger.kernel.org
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> Cc: Takashi Iwai <tiwai@suse.com>
> Cc: Wolfram Sang <wsa@the-dreams.de>
> Cc: Alan Tull <atull@kernel.org>
> Cc: Moritz Fischer <mdf@kernel.org>
> Cc: linux-fpga@vger.kernel.org
> Cc: Peter Rosin <peda@axentia.se>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Heiner Kallweit <hkallweit1@gmail.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Lee Jones <lee.jones@linaro.org>
> Cc: Thor Thayer <thor.thayer@linux.intel.com>
> Cc: Jiri Slaby <jslaby@suse.com>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Peter Rosin <peda@axentia.se>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>

Acked-by: Moritz Fischer <mdf@kernel.org> # For FPGA part

> ---
>  - Dropped the reviewed-by tags from Thor, Mark, Andrew and Peter as the
>    patches are mereged, though there are no functional changes.
> ---
>  drivers/amba/tegra-ahb.c              | 11 +-------
>  drivers/fpga/fpga-bridge.c            |  8 +-----
>  drivers/fpga/fpga-mgr.c               |  8 +-----
>  drivers/gpu/drm/drm_mipi_dsi.c        |  7 +----
>  drivers/i2c/i2c-core-of.c             |  7 +----
>  drivers/mfd/altera-sysmgr.c           | 14 ++--------
>  drivers/mux/core.c                    |  7 +----
>  drivers/net/phy/mdio_bus.c            |  9 +------
>  drivers/nvmem/core.c                  |  7 +----
>  drivers/of/of_mdio.c                  |  8 +-----
>  drivers/of/platform.c                 |  7 +----
>  drivers/regulator/of_regulator.c      |  7 +----
>  drivers/spi/spi.c                     | 20 +++------------
>  include/linux/device.h                | 37 +++++++++++++++++++++++++++
>  sound/soc/rockchip/rk3399_gru_sound.c |  9 ++-----
>  15 files changed, 56 insertions(+), 110 deletions(-)
> 
> diff --git a/drivers/amba/tegra-ahb.c b/drivers/amba/tegra-ahb.c
> index aa64eece77a6..57d3b2e2d007 100644
> --- a/drivers/amba/tegra-ahb.c
> +++ b/drivers/amba/tegra-ahb.c
> @@ -134,22 +134,13 @@ static inline void gizmo_writel(struct tegra_ahb *ahb, u32 value, u32 offset)
>  }
>  
>  #ifdef CONFIG_TEGRA_IOMMU_SMMU
> -static int tegra_ahb_match_by_smmu(struct device *dev, const void *data)
> -{
> -	struct tegra_ahb *ahb = dev_get_drvdata(dev);
> -	const struct device_node *dn = data;
> -
> -	return (ahb->dev->of_node == dn) ? 1 : 0;
> -}
> -
>  int tegra_ahb_enable_smmu(struct device_node *dn)
>  {
>  	struct device *dev;
>  	u32 val;
>  	struct tegra_ahb *ahb;
>  
> -	dev = driver_find_device(&tegra_ahb_driver.driver, NULL, dn,
> -				 tegra_ahb_match_by_smmu);
> +	dev = driver_find_device_by_of_node(&tegra_ahb_driver.driver, dn);
>  	if (!dev)
>  		return -EPROBE_DEFER;
>  	ahb = dev_get_drvdata(dev);
> diff --git a/drivers/fpga/fpga-bridge.c b/drivers/fpga/fpga-bridge.c
> index 80bd8f1b2aa6..4bab9028940a 100644
> --- a/drivers/fpga/fpga-bridge.c
> +++ b/drivers/fpga/fpga-bridge.c
> @@ -19,11 +19,6 @@ static struct class *fpga_bridge_class;
>  /* Lock for adding/removing bridges to linked lists*/
>  static spinlock_t bridge_list_lock;
>  
> -static int fpga_bridge_of_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /**
>   * fpga_bridge_enable - Enable transactions on the bridge
>   *
> @@ -104,8 +99,7 @@ struct fpga_bridge *of_fpga_bridge_get(struct device_node *np,
>  {
>  	struct device *dev;
>  
> -	dev = class_find_device(fpga_bridge_class, NULL, np,
> -				fpga_bridge_of_node_match);
> +	dev = class_find_device_by_of_node(fpga_bridge_class, np);
>  	if (!dev)
>  		return ERR_PTR(-ENODEV);
>  
> diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
> index c3866816456a..e05104f5e40c 100644
> --- a/drivers/fpga/fpga-mgr.c
> +++ b/drivers/fpga/fpga-mgr.c
> @@ -482,11 +482,6 @@ struct fpga_manager *fpga_mgr_get(struct device *dev)
>  }
>  EXPORT_SYMBOL_GPL(fpga_mgr_get);
>  
> -static int fpga_mgr_of_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /**
>   * of_fpga_mgr_get - Given a device node, get a reference to a fpga mgr.
>   *
> @@ -498,8 +493,7 @@ struct fpga_manager *of_fpga_mgr_get(struct device_node *node)
>  {
>  	struct device *dev;
>  
> -	dev = class_find_device(fpga_mgr_class, NULL, node,
> -				fpga_mgr_of_node_match);
> +	dev = class_find_device_by_of_node(fpga_mgr_class, node);
>  	if (!dev)
>  		return ERR_PTR(-ENODEV);
>  
> diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
> index ad19df0686c9..bd2498bbd74a 100644
> --- a/drivers/gpu/drm/drm_mipi_dsi.c
> +++ b/drivers/gpu/drm/drm_mipi_dsi.c
> @@ -93,11 +93,6 @@ static struct bus_type mipi_dsi_bus_type = {
>  	.pm = &mipi_dsi_device_pm_ops,
>  };
>  
> -static int of_device_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /**
>   * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a
>   *    device tree node
> @@ -110,7 +105,7 @@ struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np)
>  {
>  	struct device *dev;
>  
> -	dev = bus_find_device(&mipi_dsi_bus_type, NULL, np, of_device_match);
> +	dev = bus_find_device_by_of_node(&mipi_dsi_bus_type, np);
>  
>  	return dev ? to_mipi_dsi_device(dev) : NULL;
>  }
> diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
> index d1c48dec7118..6f632d543fcc 100644
> --- a/drivers/i2c/i2c-core-of.c
> +++ b/drivers/i2c/i2c-core-of.c
> @@ -113,11 +113,6 @@ void of_i2c_register_devices(struct i2c_adapter *adap)
>  	of_node_put(bus);
>  }
>  
> -static int of_dev_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  static int of_dev_or_parent_node_match(struct device *dev, const void *data)
>  {
>  	if (dev->of_node == data)
> @@ -135,7 +130,7 @@ struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
>  	struct device *dev;
>  	struct i2c_client *client;
>  
> -	dev = bus_find_device(&i2c_bus_type, NULL, node, of_dev_node_match);
> +	dev = bus_find_device_by_of_node(&i2c_bus_type, node);
>  	if (!dev)
>  		return NULL;
>  
> diff --git a/drivers/mfd/altera-sysmgr.c b/drivers/mfd/altera-sysmgr.c
> index 2ee14d8a6d31..d2a13a547a3c 100644
> --- a/drivers/mfd/altera-sysmgr.c
> +++ b/drivers/mfd/altera-sysmgr.c
> @@ -87,16 +87,6 @@ static struct regmap_config altr_sysmgr_regmap_cfg = {
>  	.use_single_write = true,
>  };
>  
> -/**
> - * sysmgr_match_phandle
> - * Matching function used by driver_find_device().
> - * Return: True if match is found, otherwise false.
> - */
> -static int sysmgr_match_phandle(struct device *dev, const void *data)
> -{
> -	return dev->of_node == (const struct device_node *)data;
> -}
> -
>  /**
>   * altr_sysmgr_regmap_lookup_by_phandle
>   * 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,
>  	if (!sysmgr_np)
>  		return ERR_PTR(-ENODEV);
>  
> -	dev = driver_find_device(&altr_sysmgr_driver.driver, NULL,
> -				 (void *)sysmgr_np, sysmgr_match_phandle);
> +	dev = driver_find_device_by_of_node(&altr_sysmgr_driver.driver,
> +					    (void *)sysmgr_np);
>  	of_node_put(sysmgr_np);
>  	if (!dev)
>  		return ERR_PTR(-EPROBE_DEFER);
> diff --git a/drivers/mux/core.c b/drivers/mux/core.c
> index d1271c1ee23c..1fb22388e7e0 100644
> --- a/drivers/mux/core.c
> +++ b/drivers/mux/core.c
> @@ -405,17 +405,12 @@ int mux_control_deselect(struct mux_control *mux)
>  }
>  EXPORT_SYMBOL_GPL(mux_control_deselect);
>  
> -static int of_dev_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /* Note this function returns a reference to the mux_chip dev. */
>  static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np)
>  {
>  	struct device *dev;
>  
> -	dev = class_find_device(&mux_class, NULL, np, of_dev_node_match);
> +	dev = class_find_device_by_of_node(&mux_class, np);
>  
>  	return dev ? to_mux_chip(dev) : NULL;
>  }
> diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
> index bd04fe762056..ce940871331e 100644
> --- a/drivers/net/phy/mdio_bus.c
> +++ b/drivers/net/phy/mdio_bus.c
> @@ -262,11 +262,6 @@ static struct class mdio_bus_class = {
>  };
>  
>  #if IS_ENABLED(CONFIG_OF_MDIO)
> -/* Helper function for of_mdio_find_bus */
> -static int of_mdio_bus_match(struct device *dev, const void *mdio_bus_np)
> -{
> -	return dev->of_node == mdio_bus_np;
> -}
>  /**
>   * of_mdio_find_bus - Given an mii_bus node, find the mii_bus.
>   * @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)
>  	if (!mdio_bus_np)
>  		return NULL;
>  
> -	d = class_find_device(&mdio_bus_class, NULL,  mdio_bus_np,
> -			      of_mdio_bus_match);
> -
> +	d = class_find_device_by_of_node(&mdio_bus_class, mdio_bus_np);
>  	return d ? to_mii_bus(d) : NULL;
>  }
>  EXPORT_SYMBOL(of_mdio_find_bus);
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index ac5d945be88a..057d1ff87d5d 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -76,11 +76,6 @@ static struct bus_type nvmem_bus_type = {
>  	.name		= "nvmem",
>  };
>  
> -static int of_nvmem_match(struct device *dev, const void *nvmem_np)
> -{
> -	return dev->of_node == nvmem_np;
> -}
> -
>  static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)
>  {
>  	struct device *d;
> @@ -88,7 +83,7 @@ static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)
>  	if (!nvmem_np)
>  		return NULL;
>  
> -	d = bus_find_device(&nvmem_bus_type, NULL, nvmem_np, of_nvmem_match);
> +	d = bus_find_device_by_of_node(&nvmem_bus_type, nvmem_np);
>  
>  	if (!d)
>  		return NULL;
> diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
> index 44f53496cab1..000b95787df1 100644
> --- a/drivers/of/of_mdio.c
> +++ b/drivers/of/of_mdio.c
> @@ -280,12 +280,6 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
>  }
>  EXPORT_SYMBOL(of_mdiobus_register);
>  
> -/* Helper function for of_phy_find_device */
> -static int of_phy_match(struct device *dev, const void *phy_np)
> -{
> -	return dev->of_node == phy_np;
> -}
> -
>  /**
>   * of_phy_find_device - Give a PHY node, find the phy_device
>   * @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)
>  	if (!phy_np)
>  		return NULL;
>  
> -	d = bus_find_device(&mdio_bus_type, NULL, phy_np, of_phy_match);
> +	d = bus_find_device_by_of_node(&mdio_bus_type, phy_np);
>  	if (d) {
>  		mdiodev = to_mdio_device(d);
>  		if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)
> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> index 7801e25e6895..b47a2292fe8e 100644
> --- a/drivers/of/platform.c
> +++ b/drivers/of/platform.c
> @@ -37,11 +37,6 @@ static const struct of_device_id of_skipped_node_table[] = {
>  	{} /* Empty terminated list */
>  };
>  
> -static int of_dev_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /**
>   * of_find_device_by_node - Find the platform_device associated with a node
>   * @np: Pointer to device tree node
> @@ -55,7 +50,7 @@ struct platform_device *of_find_device_by_node(struct device_node *np)
>  {
>  	struct device *dev;
>  
> -	dev = bus_find_device(&platform_bus_type, NULL, np, of_dev_node_match);
> +	dev = bus_find_device_by_of_node(&platform_bus_type, np);
>  	return dev ? to_platform_device(dev) : NULL;
>  }
>  EXPORT_SYMBOL(of_find_device_by_node);
> diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
> index 397918ebba55..20dcc9c03adc 100644
> --- a/drivers/regulator/of_regulator.c
> +++ b/drivers/regulator/of_regulator.c
> @@ -460,16 +460,11 @@ struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
>  	return NULL;
>  }
>  
> -static int of_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  struct regulator_dev *of_find_regulator_by_node(struct device_node *np)
>  {
>  	struct device *dev;
>  
> -	dev = class_find_device(&regulator_class, NULL, np, of_node_match);
> +	dev = class_find_device_by_of_node(&regulator_class, np);
>  
>  	return dev ? dev_to_rdev(dev) : NULL;
>  }
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 75ac046cae52..a591da87981a 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -3652,37 +3652,25 @@ EXPORT_SYMBOL_GPL(spi_write_then_read);
>  /*-------------------------------------------------------------------------*/
>  
>  #if IS_ENABLED(CONFIG_OF)
> -static int __spi_of_device_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /* must call put_device() when done with returned spi_device device */
>  struct spi_device *of_find_spi_device_by_node(struct device_node *node)
>  {
> -	struct device *dev = bus_find_device(&spi_bus_type, NULL, node,
> -						__spi_of_device_match);
> +	struct device *dev = bus_find_device_by_of_node(&spi_bus_type, node);
> +
>  	return dev ? to_spi_device(dev) : NULL;
>  }
>  EXPORT_SYMBOL_GPL(of_find_spi_device_by_node);
>  #endif /* IS_ENABLED(CONFIG_OF) */
>  
>  #if IS_ENABLED(CONFIG_OF_DYNAMIC)
> -static int __spi_of_controller_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /* the spi controllers are not using spi_bus, so we find it with another way */
>  static struct spi_controller *of_find_spi_controller_by_node(struct device_node *node)
>  {
>  	struct device *dev;
>  
> -	dev = class_find_device(&spi_master_class, NULL, node,
> -				__spi_of_controller_match);
> +	dev = class_find_device_by_of_node(&spi_master_class, node);
>  	if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE))
> -		dev = class_find_device(&spi_slave_class, NULL, node,
> -					__spi_of_controller_match);
> +		dev = class_find_device_by_of_node(&spi_slave_class, node);
>  	if (!dev)
>  		return NULL;
>  
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 3ba376b8b456..29d8d7ad41e6 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -186,6 +186,18 @@ static inline struct device *bus_find_device_by_name(struct bus_type *bus,
>  	return bus_find_device(bus, start, name, device_match_name);
>  }
>  
> +/**
> + * bus_find_device_by_of_node : device iterator for locating a particular device
> + * matching the of_node.
> + * @bus: bus type
> + * @np: of_node of the device to match.
> + */
> +static inline struct device *
> +bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
> +{
> +	return bus_find_device(bus, NULL, np, device_match_of_node);
> +}
> +
>  struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
>  					struct device *hint);
>  int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
> @@ -366,6 +378,19 @@ static inline struct device *driver_find_device_by_name(struct device_driver *dr
>  	return driver_find_device(drv, NULL, name, device_match_name);
>  }
>  
> +/**
> + * driver_find_device_by_of_node- device iterator for locating a particular device
> + * by of_node pointer.
> + * @driver: the driver we're iterating
> + * @np: of_node pointer to match.
> + */
> +static inline struct device *
> +driver_find_device_by_of_node(struct device_driver *drv,
> +			      const struct device_node *np)
> +{
> +	return driver_find_device(drv, NULL, np, device_match_of_node);
> +}
> +
>  void driver_deferred_probe_add(struct device *dev);
>  int driver_deferred_probe_check_state(struct device *dev);
>  int driver_deferred_probe_check_state_continue(struct device *dev);
> @@ -507,6 +532,18 @@ static inline struct device *class_find_device_by_name(struct class *class,
>  	return class_find_device(class, NULL, name, device_match_name);
>  }
>  
> +/**
> + * class_find_device_by_of_node : device iterator for locating a particular device
> + * matching the of_node.
> + * @class: class type
> + * @np: of_node of the device to match.
> + */
> +static inline struct device *
> +class_find_device_by_of_node(struct class *class, const struct device_node *np)
> +{
> +	return class_find_device(class, NULL, np, device_match_of_node);
> +}
> +
>  struct class_attribute {
>  	struct attribute attr;
>  	ssize_t (*show)(struct class *class, struct class_attribute *attr,
> diff --git a/sound/soc/rockchip/rk3399_gru_sound.c b/sound/soc/rockchip/rk3399_gru_sound.c
> index c16b0ffe8cfc..d951100bf770 100644
> --- a/sound/soc/rockchip/rk3399_gru_sound.c
> +++ b/sound/soc/rockchip/rk3399_gru_sound.c
> @@ -422,11 +422,6 @@ static const struct dailink_match_data dailink_match[] = {
>  	},
>  };
>  
> -static int of_dev_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  static int rockchip_sound_codec_node_match(struct device_node *np_codec)
>  {
>  	struct device *dev;
> @@ -438,8 +433,8 @@ static int rockchip_sound_codec_node_match(struct device_node *np_codec)
>  			continue;
>  
>  		if (dailink_match[i].bus_type) {
> -			dev = bus_find_device(dailink_match[i].bus_type, NULL,
> -					      np_codec, of_dev_node_match);
> +			dev = bus_find_device_by_of_node(dailink_match[i].bus_type,
> +							 np_codec);
>  			if (!dev)
>  				continue;
>  			put_device(dev);
> -- 
> 2.21.0
> 

Thanks,
Moritz

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
@ 2019-07-25 21:01     ` Moritz Fischer
  0 siblings, 0 replies; 71+ messages in thread
From: Moritz Fischer @ 2019-07-25 21:01 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: linux-kernel, gregkh, rafael, linux-arm-kernel,
	Maarten Lankhorst, Maxime Ripard, dri-devel, David Airlie,
	Daniel Vetter, devicetree, Florian Fainelli, Frank Rowand,
	Heiko Stuebner, Liam Girdwood, linux-i2c, linux-rockchip,
	linux-spi, Mathieu Poirier, Rob Herring, Srinivas Kandagatla,
	Takashi Iwai, Wolfram Sang

On Tue, Jul 23, 2019 at 11:18:33PM +0100, Suzuki K Poulose wrote:
> Introduce wrappers for {bus/driver/class}_find_device() to
> locate devices by its of_node.
> 
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <maxime.ripard@bootlin.com>
> Cc: dri-devel@lists.freedesktop.org
> Cc: David Airlie <airlied@linux.ie>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: devicetree@vger.kernel.org
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Frank Rowand <frowand.list@gmail.com>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: linux-i2c@vger.kernel.org
> Cc: linux-rockchip@lists.infradead.org
> Cc: linux-spi@vger.kernel.org
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> Cc: Takashi Iwai <tiwai@suse.com>
> Cc: Wolfram Sang <wsa@the-dreams.de>
> Cc: Alan Tull <atull@kernel.org>
> Cc: Moritz Fischer <mdf@kernel.org>
> Cc: linux-fpga@vger.kernel.org
> Cc: Peter Rosin <peda@axentia.se>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Heiner Kallweit <hkallweit1@gmail.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Lee Jones <lee.jones@linaro.org>
> Cc: Thor Thayer <thor.thayer@linux.intel.com>
> Cc: Jiri Slaby <jslaby@suse.com>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Peter Rosin <peda@axentia.se>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>

Acked-by: Moritz Fischer <mdf@kernel.org> # For FPGA part

> ---
>  - Dropped the reviewed-by tags from Thor, Mark, Andrew and Peter as the
>    patches are mereged, though there are no functional changes.
> ---
>  drivers/amba/tegra-ahb.c              | 11 +-------
>  drivers/fpga/fpga-bridge.c            |  8 +-----
>  drivers/fpga/fpga-mgr.c               |  8 +-----
>  drivers/gpu/drm/drm_mipi_dsi.c        |  7 +----
>  drivers/i2c/i2c-core-of.c             |  7 +----
>  drivers/mfd/altera-sysmgr.c           | 14 ++--------
>  drivers/mux/core.c                    |  7 +----
>  drivers/net/phy/mdio_bus.c            |  9 +------
>  drivers/nvmem/core.c                  |  7 +----
>  drivers/of/of_mdio.c                  |  8 +-----
>  drivers/of/platform.c                 |  7 +----
>  drivers/regulator/of_regulator.c      |  7 +----
>  drivers/spi/spi.c                     | 20 +++------------
>  include/linux/device.h                | 37 +++++++++++++++++++++++++++
>  sound/soc/rockchip/rk3399_gru_sound.c |  9 ++-----
>  15 files changed, 56 insertions(+), 110 deletions(-)
> 
> diff --git a/drivers/amba/tegra-ahb.c b/drivers/amba/tegra-ahb.c
> index aa64eece77a6..57d3b2e2d007 100644
> --- a/drivers/amba/tegra-ahb.c
> +++ b/drivers/amba/tegra-ahb.c
> @@ -134,22 +134,13 @@ static inline void gizmo_writel(struct tegra_ahb *ahb, u32 value, u32 offset)
>  }
>  
>  #ifdef CONFIG_TEGRA_IOMMU_SMMU
> -static int tegra_ahb_match_by_smmu(struct device *dev, const void *data)
> -{
> -	struct tegra_ahb *ahb = dev_get_drvdata(dev);
> -	const struct device_node *dn = data;
> -
> -	return (ahb->dev->of_node == dn) ? 1 : 0;
> -}
> -
>  int tegra_ahb_enable_smmu(struct device_node *dn)
>  {
>  	struct device *dev;
>  	u32 val;
>  	struct tegra_ahb *ahb;
>  
> -	dev = driver_find_device(&tegra_ahb_driver.driver, NULL, dn,
> -				 tegra_ahb_match_by_smmu);
> +	dev = driver_find_device_by_of_node(&tegra_ahb_driver.driver, dn);
>  	if (!dev)
>  		return -EPROBE_DEFER;
>  	ahb = dev_get_drvdata(dev);
> diff --git a/drivers/fpga/fpga-bridge.c b/drivers/fpga/fpga-bridge.c
> index 80bd8f1b2aa6..4bab9028940a 100644
> --- a/drivers/fpga/fpga-bridge.c
> +++ b/drivers/fpga/fpga-bridge.c
> @@ -19,11 +19,6 @@ static struct class *fpga_bridge_class;
>  /* Lock for adding/removing bridges to linked lists*/
>  static spinlock_t bridge_list_lock;
>  
> -static int fpga_bridge_of_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /**
>   * fpga_bridge_enable - Enable transactions on the bridge
>   *
> @@ -104,8 +99,7 @@ struct fpga_bridge *of_fpga_bridge_get(struct device_node *np,
>  {
>  	struct device *dev;
>  
> -	dev = class_find_device(fpga_bridge_class, NULL, np,
> -				fpga_bridge_of_node_match);
> +	dev = class_find_device_by_of_node(fpga_bridge_class, np);
>  	if (!dev)
>  		return ERR_PTR(-ENODEV);
>  
> diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
> index c3866816456a..e05104f5e40c 100644
> --- a/drivers/fpga/fpga-mgr.c
> +++ b/drivers/fpga/fpga-mgr.c
> @@ -482,11 +482,6 @@ struct fpga_manager *fpga_mgr_get(struct device *dev)
>  }
>  EXPORT_SYMBOL_GPL(fpga_mgr_get);
>  
> -static int fpga_mgr_of_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /**
>   * of_fpga_mgr_get - Given a device node, get a reference to a fpga mgr.
>   *
> @@ -498,8 +493,7 @@ struct fpga_manager *of_fpga_mgr_get(struct device_node *node)
>  {
>  	struct device *dev;
>  
> -	dev = class_find_device(fpga_mgr_class, NULL, node,
> -				fpga_mgr_of_node_match);
> +	dev = class_find_device_by_of_node(fpga_mgr_class, node);
>  	if (!dev)
>  		return ERR_PTR(-ENODEV);
>  
> diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
> index ad19df0686c9..bd2498bbd74a 100644
> --- a/drivers/gpu/drm/drm_mipi_dsi.c
> +++ b/drivers/gpu/drm/drm_mipi_dsi.c
> @@ -93,11 +93,6 @@ static struct bus_type mipi_dsi_bus_type = {
>  	.pm = &mipi_dsi_device_pm_ops,
>  };
>  
> -static int of_device_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /**
>   * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a
>   *    device tree node
> @@ -110,7 +105,7 @@ struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np)
>  {
>  	struct device *dev;
>  
> -	dev = bus_find_device(&mipi_dsi_bus_type, NULL, np, of_device_match);
> +	dev = bus_find_device_by_of_node(&mipi_dsi_bus_type, np);
>  
>  	return dev ? to_mipi_dsi_device(dev) : NULL;
>  }
> diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
> index d1c48dec7118..6f632d543fcc 100644
> --- a/drivers/i2c/i2c-core-of.c
> +++ b/drivers/i2c/i2c-core-of.c
> @@ -113,11 +113,6 @@ void of_i2c_register_devices(struct i2c_adapter *adap)
>  	of_node_put(bus);
>  }
>  
> -static int of_dev_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  static int of_dev_or_parent_node_match(struct device *dev, const void *data)
>  {
>  	if (dev->of_node == data)
> @@ -135,7 +130,7 @@ struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
>  	struct device *dev;
>  	struct i2c_client *client;
>  
> -	dev = bus_find_device(&i2c_bus_type, NULL, node, of_dev_node_match);
> +	dev = bus_find_device_by_of_node(&i2c_bus_type, node);
>  	if (!dev)
>  		return NULL;
>  
> diff --git a/drivers/mfd/altera-sysmgr.c b/drivers/mfd/altera-sysmgr.c
> index 2ee14d8a6d31..d2a13a547a3c 100644
> --- a/drivers/mfd/altera-sysmgr.c
> +++ b/drivers/mfd/altera-sysmgr.c
> @@ -87,16 +87,6 @@ static struct regmap_config altr_sysmgr_regmap_cfg = {
>  	.use_single_write = true,
>  };
>  
> -/**
> - * sysmgr_match_phandle
> - * Matching function used by driver_find_device().
> - * Return: True if match is found, otherwise false.
> - */
> -static int sysmgr_match_phandle(struct device *dev, const void *data)
> -{
> -	return dev->of_node == (const struct device_node *)data;
> -}
> -
>  /**
>   * altr_sysmgr_regmap_lookup_by_phandle
>   * 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,
>  	if (!sysmgr_np)
>  		return ERR_PTR(-ENODEV);
>  
> -	dev = driver_find_device(&altr_sysmgr_driver.driver, NULL,
> -				 (void *)sysmgr_np, sysmgr_match_phandle);
> +	dev = driver_find_device_by_of_node(&altr_sysmgr_driver.driver,
> +					    (void *)sysmgr_np);
>  	of_node_put(sysmgr_np);
>  	if (!dev)
>  		return ERR_PTR(-EPROBE_DEFER);
> diff --git a/drivers/mux/core.c b/drivers/mux/core.c
> index d1271c1ee23c..1fb22388e7e0 100644
> --- a/drivers/mux/core.c
> +++ b/drivers/mux/core.c
> @@ -405,17 +405,12 @@ int mux_control_deselect(struct mux_control *mux)
>  }
>  EXPORT_SYMBOL_GPL(mux_control_deselect);
>  
> -static int of_dev_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /* Note this function returns a reference to the mux_chip dev. */
>  static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np)
>  {
>  	struct device *dev;
>  
> -	dev = class_find_device(&mux_class, NULL, np, of_dev_node_match);
> +	dev = class_find_device_by_of_node(&mux_class, np);
>  
>  	return dev ? to_mux_chip(dev) : NULL;
>  }
> diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
> index bd04fe762056..ce940871331e 100644
> --- a/drivers/net/phy/mdio_bus.c
> +++ b/drivers/net/phy/mdio_bus.c
> @@ -262,11 +262,6 @@ static struct class mdio_bus_class = {
>  };
>  
>  #if IS_ENABLED(CONFIG_OF_MDIO)
> -/* Helper function for of_mdio_find_bus */
> -static int of_mdio_bus_match(struct device *dev, const void *mdio_bus_np)
> -{
> -	return dev->of_node == mdio_bus_np;
> -}
>  /**
>   * of_mdio_find_bus - Given an mii_bus node, find the mii_bus.
>   * @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)
>  	if (!mdio_bus_np)
>  		return NULL;
>  
> -	d = class_find_device(&mdio_bus_class, NULL,  mdio_bus_np,
> -			      of_mdio_bus_match);
> -
> +	d = class_find_device_by_of_node(&mdio_bus_class, mdio_bus_np);
>  	return d ? to_mii_bus(d) : NULL;
>  }
>  EXPORT_SYMBOL(of_mdio_find_bus);
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index ac5d945be88a..057d1ff87d5d 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -76,11 +76,6 @@ static struct bus_type nvmem_bus_type = {
>  	.name		= "nvmem",
>  };
>  
> -static int of_nvmem_match(struct device *dev, const void *nvmem_np)
> -{
> -	return dev->of_node == nvmem_np;
> -}
> -
>  static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)
>  {
>  	struct device *d;
> @@ -88,7 +83,7 @@ static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)
>  	if (!nvmem_np)
>  		return NULL;
>  
> -	d = bus_find_device(&nvmem_bus_type, NULL, nvmem_np, of_nvmem_match);
> +	d = bus_find_device_by_of_node(&nvmem_bus_type, nvmem_np);
>  
>  	if (!d)
>  		return NULL;
> diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
> index 44f53496cab1..000b95787df1 100644
> --- a/drivers/of/of_mdio.c
> +++ b/drivers/of/of_mdio.c
> @@ -280,12 +280,6 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
>  }
>  EXPORT_SYMBOL(of_mdiobus_register);
>  
> -/* Helper function for of_phy_find_device */
> -static int of_phy_match(struct device *dev, const void *phy_np)
> -{
> -	return dev->of_node == phy_np;
> -}
> -
>  /**
>   * of_phy_find_device - Give a PHY node, find the phy_device
>   * @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)
>  	if (!phy_np)
>  		return NULL;
>  
> -	d = bus_find_device(&mdio_bus_type, NULL, phy_np, of_phy_match);
> +	d = bus_find_device_by_of_node(&mdio_bus_type, phy_np);
>  	if (d) {
>  		mdiodev = to_mdio_device(d);
>  		if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)
> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> index 7801e25e6895..b47a2292fe8e 100644
> --- a/drivers/of/platform.c
> +++ b/drivers/of/platform.c
> @@ -37,11 +37,6 @@ static const struct of_device_id of_skipped_node_table[] = {
>  	{} /* Empty terminated list */
>  };
>  
> -static int of_dev_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /**
>   * of_find_device_by_node - Find the platform_device associated with a node
>   * @np: Pointer to device tree node
> @@ -55,7 +50,7 @@ struct platform_device *of_find_device_by_node(struct device_node *np)
>  {
>  	struct device *dev;
>  
> -	dev = bus_find_device(&platform_bus_type, NULL, np, of_dev_node_match);
> +	dev = bus_find_device_by_of_node(&platform_bus_type, np);
>  	return dev ? to_platform_device(dev) : NULL;
>  }
>  EXPORT_SYMBOL(of_find_device_by_node);
> diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
> index 397918ebba55..20dcc9c03adc 100644
> --- a/drivers/regulator/of_regulator.c
> +++ b/drivers/regulator/of_regulator.c
> @@ -460,16 +460,11 @@ struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
>  	return NULL;
>  }
>  
> -static int of_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  struct regulator_dev *of_find_regulator_by_node(struct device_node *np)
>  {
>  	struct device *dev;
>  
> -	dev = class_find_device(&regulator_class, NULL, np, of_node_match);
> +	dev = class_find_device_by_of_node(&regulator_class, np);
>  
>  	return dev ? dev_to_rdev(dev) : NULL;
>  }
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 75ac046cae52..a591da87981a 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -3652,37 +3652,25 @@ EXPORT_SYMBOL_GPL(spi_write_then_read);
>  /*-------------------------------------------------------------------------*/
>  
>  #if IS_ENABLED(CONFIG_OF)
> -static int __spi_of_device_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /* must call put_device() when done with returned spi_device device */
>  struct spi_device *of_find_spi_device_by_node(struct device_node *node)
>  {
> -	struct device *dev = bus_find_device(&spi_bus_type, NULL, node,
> -						__spi_of_device_match);
> +	struct device *dev = bus_find_device_by_of_node(&spi_bus_type, node);
> +
>  	return dev ? to_spi_device(dev) : NULL;
>  }
>  EXPORT_SYMBOL_GPL(of_find_spi_device_by_node);
>  #endif /* IS_ENABLED(CONFIG_OF) */
>  
>  #if IS_ENABLED(CONFIG_OF_DYNAMIC)
> -static int __spi_of_controller_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /* the spi controllers are not using spi_bus, so we find it with another way */
>  static struct spi_controller *of_find_spi_controller_by_node(struct device_node *node)
>  {
>  	struct device *dev;
>  
> -	dev = class_find_device(&spi_master_class, NULL, node,
> -				__spi_of_controller_match);
> +	dev = class_find_device_by_of_node(&spi_master_class, node);
>  	if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE))
> -		dev = class_find_device(&spi_slave_class, NULL, node,
> -					__spi_of_controller_match);
> +		dev = class_find_device_by_of_node(&spi_slave_class, node);
>  	if (!dev)
>  		return NULL;
>  
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 3ba376b8b456..29d8d7ad41e6 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -186,6 +186,18 @@ static inline struct device *bus_find_device_by_name(struct bus_type *bus,
>  	return bus_find_device(bus, start, name, device_match_name);
>  }
>  
> +/**
> + * bus_find_device_by_of_node : device iterator for locating a particular device
> + * matching the of_node.
> + * @bus: bus type
> + * @np: of_node of the device to match.
> + */
> +static inline struct device *
> +bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
> +{
> +	return bus_find_device(bus, NULL, np, device_match_of_node);
> +}
> +
>  struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
>  					struct device *hint);
>  int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
> @@ -366,6 +378,19 @@ static inline struct device *driver_find_device_by_name(struct device_driver *dr
>  	return driver_find_device(drv, NULL, name, device_match_name);
>  }
>  
> +/**
> + * driver_find_device_by_of_node- device iterator for locating a particular device
> + * by of_node pointer.
> + * @driver: the driver we're iterating
> + * @np: of_node pointer to match.
> + */
> +static inline struct device *
> +driver_find_device_by_of_node(struct device_driver *drv,
> +			      const struct device_node *np)
> +{
> +	return driver_find_device(drv, NULL, np, device_match_of_node);
> +}
> +
>  void driver_deferred_probe_add(struct device *dev);
>  int driver_deferred_probe_check_state(struct device *dev);
>  int driver_deferred_probe_check_state_continue(struct device *dev);
> @@ -507,6 +532,18 @@ static inline struct device *class_find_device_by_name(struct class *class,
>  	return class_find_device(class, NULL, name, device_match_name);
>  }
>  
> +/**
> + * class_find_device_by_of_node : device iterator for locating a particular device
> + * matching the of_node.
> + * @class: class type
> + * @np: of_node of the device to match.
> + */
> +static inline struct device *
> +class_find_device_by_of_node(struct class *class, const struct device_node *np)
> +{
> +	return class_find_device(class, NULL, np, device_match_of_node);
> +}
> +
>  struct class_attribute {
>  	struct attribute attr;
>  	ssize_t (*show)(struct class *class, struct class_attribute *attr,
> diff --git a/sound/soc/rockchip/rk3399_gru_sound.c b/sound/soc/rockchip/rk3399_gru_sound.c
> index c16b0ffe8cfc..d951100bf770 100644
> --- a/sound/soc/rockchip/rk3399_gru_sound.c
> +++ b/sound/soc/rockchip/rk3399_gru_sound.c
> @@ -422,11 +422,6 @@ static const struct dailink_match_data dailink_match[] = {
>  	},
>  };
>  
> -static int of_dev_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  static int rockchip_sound_codec_node_match(struct device_node *np_codec)
>  {
>  	struct device *dev;
> @@ -438,8 +433,8 @@ static int rockchip_sound_codec_node_match(struct device_node *np_codec)
>  			continue;
>  
>  		if (dailink_match[i].bus_type) {
> -			dev = bus_find_device(dailink_match[i].bus_type, NULL,
> -					      np_codec, of_dev_node_match);
> +			dev = bus_find_device_by_of_node(dailink_match[i].bus_type,
> +							 np_codec);
>  			if (!dev)
>  				continue;
>  			put_device(dev);
> -- 
> 2.21.0
> 

Thanks,
Moritz

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
@ 2019-07-25 21:01     ` Moritz Fischer
  0 siblings, 0 replies; 71+ messages in thread
From: Moritz Fischer @ 2019-07-25 21:01 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: linux-kernel, gregkh, rafael, linux-arm-kernel,
	Maarten Lankhorst, Maxime Ripard, dri-devel, David Airlie,
	Daniel Vetter, devicetree, Florian Fainelli, Frank Rowand,
	Heiko Stuebner, Liam Girdwood, linux-i2c, linux-rockchip,
	linux-spi, Mathieu Poirier, Rob Herring, Srinivas Kandagatla,
	Takashi Iwai, Wolfram Sang

On Tue, Jul 23, 2019 at 11:18:33PM +0100, Suzuki K Poulose wrote:
> Introduce wrappers for {bus/driver/class}_find_device() to
> locate devices by its of_node.
> 
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <maxime.ripard@bootlin.com>
> Cc: dri-devel@lists.freedesktop.org
> Cc: David Airlie <airlied@linux.ie>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: devicetree@vger.kernel.org
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Frank Rowand <frowand.list@gmail.com>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: linux-i2c@vger.kernel.org
> Cc: linux-rockchip@lists.infradead.org
> Cc: linux-spi@vger.kernel.org
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> Cc: Takashi Iwai <tiwai@suse.com>
> Cc: Wolfram Sang <wsa@the-dreams.de>
> Cc: Alan Tull <atull@kernel.org>
> Cc: Moritz Fischer <mdf@kernel.org>
> Cc: linux-fpga@vger.kernel.org
> Cc: Peter Rosin <peda@axentia.se>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Heiner Kallweit <hkallweit1@gmail.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Lee Jones <lee.jones@linaro.org>
> Cc: Thor Thayer <thor.thayer@linux.intel.com>
> Cc: Jiri Slaby <jslaby@suse.com>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Peter Rosin <peda@axentia.se>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>

Acked-by: Moritz Fischer <mdf@kernel.org> # For FPGA part

> ---
>  - Dropped the reviewed-by tags from Thor, Mark, Andrew and Peter as the
>    patches are mereged, though there are no functional changes.
> ---
>  drivers/amba/tegra-ahb.c              | 11 +-------
>  drivers/fpga/fpga-bridge.c            |  8 +-----
>  drivers/fpga/fpga-mgr.c               |  8 +-----
>  drivers/gpu/drm/drm_mipi_dsi.c        |  7 +----
>  drivers/i2c/i2c-core-of.c             |  7 +----
>  drivers/mfd/altera-sysmgr.c           | 14 ++--------
>  drivers/mux/core.c                    |  7 +----
>  drivers/net/phy/mdio_bus.c            |  9 +------
>  drivers/nvmem/core.c                  |  7 +----
>  drivers/of/of_mdio.c                  |  8 +-----
>  drivers/of/platform.c                 |  7 +----
>  drivers/regulator/of_regulator.c      |  7 +----
>  drivers/spi/spi.c                     | 20 +++------------
>  include/linux/device.h                | 37 +++++++++++++++++++++++++++
>  sound/soc/rockchip/rk3399_gru_sound.c |  9 ++-----
>  15 files changed, 56 insertions(+), 110 deletions(-)
> 
> diff --git a/drivers/amba/tegra-ahb.c b/drivers/amba/tegra-ahb.c
> index aa64eece77a6..57d3b2e2d007 100644
> --- a/drivers/amba/tegra-ahb.c
> +++ b/drivers/amba/tegra-ahb.c
> @@ -134,22 +134,13 @@ static inline void gizmo_writel(struct tegra_ahb *ahb, u32 value, u32 offset)
>  }
>  
>  #ifdef CONFIG_TEGRA_IOMMU_SMMU
> -static int tegra_ahb_match_by_smmu(struct device *dev, const void *data)
> -{
> -	struct tegra_ahb *ahb = dev_get_drvdata(dev);
> -	const struct device_node *dn = data;
> -
> -	return (ahb->dev->of_node == dn) ? 1 : 0;
> -}
> -
>  int tegra_ahb_enable_smmu(struct device_node *dn)
>  {
>  	struct device *dev;
>  	u32 val;
>  	struct tegra_ahb *ahb;
>  
> -	dev = driver_find_device(&tegra_ahb_driver.driver, NULL, dn,
> -				 tegra_ahb_match_by_smmu);
> +	dev = driver_find_device_by_of_node(&tegra_ahb_driver.driver, dn);
>  	if (!dev)
>  		return -EPROBE_DEFER;
>  	ahb = dev_get_drvdata(dev);
> diff --git a/drivers/fpga/fpga-bridge.c b/drivers/fpga/fpga-bridge.c
> index 80bd8f1b2aa6..4bab9028940a 100644
> --- a/drivers/fpga/fpga-bridge.c
> +++ b/drivers/fpga/fpga-bridge.c
> @@ -19,11 +19,6 @@ static struct class *fpga_bridge_class;
>  /* Lock for adding/removing bridges to linked lists*/
>  static spinlock_t bridge_list_lock;
>  
> -static int fpga_bridge_of_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /**
>   * fpga_bridge_enable - Enable transactions on the bridge
>   *
> @@ -104,8 +99,7 @@ struct fpga_bridge *of_fpga_bridge_get(struct device_node *np,
>  {
>  	struct device *dev;
>  
> -	dev = class_find_device(fpga_bridge_class, NULL, np,
> -				fpga_bridge_of_node_match);
> +	dev = class_find_device_by_of_node(fpga_bridge_class, np);
>  	if (!dev)
>  		return ERR_PTR(-ENODEV);
>  
> diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
> index c3866816456a..e05104f5e40c 100644
> --- a/drivers/fpga/fpga-mgr.c
> +++ b/drivers/fpga/fpga-mgr.c
> @@ -482,11 +482,6 @@ struct fpga_manager *fpga_mgr_get(struct device *dev)
>  }
>  EXPORT_SYMBOL_GPL(fpga_mgr_get);
>  
> -static int fpga_mgr_of_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /**
>   * of_fpga_mgr_get - Given a device node, get a reference to a fpga mgr.
>   *
> @@ -498,8 +493,7 @@ struct fpga_manager *of_fpga_mgr_get(struct device_node *node)
>  {
>  	struct device *dev;
>  
> -	dev = class_find_device(fpga_mgr_class, NULL, node,
> -				fpga_mgr_of_node_match);
> +	dev = class_find_device_by_of_node(fpga_mgr_class, node);
>  	if (!dev)
>  		return ERR_PTR(-ENODEV);
>  
> diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
> index ad19df0686c9..bd2498bbd74a 100644
> --- a/drivers/gpu/drm/drm_mipi_dsi.c
> +++ b/drivers/gpu/drm/drm_mipi_dsi.c
> @@ -93,11 +93,6 @@ static struct bus_type mipi_dsi_bus_type = {
>  	.pm = &mipi_dsi_device_pm_ops,
>  };
>  
> -static int of_device_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /**
>   * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a
>   *    device tree node
> @@ -110,7 +105,7 @@ struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np)
>  {
>  	struct device *dev;
>  
> -	dev = bus_find_device(&mipi_dsi_bus_type, NULL, np, of_device_match);
> +	dev = bus_find_device_by_of_node(&mipi_dsi_bus_type, np);
>  
>  	return dev ? to_mipi_dsi_device(dev) : NULL;
>  }
> diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
> index d1c48dec7118..6f632d543fcc 100644
> --- a/drivers/i2c/i2c-core-of.c
> +++ b/drivers/i2c/i2c-core-of.c
> @@ -113,11 +113,6 @@ void of_i2c_register_devices(struct i2c_adapter *adap)
>  	of_node_put(bus);
>  }
>  
> -static int of_dev_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  static int of_dev_or_parent_node_match(struct device *dev, const void *data)
>  {
>  	if (dev->of_node == data)
> @@ -135,7 +130,7 @@ struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
>  	struct device *dev;
>  	struct i2c_client *client;
>  
> -	dev = bus_find_device(&i2c_bus_type, NULL, node, of_dev_node_match);
> +	dev = bus_find_device_by_of_node(&i2c_bus_type, node);
>  	if (!dev)
>  		return NULL;
>  
> diff --git a/drivers/mfd/altera-sysmgr.c b/drivers/mfd/altera-sysmgr.c
> index 2ee14d8a6d31..d2a13a547a3c 100644
> --- a/drivers/mfd/altera-sysmgr.c
> +++ b/drivers/mfd/altera-sysmgr.c
> @@ -87,16 +87,6 @@ static struct regmap_config altr_sysmgr_regmap_cfg = {
>  	.use_single_write = true,
>  };
>  
> -/**
> - * sysmgr_match_phandle
> - * Matching function used by driver_find_device().
> - * Return: True if match is found, otherwise false.
> - */
> -static int sysmgr_match_phandle(struct device *dev, const void *data)
> -{
> -	return dev->of_node == (const struct device_node *)data;
> -}
> -
>  /**
>   * altr_sysmgr_regmap_lookup_by_phandle
>   * 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,
>  	if (!sysmgr_np)
>  		return ERR_PTR(-ENODEV);
>  
> -	dev = driver_find_device(&altr_sysmgr_driver.driver, NULL,
> -				 (void *)sysmgr_np, sysmgr_match_phandle);
> +	dev = driver_find_device_by_of_node(&altr_sysmgr_driver.driver,
> +					    (void *)sysmgr_np);
>  	of_node_put(sysmgr_np);
>  	if (!dev)
>  		return ERR_PTR(-EPROBE_DEFER);
> diff --git a/drivers/mux/core.c b/drivers/mux/core.c
> index d1271c1ee23c..1fb22388e7e0 100644
> --- a/drivers/mux/core.c
> +++ b/drivers/mux/core.c
> @@ -405,17 +405,12 @@ int mux_control_deselect(struct mux_control *mux)
>  }
>  EXPORT_SYMBOL_GPL(mux_control_deselect);
>  
> -static int of_dev_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /* Note this function returns a reference to the mux_chip dev. */
>  static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np)
>  {
>  	struct device *dev;
>  
> -	dev = class_find_device(&mux_class, NULL, np, of_dev_node_match);
> +	dev = class_find_device_by_of_node(&mux_class, np);
>  
>  	return dev ? to_mux_chip(dev) : NULL;
>  }
> diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
> index bd04fe762056..ce940871331e 100644
> --- a/drivers/net/phy/mdio_bus.c
> +++ b/drivers/net/phy/mdio_bus.c
> @@ -262,11 +262,6 @@ static struct class mdio_bus_class = {
>  };
>  
>  #if IS_ENABLED(CONFIG_OF_MDIO)
> -/* Helper function for of_mdio_find_bus */
> -static int of_mdio_bus_match(struct device *dev, const void *mdio_bus_np)
> -{
> -	return dev->of_node == mdio_bus_np;
> -}
>  /**
>   * of_mdio_find_bus - Given an mii_bus node, find the mii_bus.
>   * @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)
>  	if (!mdio_bus_np)
>  		return NULL;
>  
> -	d = class_find_device(&mdio_bus_class, NULL,  mdio_bus_np,
> -			      of_mdio_bus_match);
> -
> +	d = class_find_device_by_of_node(&mdio_bus_class, mdio_bus_np);
>  	return d ? to_mii_bus(d) : NULL;
>  }
>  EXPORT_SYMBOL(of_mdio_find_bus);
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index ac5d945be88a..057d1ff87d5d 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -76,11 +76,6 @@ static struct bus_type nvmem_bus_type = {
>  	.name		= "nvmem",
>  };
>  
> -static int of_nvmem_match(struct device *dev, const void *nvmem_np)
> -{
> -	return dev->of_node == nvmem_np;
> -}
> -
>  static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)
>  {
>  	struct device *d;
> @@ -88,7 +83,7 @@ static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)
>  	if (!nvmem_np)
>  		return NULL;
>  
> -	d = bus_find_device(&nvmem_bus_type, NULL, nvmem_np, of_nvmem_match);
> +	d = bus_find_device_by_of_node(&nvmem_bus_type, nvmem_np);
>  
>  	if (!d)
>  		return NULL;
> diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
> index 44f53496cab1..000b95787df1 100644
> --- a/drivers/of/of_mdio.c
> +++ b/drivers/of/of_mdio.c
> @@ -280,12 +280,6 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
>  }
>  EXPORT_SYMBOL(of_mdiobus_register);
>  
> -/* Helper function for of_phy_find_device */
> -static int of_phy_match(struct device *dev, const void *phy_np)
> -{
> -	return dev->of_node == phy_np;
> -}
> -
>  /**
>   * of_phy_find_device - Give a PHY node, find the phy_device
>   * @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)
>  	if (!phy_np)
>  		return NULL;
>  
> -	d = bus_find_device(&mdio_bus_type, NULL, phy_np, of_phy_match);
> +	d = bus_find_device_by_of_node(&mdio_bus_type, phy_np);
>  	if (d) {
>  		mdiodev = to_mdio_device(d);
>  		if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)
> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> index 7801e25e6895..b47a2292fe8e 100644
> --- a/drivers/of/platform.c
> +++ b/drivers/of/platform.c
> @@ -37,11 +37,6 @@ static const struct of_device_id of_skipped_node_table[] = {
>  	{} /* Empty terminated list */
>  };
>  
> -static int of_dev_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /**
>   * of_find_device_by_node - Find the platform_device associated with a node
>   * @np: Pointer to device tree node
> @@ -55,7 +50,7 @@ struct platform_device *of_find_device_by_node(struct device_node *np)
>  {
>  	struct device *dev;
>  
> -	dev = bus_find_device(&platform_bus_type, NULL, np, of_dev_node_match);
> +	dev = bus_find_device_by_of_node(&platform_bus_type, np);
>  	return dev ? to_platform_device(dev) : NULL;
>  }
>  EXPORT_SYMBOL(of_find_device_by_node);
> diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
> index 397918ebba55..20dcc9c03adc 100644
> --- a/drivers/regulator/of_regulator.c
> +++ b/drivers/regulator/of_regulator.c
> @@ -460,16 +460,11 @@ struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
>  	return NULL;
>  }
>  
> -static int of_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  struct regulator_dev *of_find_regulator_by_node(struct device_node *np)
>  {
>  	struct device *dev;
>  
> -	dev = class_find_device(&regulator_class, NULL, np, of_node_match);
> +	dev = class_find_device_by_of_node(&regulator_class, np);
>  
>  	return dev ? dev_to_rdev(dev) : NULL;
>  }
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 75ac046cae52..a591da87981a 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -3652,37 +3652,25 @@ EXPORT_SYMBOL_GPL(spi_write_then_read);
>  /*-------------------------------------------------------------------------*/
>  
>  #if IS_ENABLED(CONFIG_OF)
> -static int __spi_of_device_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /* must call put_device() when done with returned spi_device device */
>  struct spi_device *of_find_spi_device_by_node(struct device_node *node)
>  {
> -	struct device *dev = bus_find_device(&spi_bus_type, NULL, node,
> -						__spi_of_device_match);
> +	struct device *dev = bus_find_device_by_of_node(&spi_bus_type, node);
> +
>  	return dev ? to_spi_device(dev) : NULL;
>  }
>  EXPORT_SYMBOL_GPL(of_find_spi_device_by_node);
>  #endif /* IS_ENABLED(CONFIG_OF) */
>  
>  #if IS_ENABLED(CONFIG_OF_DYNAMIC)
> -static int __spi_of_controller_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /* the spi controllers are not using spi_bus, so we find it with another way */
>  static struct spi_controller *of_find_spi_controller_by_node(struct device_node *node)
>  {
>  	struct device *dev;
>  
> -	dev = class_find_device(&spi_master_class, NULL, node,
> -				__spi_of_controller_match);
> +	dev = class_find_device_by_of_node(&spi_master_class, node);
>  	if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE))
> -		dev = class_find_device(&spi_slave_class, NULL, node,
> -					__spi_of_controller_match);
> +		dev = class_find_device_by_of_node(&spi_slave_class, node);
>  	if (!dev)
>  		return NULL;
>  
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 3ba376b8b456..29d8d7ad41e6 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -186,6 +186,18 @@ static inline struct device *bus_find_device_by_name(struct bus_type *bus,
>  	return bus_find_device(bus, start, name, device_match_name);
>  }
>  
> +/**
> + * bus_find_device_by_of_node : device iterator for locating a particular device
> + * matching the of_node.
> + * @bus: bus type
> + * @np: of_node of the device to match.
> + */
> +static inline struct device *
> +bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
> +{
> +	return bus_find_device(bus, NULL, np, device_match_of_node);
> +}
> +
>  struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
>  					struct device *hint);
>  int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
> @@ -366,6 +378,19 @@ static inline struct device *driver_find_device_by_name(struct device_driver *dr
>  	return driver_find_device(drv, NULL, name, device_match_name);
>  }
>  
> +/**
> + * driver_find_device_by_of_node- device iterator for locating a particular device
> + * by of_node pointer.
> + * @driver: the driver we're iterating
> + * @np: of_node pointer to match.
> + */
> +static inline struct device *
> +driver_find_device_by_of_node(struct device_driver *drv,
> +			      const struct device_node *np)
> +{
> +	return driver_find_device(drv, NULL, np, device_match_of_node);
> +}
> +
>  void driver_deferred_probe_add(struct device *dev);
>  int driver_deferred_probe_check_state(struct device *dev);
>  int driver_deferred_probe_check_state_continue(struct device *dev);
> @@ -507,6 +532,18 @@ static inline struct device *class_find_device_by_name(struct class *class,
>  	return class_find_device(class, NULL, name, device_match_name);
>  }
>  
> +/**
> + * class_find_device_by_of_node : device iterator for locating a particular device
> + * matching the of_node.
> + * @class: class type
> + * @np: of_node of the device to match.
> + */
> +static inline struct device *
> +class_find_device_by_of_node(struct class *class, const struct device_node *np)
> +{
> +	return class_find_device(class, NULL, np, device_match_of_node);
> +}
> +
>  struct class_attribute {
>  	struct attribute attr;
>  	ssize_t (*show)(struct class *class, struct class_attribute *attr,
> diff --git a/sound/soc/rockchip/rk3399_gru_sound.c b/sound/soc/rockchip/rk3399_gru_sound.c
> index c16b0ffe8cfc..d951100bf770 100644
> --- a/sound/soc/rockchip/rk3399_gru_sound.c
> +++ b/sound/soc/rockchip/rk3399_gru_sound.c
> @@ -422,11 +422,6 @@ static const struct dailink_match_data dailink_match[] = {
>  	},
>  };
>  
> -static int of_dev_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  static int rockchip_sound_codec_node_match(struct device_node *np_codec)
>  {
>  	struct device *dev;
> @@ -438,8 +433,8 @@ static int rockchip_sound_codec_node_match(struct device_node *np_codec)
>  			continue;
>  
>  		if (dailink_match[i].bus_type) {
> -			dev = bus_find_device(dailink_match[i].bus_type, NULL,
> -					      np_codec, of_dev_node_match);
> +			dev = bus_find_device_by_of_node(dailink_match[i].bus_type,
> +							 np_codec);
>  			if (!dev)
>  				continue;
>  			put_device(dev);
> -- 
> 2.21.0
> 

Thanks,
Moritz

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
@ 2019-07-25 21:01     ` Moritz Fischer
  0 siblings, 0 replies; 71+ messages in thread
From: Moritz Fischer @ 2019-07-25 21:01 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Andrew Lunn, Thor Thayer, Heiko Stuebner, rafael, Maxime Ripard,
	linux-fpga, dri-devel, linux-kernel, David S. Miller,
	Srinivas Kandagatla, linux-i2c, Frank Rowand, Florian Fainelli,
	linux-rockchip, Lee Jones, Wolfram Sang, David Airlie,
	Jiri Slaby, devicetree, Alan Tull, Liam Girdwood,
	Maarten Lankhorst, Rob Herring, Moritz Fischer, linux-arm-kernel,
	Mathieu Poirier, gregkh, Takashi Iwai, linux-spi, Mark Brown,
	Daniel Vetter, Peter Rosin, Heiner Kallweit

On Tue, Jul 23, 2019 at 11:18:33PM +0100, Suzuki K Poulose wrote:
> Introduce wrappers for {bus/driver/class}_find_device() to
> locate devices by its of_node.
> 
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <maxime.ripard@bootlin.com>
> Cc: dri-devel@lists.freedesktop.org
> Cc: David Airlie <airlied@linux.ie>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: devicetree@vger.kernel.org
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Frank Rowand <frowand.list@gmail.com>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: linux-i2c@vger.kernel.org
> Cc: linux-rockchip@lists.infradead.org
> Cc: linux-spi@vger.kernel.org
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> Cc: Takashi Iwai <tiwai@suse.com>
> Cc: Wolfram Sang <wsa@the-dreams.de>
> Cc: Alan Tull <atull@kernel.org>
> Cc: Moritz Fischer <mdf@kernel.org>
> Cc: linux-fpga@vger.kernel.org
> Cc: Peter Rosin <peda@axentia.se>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Heiner Kallweit <hkallweit1@gmail.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Lee Jones <lee.jones@linaro.org>
> Cc: Thor Thayer <thor.thayer@linux.intel.com>
> Cc: Jiri Slaby <jslaby@suse.com>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Peter Rosin <peda@axentia.se>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>

Acked-by: Moritz Fischer <mdf@kernel.org> # For FPGA part

> ---
>  - Dropped the reviewed-by tags from Thor, Mark, Andrew and Peter as the
>    patches are mereged, though there are no functional changes.
> ---
>  drivers/amba/tegra-ahb.c              | 11 +-------
>  drivers/fpga/fpga-bridge.c            |  8 +-----
>  drivers/fpga/fpga-mgr.c               |  8 +-----
>  drivers/gpu/drm/drm_mipi_dsi.c        |  7 +----
>  drivers/i2c/i2c-core-of.c             |  7 +----
>  drivers/mfd/altera-sysmgr.c           | 14 ++--------
>  drivers/mux/core.c                    |  7 +----
>  drivers/net/phy/mdio_bus.c            |  9 +------
>  drivers/nvmem/core.c                  |  7 +----
>  drivers/of/of_mdio.c                  |  8 +-----
>  drivers/of/platform.c                 |  7 +----
>  drivers/regulator/of_regulator.c      |  7 +----
>  drivers/spi/spi.c                     | 20 +++------------
>  include/linux/device.h                | 37 +++++++++++++++++++++++++++
>  sound/soc/rockchip/rk3399_gru_sound.c |  9 ++-----
>  15 files changed, 56 insertions(+), 110 deletions(-)
> 
> diff --git a/drivers/amba/tegra-ahb.c b/drivers/amba/tegra-ahb.c
> index aa64eece77a6..57d3b2e2d007 100644
> --- a/drivers/amba/tegra-ahb.c
> +++ b/drivers/amba/tegra-ahb.c
> @@ -134,22 +134,13 @@ static inline void gizmo_writel(struct tegra_ahb *ahb, u32 value, u32 offset)
>  }
>  
>  #ifdef CONFIG_TEGRA_IOMMU_SMMU
> -static int tegra_ahb_match_by_smmu(struct device *dev, const void *data)
> -{
> -	struct tegra_ahb *ahb = dev_get_drvdata(dev);
> -	const struct device_node *dn = data;
> -
> -	return (ahb->dev->of_node == dn) ? 1 : 0;
> -}
> -
>  int tegra_ahb_enable_smmu(struct device_node *dn)
>  {
>  	struct device *dev;
>  	u32 val;
>  	struct tegra_ahb *ahb;
>  
> -	dev = driver_find_device(&tegra_ahb_driver.driver, NULL, dn,
> -				 tegra_ahb_match_by_smmu);
> +	dev = driver_find_device_by_of_node(&tegra_ahb_driver.driver, dn);
>  	if (!dev)
>  		return -EPROBE_DEFER;
>  	ahb = dev_get_drvdata(dev);
> diff --git a/drivers/fpga/fpga-bridge.c b/drivers/fpga/fpga-bridge.c
> index 80bd8f1b2aa6..4bab9028940a 100644
> --- a/drivers/fpga/fpga-bridge.c
> +++ b/drivers/fpga/fpga-bridge.c
> @@ -19,11 +19,6 @@ static struct class *fpga_bridge_class;
>  /* Lock for adding/removing bridges to linked lists*/
>  static spinlock_t bridge_list_lock;
>  
> -static int fpga_bridge_of_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /**
>   * fpga_bridge_enable - Enable transactions on the bridge
>   *
> @@ -104,8 +99,7 @@ struct fpga_bridge *of_fpga_bridge_get(struct device_node *np,
>  {
>  	struct device *dev;
>  
> -	dev = class_find_device(fpga_bridge_class, NULL, np,
> -				fpga_bridge_of_node_match);
> +	dev = class_find_device_by_of_node(fpga_bridge_class, np);
>  	if (!dev)
>  		return ERR_PTR(-ENODEV);
>  
> diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
> index c3866816456a..e05104f5e40c 100644
> --- a/drivers/fpga/fpga-mgr.c
> +++ b/drivers/fpga/fpga-mgr.c
> @@ -482,11 +482,6 @@ struct fpga_manager *fpga_mgr_get(struct device *dev)
>  }
>  EXPORT_SYMBOL_GPL(fpga_mgr_get);
>  
> -static int fpga_mgr_of_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /**
>   * of_fpga_mgr_get - Given a device node, get a reference to a fpga mgr.
>   *
> @@ -498,8 +493,7 @@ struct fpga_manager *of_fpga_mgr_get(struct device_node *node)
>  {
>  	struct device *dev;
>  
> -	dev = class_find_device(fpga_mgr_class, NULL, node,
> -				fpga_mgr_of_node_match);
> +	dev = class_find_device_by_of_node(fpga_mgr_class, node);
>  	if (!dev)
>  		return ERR_PTR(-ENODEV);
>  
> diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
> index ad19df0686c9..bd2498bbd74a 100644
> --- a/drivers/gpu/drm/drm_mipi_dsi.c
> +++ b/drivers/gpu/drm/drm_mipi_dsi.c
> @@ -93,11 +93,6 @@ static struct bus_type mipi_dsi_bus_type = {
>  	.pm = &mipi_dsi_device_pm_ops,
>  };
>  
> -static int of_device_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /**
>   * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a
>   *    device tree node
> @@ -110,7 +105,7 @@ struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np)
>  {
>  	struct device *dev;
>  
> -	dev = bus_find_device(&mipi_dsi_bus_type, NULL, np, of_device_match);
> +	dev = bus_find_device_by_of_node(&mipi_dsi_bus_type, np);
>  
>  	return dev ? to_mipi_dsi_device(dev) : NULL;
>  }
> diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
> index d1c48dec7118..6f632d543fcc 100644
> --- a/drivers/i2c/i2c-core-of.c
> +++ b/drivers/i2c/i2c-core-of.c
> @@ -113,11 +113,6 @@ void of_i2c_register_devices(struct i2c_adapter *adap)
>  	of_node_put(bus);
>  }
>  
> -static int of_dev_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  static int of_dev_or_parent_node_match(struct device *dev, const void *data)
>  {
>  	if (dev->of_node == data)
> @@ -135,7 +130,7 @@ struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
>  	struct device *dev;
>  	struct i2c_client *client;
>  
> -	dev = bus_find_device(&i2c_bus_type, NULL, node, of_dev_node_match);
> +	dev = bus_find_device_by_of_node(&i2c_bus_type, node);
>  	if (!dev)
>  		return NULL;
>  
> diff --git a/drivers/mfd/altera-sysmgr.c b/drivers/mfd/altera-sysmgr.c
> index 2ee14d8a6d31..d2a13a547a3c 100644
> --- a/drivers/mfd/altera-sysmgr.c
> +++ b/drivers/mfd/altera-sysmgr.c
> @@ -87,16 +87,6 @@ static struct regmap_config altr_sysmgr_regmap_cfg = {
>  	.use_single_write = true,
>  };
>  
> -/**
> - * sysmgr_match_phandle
> - * Matching function used by driver_find_device().
> - * Return: True if match is found, otherwise false.
> - */
> -static int sysmgr_match_phandle(struct device *dev, const void *data)
> -{
> -	return dev->of_node == (const struct device_node *)data;
> -}
> -
>  /**
>   * altr_sysmgr_regmap_lookup_by_phandle
>   * 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,
>  	if (!sysmgr_np)
>  		return ERR_PTR(-ENODEV);
>  
> -	dev = driver_find_device(&altr_sysmgr_driver.driver, NULL,
> -				 (void *)sysmgr_np, sysmgr_match_phandle);
> +	dev = driver_find_device_by_of_node(&altr_sysmgr_driver.driver,
> +					    (void *)sysmgr_np);
>  	of_node_put(sysmgr_np);
>  	if (!dev)
>  		return ERR_PTR(-EPROBE_DEFER);
> diff --git a/drivers/mux/core.c b/drivers/mux/core.c
> index d1271c1ee23c..1fb22388e7e0 100644
> --- a/drivers/mux/core.c
> +++ b/drivers/mux/core.c
> @@ -405,17 +405,12 @@ int mux_control_deselect(struct mux_control *mux)
>  }
>  EXPORT_SYMBOL_GPL(mux_control_deselect);
>  
> -static int of_dev_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /* Note this function returns a reference to the mux_chip dev. */
>  static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np)
>  {
>  	struct device *dev;
>  
> -	dev = class_find_device(&mux_class, NULL, np, of_dev_node_match);
> +	dev = class_find_device_by_of_node(&mux_class, np);
>  
>  	return dev ? to_mux_chip(dev) : NULL;
>  }
> diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
> index bd04fe762056..ce940871331e 100644
> --- a/drivers/net/phy/mdio_bus.c
> +++ b/drivers/net/phy/mdio_bus.c
> @@ -262,11 +262,6 @@ static struct class mdio_bus_class = {
>  };
>  
>  #if IS_ENABLED(CONFIG_OF_MDIO)
> -/* Helper function for of_mdio_find_bus */
> -static int of_mdio_bus_match(struct device *dev, const void *mdio_bus_np)
> -{
> -	return dev->of_node == mdio_bus_np;
> -}
>  /**
>   * of_mdio_find_bus - Given an mii_bus node, find the mii_bus.
>   * @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)
>  	if (!mdio_bus_np)
>  		return NULL;
>  
> -	d = class_find_device(&mdio_bus_class, NULL,  mdio_bus_np,
> -			      of_mdio_bus_match);
> -
> +	d = class_find_device_by_of_node(&mdio_bus_class, mdio_bus_np);
>  	return d ? to_mii_bus(d) : NULL;
>  }
>  EXPORT_SYMBOL(of_mdio_find_bus);
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index ac5d945be88a..057d1ff87d5d 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -76,11 +76,6 @@ static struct bus_type nvmem_bus_type = {
>  	.name		= "nvmem",
>  };
>  
> -static int of_nvmem_match(struct device *dev, const void *nvmem_np)
> -{
> -	return dev->of_node == nvmem_np;
> -}
> -
>  static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)
>  {
>  	struct device *d;
> @@ -88,7 +83,7 @@ static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)
>  	if (!nvmem_np)
>  		return NULL;
>  
> -	d = bus_find_device(&nvmem_bus_type, NULL, nvmem_np, of_nvmem_match);
> +	d = bus_find_device_by_of_node(&nvmem_bus_type, nvmem_np);
>  
>  	if (!d)
>  		return NULL;
> diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
> index 44f53496cab1..000b95787df1 100644
> --- a/drivers/of/of_mdio.c
> +++ b/drivers/of/of_mdio.c
> @@ -280,12 +280,6 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
>  }
>  EXPORT_SYMBOL(of_mdiobus_register);
>  
> -/* Helper function for of_phy_find_device */
> -static int of_phy_match(struct device *dev, const void *phy_np)
> -{
> -	return dev->of_node == phy_np;
> -}
> -
>  /**
>   * of_phy_find_device - Give a PHY node, find the phy_device
>   * @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)
>  	if (!phy_np)
>  		return NULL;
>  
> -	d = bus_find_device(&mdio_bus_type, NULL, phy_np, of_phy_match);
> +	d = bus_find_device_by_of_node(&mdio_bus_type, phy_np);
>  	if (d) {
>  		mdiodev = to_mdio_device(d);
>  		if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)
> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> index 7801e25e6895..b47a2292fe8e 100644
> --- a/drivers/of/platform.c
> +++ b/drivers/of/platform.c
> @@ -37,11 +37,6 @@ static const struct of_device_id of_skipped_node_table[] = {
>  	{} /* Empty terminated list */
>  };
>  
> -static int of_dev_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /**
>   * of_find_device_by_node - Find the platform_device associated with a node
>   * @np: Pointer to device tree node
> @@ -55,7 +50,7 @@ struct platform_device *of_find_device_by_node(struct device_node *np)
>  {
>  	struct device *dev;
>  
> -	dev = bus_find_device(&platform_bus_type, NULL, np, of_dev_node_match);
> +	dev = bus_find_device_by_of_node(&platform_bus_type, np);
>  	return dev ? to_platform_device(dev) : NULL;
>  }
>  EXPORT_SYMBOL(of_find_device_by_node);
> diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
> index 397918ebba55..20dcc9c03adc 100644
> --- a/drivers/regulator/of_regulator.c
> +++ b/drivers/regulator/of_regulator.c
> @@ -460,16 +460,11 @@ struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
>  	return NULL;
>  }
>  
> -static int of_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  struct regulator_dev *of_find_regulator_by_node(struct device_node *np)
>  {
>  	struct device *dev;
>  
> -	dev = class_find_device(&regulator_class, NULL, np, of_node_match);
> +	dev = class_find_device_by_of_node(&regulator_class, np);
>  
>  	return dev ? dev_to_rdev(dev) : NULL;
>  }
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 75ac046cae52..a591da87981a 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -3652,37 +3652,25 @@ EXPORT_SYMBOL_GPL(spi_write_then_read);
>  /*-------------------------------------------------------------------------*/
>  
>  #if IS_ENABLED(CONFIG_OF)
> -static int __spi_of_device_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /* must call put_device() when done with returned spi_device device */
>  struct spi_device *of_find_spi_device_by_node(struct device_node *node)
>  {
> -	struct device *dev = bus_find_device(&spi_bus_type, NULL, node,
> -						__spi_of_device_match);
> +	struct device *dev = bus_find_device_by_of_node(&spi_bus_type, node);
> +
>  	return dev ? to_spi_device(dev) : NULL;
>  }
>  EXPORT_SYMBOL_GPL(of_find_spi_device_by_node);
>  #endif /* IS_ENABLED(CONFIG_OF) */
>  
>  #if IS_ENABLED(CONFIG_OF_DYNAMIC)
> -static int __spi_of_controller_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  /* the spi controllers are not using spi_bus, so we find it with another way */
>  static struct spi_controller *of_find_spi_controller_by_node(struct device_node *node)
>  {
>  	struct device *dev;
>  
> -	dev = class_find_device(&spi_master_class, NULL, node,
> -				__spi_of_controller_match);
> +	dev = class_find_device_by_of_node(&spi_master_class, node);
>  	if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE))
> -		dev = class_find_device(&spi_slave_class, NULL, node,
> -					__spi_of_controller_match);
> +		dev = class_find_device_by_of_node(&spi_slave_class, node);
>  	if (!dev)
>  		return NULL;
>  
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 3ba376b8b456..29d8d7ad41e6 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -186,6 +186,18 @@ static inline struct device *bus_find_device_by_name(struct bus_type *bus,
>  	return bus_find_device(bus, start, name, device_match_name);
>  }
>  
> +/**
> + * bus_find_device_by_of_node : device iterator for locating a particular device
> + * matching the of_node.
> + * @bus: bus type
> + * @np: of_node of the device to match.
> + */
> +static inline struct device *
> +bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
> +{
> +	return bus_find_device(bus, NULL, np, device_match_of_node);
> +}
> +
>  struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
>  					struct device *hint);
>  int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
> @@ -366,6 +378,19 @@ static inline struct device *driver_find_device_by_name(struct device_driver *dr
>  	return driver_find_device(drv, NULL, name, device_match_name);
>  }
>  
> +/**
> + * driver_find_device_by_of_node- device iterator for locating a particular device
> + * by of_node pointer.
> + * @driver: the driver we're iterating
> + * @np: of_node pointer to match.
> + */
> +static inline struct device *
> +driver_find_device_by_of_node(struct device_driver *drv,
> +			      const struct device_node *np)
> +{
> +	return driver_find_device(drv, NULL, np, device_match_of_node);
> +}
> +
>  void driver_deferred_probe_add(struct device *dev);
>  int driver_deferred_probe_check_state(struct device *dev);
>  int driver_deferred_probe_check_state_continue(struct device *dev);
> @@ -507,6 +532,18 @@ static inline struct device *class_find_device_by_name(struct class *class,
>  	return class_find_device(class, NULL, name, device_match_name);
>  }
>  
> +/**
> + * class_find_device_by_of_node : device iterator for locating a particular device
> + * matching the of_node.
> + * @class: class type
> + * @np: of_node of the device to match.
> + */
> +static inline struct device *
> +class_find_device_by_of_node(struct class *class, const struct device_node *np)
> +{
> +	return class_find_device(class, NULL, np, device_match_of_node);
> +}
> +
>  struct class_attribute {
>  	struct attribute attr;
>  	ssize_t (*show)(struct class *class, struct class_attribute *attr,
> diff --git a/sound/soc/rockchip/rk3399_gru_sound.c b/sound/soc/rockchip/rk3399_gru_sound.c
> index c16b0ffe8cfc..d951100bf770 100644
> --- a/sound/soc/rockchip/rk3399_gru_sound.c
> +++ b/sound/soc/rockchip/rk3399_gru_sound.c
> @@ -422,11 +422,6 @@ static const struct dailink_match_data dailink_match[] = {
>  	},
>  };
>  
> -static int of_dev_node_match(struct device *dev, const void *data)
> -{
> -	return dev->of_node == data;
> -}
> -
>  static int rockchip_sound_codec_node_match(struct device_node *np_codec)
>  {
>  	struct device *dev;
> @@ -438,8 +433,8 @@ static int rockchip_sound_codec_node_match(struct device_node *np_codec)
>  			continue;
>  
>  		if (dailink_match[i].bus_type) {
> -			dev = bus_find_device(dailink_match[i].bus_type, NULL,
> -					      np_codec, of_dev_node_match);
> +			dev = bus_find_device_by_of_node(dailink_match[i].bus_type,
> +							 np_codec);
>  			if (!dev)
>  				continue;
>  			put_device(dev);
> -- 
> 2.21.0
> 

Thanks,
Moritz

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
  2019-07-23 22:18   ` Suzuki K Poulose
  (?)
  (?)
@ 2019-07-26 17:18     ` Mark Brown
  -1 siblings, 0 replies; 71+ messages in thread
From: Mark Brown @ 2019-07-26 17:18 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: linux-kernel, gregkh, rafael, linux-arm-kernel,
	Maarten Lankhorst, Maxime Ripard, dri-devel, David Airlie,
	Daniel Vetter, devicetree, Florian Fainelli, Frank Rowand,
	Heiko Stuebner, Liam Girdwood, linux-i2c, linux-rockchip,
	linux-spi, Mathieu Poirier, Rob Herring, Srinivas Kandagatla,
	Takashi Iwai, Wolfram Sang, Alan Tull, Moritz Fischer,
	linux-fpga, Peter Rosin, Heiner Kallweit, David S. Miller,
	Andrew Lunn, Lee Jones, Thor Thayer, Jiri Slaby

[-- Attachment #1: Type: text/plain, Size: 203 bytes --]

On Tue, Jul 23, 2019 at 11:18:33PM +0100, Suzuki K Poulose wrote:
> Introduce wrappers for {bus/driver/class}_find_device() to
> locate devices by its of_node.

Acked-by: Mark Brown <broonie@kernel.org>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
@ 2019-07-26 17:18     ` Mark Brown
  0 siblings, 0 replies; 71+ messages in thread
From: Mark Brown @ 2019-07-26 17:18 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Andrew Lunn, Thor Thayer, rafael, Maxime Ripard, linux-fpga,
	dri-devel, linux-kernel, David S. Miller, Srinivas Kandagatla,
	linux-i2c, Frank Rowand, Florian Fainelli, linux-rockchip,
	Lee Jones, Wolfram Sang, David Airlie, Jiri Slaby, devicetree,
	Alan Tull, Liam Girdwood, Rob Herring, Moritz Fischer,
	linux-arm-kernel, Mathieu Poirier, gregkh


[-- Attachment #1.1: Type: text/plain, Size: 203 bytes --]

On Tue, Jul 23, 2019 at 11:18:33PM +0100, Suzuki K Poulose wrote:
> Introduce wrappers for {bus/driver/class}_find_device() to
> locate devices by its of_node.

Acked-by: Mark Brown <broonie@kernel.org>

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
@ 2019-07-26 17:18     ` Mark Brown
  0 siblings, 0 replies; 71+ messages in thread
From: Mark Brown @ 2019-07-26 17:18 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Andrew Lunn, Thor Thayer, rafael, Maxime Ripard, linux-fpga,
	dri-devel, linux-kernel, David S. Miller, Srinivas Kandagatla,
	linux-i2c, Frank Rowand, Florian Fainelli, linux-rockchip,
	Lee Jones, Wolfram Sang, David Airlie, Jiri Slaby, devicetree,
	Alan Tull, Liam Girdwood, Rob Herring, Moritz Fischer,
	linux-arm-kernel, Mathieu Poirier, gregkh, Takashi Iwai


[-- Attachment #1.1: Type: text/plain, Size: 203 bytes --]

On Tue, Jul 23, 2019 at 11:18:33PM +0100, Suzuki K Poulose wrote:
> Introduce wrappers for {bus/driver/class}_find_device() to
> locate devices by its of_node.

Acked-by: Mark Brown <broonie@kernel.org>

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
@ 2019-07-26 17:18     ` Mark Brown
  0 siblings, 0 replies; 71+ messages in thread
From: Mark Brown @ 2019-07-26 17:18 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Andrew Lunn, Thor Thayer, Heiko Stuebner, rafael, Maxime Ripard,
	linux-fpga, dri-devel, linux-kernel, David S. Miller,
	Srinivas Kandagatla, linux-i2c, Frank Rowand, Florian Fainelli,
	linux-rockchip, Lee Jones, Wolfram Sang, David Airlie,
	Jiri Slaby, devicetree, Alan Tull, Liam Girdwood,
	Maarten Lankhorst, Rob Herring, Moritz Fischer, linux-arm-kernel,
	Mathieu Poirier, gregkh, Takashi Iwai, linux-spi, Daniel Vetter,
	Peter Rosin, Heiner Kallweit


[-- Attachment #1.1: Type: text/plain, Size: 203 bytes --]

On Tue, Jul 23, 2019 at 11:18:33PM +0100, Suzuki K Poulose wrote:
> Introduce wrappers for {bus/driver/class}_find_device() to
> locate devices by its of_node.

Acked-by: Mark Brown <broonie@kernel.org>

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 5/7] drivers: Introduce device lookup variants by ACPI_COMPANION device
  2019-07-23 22:18   ` Suzuki K Poulose
@ 2019-07-26 17:18     ` Mark Brown
  -1 siblings, 0 replies; 71+ messages in thread
From: Mark Brown @ 2019-07-26 17:18 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: linux-kernel, gregkh, rafael, linux-arm-kernel, Len Brown,
	linux-acpi, linux-spi, Mika Westerberg, Wolfram Sang, linux-i2c

[-- Attachment #1: Type: text/plain, Size: 230 bytes --]

On Tue, Jul 23, 2019 at 11:18:36PM +0100, Suzuki K Poulose wrote:
> Add a generic helper to match a device by the ACPI_COMPANION device
> and provide wrappers for the device lookup APIs.

Acked-by: Mark Brown <broonie@kernel.org>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 5/7] drivers: Introduce device lookup variants by ACPI_COMPANION device
@ 2019-07-26 17:18     ` Mark Brown
  0 siblings, 0 replies; 71+ messages in thread
From: Mark Brown @ 2019-07-26 17:18 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: rafael, gregkh, Wolfram Sang, linux-kernel, linux-spi,
	linux-acpi, linux-i2c, Mika Westerberg, linux-arm-kernel,
	Len Brown


[-- Attachment #1.1: Type: text/plain, Size: 230 bytes --]

On Tue, Jul 23, 2019 at 11:18:36PM +0100, Suzuki K Poulose wrote:
> Add a generic helper to match a device by the ACPI_COMPANION device
> and provide wrappers for the device lookup APIs.

Acked-by: Mark Brown <broonie@kernel.org>

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 5/7] drivers: Introduce device lookup variants by ACPI_COMPANION device
  2019-07-23 22:18   ` Suzuki K Poulose
  (?)
@ 2019-07-26 20:23     ` Wolfram Sang
  -1 siblings, 0 replies; 71+ messages in thread
From: Wolfram Sang @ 2019-07-26 20:23 UTC (permalink / raw)
  To: Suzuki K Poulose, Mika Westerberg, Andy Shevchenko, Jarkko Nikula
  Cc: linux-kernel, gregkh, rafael, linux-arm-kernel, Len Brown,
	linux-acpi, linux-spi, Mark Brown, Mika Westerberg, linux-i2c

[-- Attachment #1: Type: text/plain, Size: 7404 bytes --]

On Tue, Jul 23, 2019 at 11:18:36PM +0100, Suzuki K Poulose wrote:
> Add a generic helper to match a device by the ACPI_COMPANION device
> and provide wrappers for the device lookup APIs.
> 
> Cc: Len Brown <lenb@kernel.org>
> Cc: linux-acpi@vger.kernel.org
> Cc: linux-spi@vger.kernel.org
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
> Cc: Wolfram Sang <wsa@the-dreams.de>
> Cc: linux-i2c@vger.kernel.org
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>

From my side, OK:

Acked-by: Wolfram Sang <wsa@the-dreams.de> # I2C parts

yet you missed to cc the I2C ACPI maintainers. Done so now.

> ---
>  drivers/base/core.c         |  6 ++++
>  drivers/i2c/i2c-core-acpi.c | 11 ++-----
>  drivers/spi/spi.c           |  8 +----
>  include/linux/device.h      | 65 +++++++++++++++++++++++++++++++++++++
>  4 files changed, 74 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 3abc32b60c0a..57d71bc2c559 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -3373,3 +3373,9 @@ int device_match_devt(struct device *dev, const void *pdevt)
>  	return dev->devt == *(dev_t *)pdevt;
>  }
>  EXPORT_SYMBOL_GPL(device_match_devt);
> +
> +int device_match_acpi_dev(struct device *dev, const void *adev)
> +{
> +	return ACPI_COMPANION(dev) == adev;
> +}
> +EXPORT_SYMBOL(device_match_acpi_dev);
> diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
> index 4dbbc9a35f65..bc80aafb521f 100644
> --- a/drivers/i2c/i2c-core-acpi.c
> +++ b/drivers/i2c/i2c-core-acpi.c
> @@ -354,17 +354,11 @@ static int i2c_acpi_find_match_adapter(struct device *dev, const void *data)
>  	return ACPI_HANDLE(dev) == (acpi_handle)data;
>  }
>  
> -static int i2c_acpi_find_match_device(struct device *dev, const void *data)
> -{
> -	return ACPI_COMPANION(dev) == data;
> -}
>  
>  struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle)
>  {
> -	struct device *dev;
> +	struct device *dev = bus_find_device_by_acpi_dev(&i2c_bus_type, handle);
>  
> -	dev = bus_find_device(&i2c_bus_type, NULL, handle,
> -			      i2c_acpi_find_match_adapter);
>  	return dev ? i2c_verify_adapter(dev) : NULL;
>  }
>  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)
>  {
>  	struct device *dev;
>  
> -	dev = bus_find_device(&i2c_bus_type, NULL, adev,
> -			      i2c_acpi_find_match_device);
> +	dev = bus_find_device_by_acpi_dev(&i2c_bus_type, adev);
>  	return dev ? i2c_verify_client(dev) : NULL;
>  }
>  
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index a591da87981a..c486a6f84c2c 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -3741,11 +3741,6 @@ static int spi_acpi_controller_match(struct device *dev, const void *data)
>  	return ACPI_COMPANION(dev->parent) == data;
>  }
>  
> -static int spi_acpi_device_match(struct device *dev, const void *data)
> -{
> -	return ACPI_COMPANION(dev) == data;
> -}
> -
>  static struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev)
>  {
>  	struct device *dev;
> @@ -3765,8 +3760,7 @@ static struct spi_device *acpi_spi_find_device_by_adev(struct acpi_device *adev)
>  {
>  	struct device *dev;
>  
> -	dev = bus_find_device(&spi_bus_type, NULL, adev, spi_acpi_device_match);
> -
> +	dev = bus_find_device_by_acpi_dev(&spi_bus_type, adev);
>  	return dev ? to_spi_device(dev) : NULL;
>  }
>  
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 93b2f55ef44e..7514ef3d3f1a 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -168,6 +168,7 @@ int device_match_name(struct device *dev, const void *name);
>  int device_match_of_node(struct device *dev, const void *np);
>  int device_match_fwnode(struct device *dev, const void *fwnode);
>  int device_match_devt(struct device *dev, const void *pdevt);
> +int device_match_acpi_dev(struct device *dev, const void *adev);
>  
>  int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
>  		     int (*fn)(struct device *dev, void *data));
> @@ -224,6 +225,28 @@ static inline struct device *bus_find_device_by_devt(struct bus_type *bus,
>  	return bus_find_device(bus, NULL, &devt, device_match_devt);
>  }
>  
> +#ifdef CONFIG_ACPI
> +struct acpi_device;
> +
> +/**
> + * bus_find_device_by_acpi_dev : device iterator for locating a particular device
> + * matching the ACPI COMPANION device.
> + * @bus: bus type
> + * @adev: ACPI COMPANION device to match.
> + */
> +static inline struct device *
> +bus_find_device_by_acpi_dev(struct bus_type *bus, const struct acpi_device *adev)
> +{
> +	return bus_find_device(bus, NULL, adev, device_match_acpi_dev);
> +}
> +#else
> +static inline struct device *
> +bus_find_device_by_acpi_dev(struct bus_type *bus, const void *adev)
> +{
> +	return NULL;
> +}
> +#endif
> +
>  struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
>  					struct device *hint);
>  int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
> @@ -442,6 +465,27 @@ static inline struct device *driver_find_device_by_devt(struct device_driver *dr
>  	return driver_find_device(drv, NULL, &devt, device_match_devt);
>  }
>  
> +#ifdef CONFIG_ACPI
> +/**
> + * driver_find_device_by_acpi_dev : device iterator for locating a particular
> + * device matching the ACPI_COMPANION device.
> + * @driver: the driver we're iterating
> + * @adev: ACPI_COMPANION device to match.
> + */
> +static inline struct device *
> +driver_find_device_by_acpi_dev(struct device_driver *drv,
> +			       const struct acpi_device *adev)
> +{
> +	return driver_find_device(drv, NULL, adev, device_match_acpi_dev);
> +}
> +#else
> +static inline struct device *
> +driver_find_device_by_acpi_dev(struct device_driver *drv, const void *adev)
> +{
> +	return NULL;
> +}
> +#endif
> +
>  void driver_deferred_probe_add(struct device *dev);
>  int driver_deferred_probe_check_state(struct device *dev);
>  int driver_deferred_probe_check_state_continue(struct device *dev);
> @@ -620,6 +664,27 @@ static inline struct device *class_find_device_by_devt(struct class *class,
>  	return class_find_device(class, NULL, &devt, device_match_devt);
>  }
>  
> +#ifdef CONFIG_ACPI
> +struct acpi_device;
> +/**
> + * class_find_device_by_acpi_dev : device iterator for locating a particular
> + * device matching the ACPI_COMPANION device.
> + * @class: class type
> + * @adev: ACPI_COMPANION device to match.
> + */
> +static inline struct device *
> +class_find_device_by_acpi_dev(struct class *class, const struct acpi_device *adev)
> +{
> +	return class_find_device(class, NULL, adev, device_match_acpi_dev);
> +}
> +#else
> +static inline struct device *
> +class_find_device_by_acpi_dev(struct class *class, const void *adev)
> +{
> +	return NULL;
> +}
> +#endif
> +
>  struct class_attribute {
>  	struct attribute attr;
>  	ssize_t (*show)(struct class *class, struct class_attribute *attr,
> -- 
> 2.21.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 5/7] drivers: Introduce device lookup variants by ACPI_COMPANION device
@ 2019-07-26 20:23     ` Wolfram Sang
  0 siblings, 0 replies; 71+ messages in thread
From: Wolfram Sang @ 2019-07-26 20:23 UTC (permalink / raw)
  To: Suzuki K Poulose, Andy Shevchenko, Jarkko Nikula
  Cc: rafael, gregkh, linux-kernel, linux-spi, linux-acpi, Mark Brown,
	linux-i2c, Mika Westerberg, linux-arm-kernel, Len Brown


[-- Attachment #1.1: Type: text/plain, Size: 7404 bytes --]

On Tue, Jul 23, 2019 at 11:18:36PM +0100, Suzuki K Poulose wrote:
> Add a generic helper to match a device by the ACPI_COMPANION device
> and provide wrappers for the device lookup APIs.
> 
> Cc: Len Brown <lenb@kernel.org>
> Cc: linux-acpi@vger.kernel.org
> Cc: linux-spi@vger.kernel.org
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
> Cc: Wolfram Sang <wsa@the-dreams.de>
> Cc: linux-i2c@vger.kernel.org
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>

From my side, OK:

Acked-by: Wolfram Sang <wsa@the-dreams.de> # I2C parts

yet you missed to cc the I2C ACPI maintainers. Done so now.

> ---
>  drivers/base/core.c         |  6 ++++
>  drivers/i2c/i2c-core-acpi.c | 11 ++-----
>  drivers/spi/spi.c           |  8 +----
>  include/linux/device.h      | 65 +++++++++++++++++++++++++++++++++++++
>  4 files changed, 74 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 3abc32b60c0a..57d71bc2c559 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -3373,3 +3373,9 @@ int device_match_devt(struct device *dev, const void *pdevt)
>  	return dev->devt == *(dev_t *)pdevt;
>  }
>  EXPORT_SYMBOL_GPL(device_match_devt);
> +
> +int device_match_acpi_dev(struct device *dev, const void *adev)
> +{
> +	return ACPI_COMPANION(dev) == adev;
> +}
> +EXPORT_SYMBOL(device_match_acpi_dev);
> diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
> index 4dbbc9a35f65..bc80aafb521f 100644
> --- a/drivers/i2c/i2c-core-acpi.c
> +++ b/drivers/i2c/i2c-core-acpi.c
> @@ -354,17 +354,11 @@ static int i2c_acpi_find_match_adapter(struct device *dev, const void *data)
>  	return ACPI_HANDLE(dev) == (acpi_handle)data;
>  }
>  
> -static int i2c_acpi_find_match_device(struct device *dev, const void *data)
> -{
> -	return ACPI_COMPANION(dev) == data;
> -}
>  
>  struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle)
>  {
> -	struct device *dev;
> +	struct device *dev = bus_find_device_by_acpi_dev(&i2c_bus_type, handle);
>  
> -	dev = bus_find_device(&i2c_bus_type, NULL, handle,
> -			      i2c_acpi_find_match_adapter);
>  	return dev ? i2c_verify_adapter(dev) : NULL;
>  }
>  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)
>  {
>  	struct device *dev;
>  
> -	dev = bus_find_device(&i2c_bus_type, NULL, adev,
> -			      i2c_acpi_find_match_device);
> +	dev = bus_find_device_by_acpi_dev(&i2c_bus_type, adev);
>  	return dev ? i2c_verify_client(dev) : NULL;
>  }
>  
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index a591da87981a..c486a6f84c2c 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -3741,11 +3741,6 @@ static int spi_acpi_controller_match(struct device *dev, const void *data)
>  	return ACPI_COMPANION(dev->parent) == data;
>  }
>  
> -static int spi_acpi_device_match(struct device *dev, const void *data)
> -{
> -	return ACPI_COMPANION(dev) == data;
> -}
> -
>  static struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev)
>  {
>  	struct device *dev;
> @@ -3765,8 +3760,7 @@ static struct spi_device *acpi_spi_find_device_by_adev(struct acpi_device *adev)
>  {
>  	struct device *dev;
>  
> -	dev = bus_find_device(&spi_bus_type, NULL, adev, spi_acpi_device_match);
> -
> +	dev = bus_find_device_by_acpi_dev(&spi_bus_type, adev);
>  	return dev ? to_spi_device(dev) : NULL;
>  }
>  
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 93b2f55ef44e..7514ef3d3f1a 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -168,6 +168,7 @@ int device_match_name(struct device *dev, const void *name);
>  int device_match_of_node(struct device *dev, const void *np);
>  int device_match_fwnode(struct device *dev, const void *fwnode);
>  int device_match_devt(struct device *dev, const void *pdevt);
> +int device_match_acpi_dev(struct device *dev, const void *adev);
>  
>  int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
>  		     int (*fn)(struct device *dev, void *data));
> @@ -224,6 +225,28 @@ static inline struct device *bus_find_device_by_devt(struct bus_type *bus,
>  	return bus_find_device(bus, NULL, &devt, device_match_devt);
>  }
>  
> +#ifdef CONFIG_ACPI
> +struct acpi_device;
> +
> +/**
> + * bus_find_device_by_acpi_dev : device iterator for locating a particular device
> + * matching the ACPI COMPANION device.
> + * @bus: bus type
> + * @adev: ACPI COMPANION device to match.
> + */
> +static inline struct device *
> +bus_find_device_by_acpi_dev(struct bus_type *bus, const struct acpi_device *adev)
> +{
> +	return bus_find_device(bus, NULL, adev, device_match_acpi_dev);
> +}
> +#else
> +static inline struct device *
> +bus_find_device_by_acpi_dev(struct bus_type *bus, const void *adev)
> +{
> +	return NULL;
> +}
> +#endif
> +
>  struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
>  					struct device *hint);
>  int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
> @@ -442,6 +465,27 @@ static inline struct device *driver_find_device_by_devt(struct device_driver *dr
>  	return driver_find_device(drv, NULL, &devt, device_match_devt);
>  }
>  
> +#ifdef CONFIG_ACPI
> +/**
> + * driver_find_device_by_acpi_dev : device iterator for locating a particular
> + * device matching the ACPI_COMPANION device.
> + * @driver: the driver we're iterating
> + * @adev: ACPI_COMPANION device to match.
> + */
> +static inline struct device *
> +driver_find_device_by_acpi_dev(struct device_driver *drv,
> +			       const struct acpi_device *adev)
> +{
> +	return driver_find_device(drv, NULL, adev, device_match_acpi_dev);
> +}
> +#else
> +static inline struct device *
> +driver_find_device_by_acpi_dev(struct device_driver *drv, const void *adev)
> +{
> +	return NULL;
> +}
> +#endif
> +
>  void driver_deferred_probe_add(struct device *dev);
>  int driver_deferred_probe_check_state(struct device *dev);
>  int driver_deferred_probe_check_state_continue(struct device *dev);
> @@ -620,6 +664,27 @@ static inline struct device *class_find_device_by_devt(struct class *class,
>  	return class_find_device(class, NULL, &devt, device_match_devt);
>  }
>  
> +#ifdef CONFIG_ACPI
> +struct acpi_device;
> +/**
> + * class_find_device_by_acpi_dev : device iterator for locating a particular
> + * device matching the ACPI_COMPANION device.
> + * @class: class type
> + * @adev: ACPI_COMPANION device to match.
> + */
> +static inline struct device *
> +class_find_device_by_acpi_dev(struct class *class, const struct acpi_device *adev)
> +{
> +	return class_find_device(class, NULL, adev, device_match_acpi_dev);
> +}
> +#else
> +static inline struct device *
> +class_find_device_by_acpi_dev(struct class *class, const void *adev)
> +{
> +	return NULL;
> +}
> +#endif
> +
>  struct class_attribute {
>  	struct attribute attr;
>  	ssize_t (*show)(struct class *class, struct class_attribute *attr,
> -- 
> 2.21.0
> 

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 5/7] drivers: Introduce device lookup variants by ACPI_COMPANION device
@ 2019-07-26 20:23     ` Wolfram Sang
  0 siblings, 0 replies; 71+ messages in thread
From: Wolfram Sang @ 2019-07-26 20:23 UTC (permalink / raw)
  To: Suzuki K Poulose, Mika Westerberg, Andy Shevchenko, Jarkko Nikula
  Cc: rafael, gregkh, linux-kernel, linux-spi, linux-acpi, Mark Brown,
	linux-i2c, Mika Westerberg, linux-arm-kernel, Len Brown


[-- Attachment #1.1: Type: text/plain, Size: 7404 bytes --]

On Tue, Jul 23, 2019 at 11:18:36PM +0100, Suzuki K Poulose wrote:
> Add a generic helper to match a device by the ACPI_COMPANION device
> and provide wrappers for the device lookup APIs.
> 
> Cc: Len Brown <lenb@kernel.org>
> Cc: linux-acpi@vger.kernel.org
> Cc: linux-spi@vger.kernel.org
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
> Cc: Wolfram Sang <wsa@the-dreams.de>
> Cc: linux-i2c@vger.kernel.org
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>

From my side, OK:

Acked-by: Wolfram Sang <wsa@the-dreams.de> # I2C parts

yet you missed to cc the I2C ACPI maintainers. Done so now.

> ---
>  drivers/base/core.c         |  6 ++++
>  drivers/i2c/i2c-core-acpi.c | 11 ++-----
>  drivers/spi/spi.c           |  8 +----
>  include/linux/device.h      | 65 +++++++++++++++++++++++++++++++++++++
>  4 files changed, 74 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 3abc32b60c0a..57d71bc2c559 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -3373,3 +3373,9 @@ int device_match_devt(struct device *dev, const void *pdevt)
>  	return dev->devt == *(dev_t *)pdevt;
>  }
>  EXPORT_SYMBOL_GPL(device_match_devt);
> +
> +int device_match_acpi_dev(struct device *dev, const void *adev)
> +{
> +	return ACPI_COMPANION(dev) == adev;
> +}
> +EXPORT_SYMBOL(device_match_acpi_dev);
> diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
> index 4dbbc9a35f65..bc80aafb521f 100644
> --- a/drivers/i2c/i2c-core-acpi.c
> +++ b/drivers/i2c/i2c-core-acpi.c
> @@ -354,17 +354,11 @@ static int i2c_acpi_find_match_adapter(struct device *dev, const void *data)
>  	return ACPI_HANDLE(dev) == (acpi_handle)data;
>  }
>  
> -static int i2c_acpi_find_match_device(struct device *dev, const void *data)
> -{
> -	return ACPI_COMPANION(dev) == data;
> -}
>  
>  struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle)
>  {
> -	struct device *dev;
> +	struct device *dev = bus_find_device_by_acpi_dev(&i2c_bus_type, handle);
>  
> -	dev = bus_find_device(&i2c_bus_type, NULL, handle,
> -			      i2c_acpi_find_match_adapter);
>  	return dev ? i2c_verify_adapter(dev) : NULL;
>  }
>  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)
>  {
>  	struct device *dev;
>  
> -	dev = bus_find_device(&i2c_bus_type, NULL, adev,
> -			      i2c_acpi_find_match_device);
> +	dev = bus_find_device_by_acpi_dev(&i2c_bus_type, adev);
>  	return dev ? i2c_verify_client(dev) : NULL;
>  }
>  
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index a591da87981a..c486a6f84c2c 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -3741,11 +3741,6 @@ static int spi_acpi_controller_match(struct device *dev, const void *data)
>  	return ACPI_COMPANION(dev->parent) == data;
>  }
>  
> -static int spi_acpi_device_match(struct device *dev, const void *data)
> -{
> -	return ACPI_COMPANION(dev) == data;
> -}
> -
>  static struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev)
>  {
>  	struct device *dev;
> @@ -3765,8 +3760,7 @@ static struct spi_device *acpi_spi_find_device_by_adev(struct acpi_device *adev)
>  {
>  	struct device *dev;
>  
> -	dev = bus_find_device(&spi_bus_type, NULL, adev, spi_acpi_device_match);
> -
> +	dev = bus_find_device_by_acpi_dev(&spi_bus_type, adev);
>  	return dev ? to_spi_device(dev) : NULL;
>  }
>  
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 93b2f55ef44e..7514ef3d3f1a 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -168,6 +168,7 @@ int device_match_name(struct device *dev, const void *name);
>  int device_match_of_node(struct device *dev, const void *np);
>  int device_match_fwnode(struct device *dev, const void *fwnode);
>  int device_match_devt(struct device *dev, const void *pdevt);
> +int device_match_acpi_dev(struct device *dev, const void *adev);
>  
>  int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
>  		     int (*fn)(struct device *dev, void *data));
> @@ -224,6 +225,28 @@ static inline struct device *bus_find_device_by_devt(struct bus_type *bus,
>  	return bus_find_device(bus, NULL, &devt, device_match_devt);
>  }
>  
> +#ifdef CONFIG_ACPI
> +struct acpi_device;
> +
> +/**
> + * bus_find_device_by_acpi_dev : device iterator for locating a particular device
> + * matching the ACPI COMPANION device.
> + * @bus: bus type
> + * @adev: ACPI COMPANION device to match.
> + */
> +static inline struct device *
> +bus_find_device_by_acpi_dev(struct bus_type *bus, const struct acpi_device *adev)
> +{
> +	return bus_find_device(bus, NULL, adev, device_match_acpi_dev);
> +}
> +#else
> +static inline struct device *
> +bus_find_device_by_acpi_dev(struct bus_type *bus, const void *adev)
> +{
> +	return NULL;
> +}
> +#endif
> +
>  struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
>  					struct device *hint);
>  int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
> @@ -442,6 +465,27 @@ static inline struct device *driver_find_device_by_devt(struct device_driver *dr
>  	return driver_find_device(drv, NULL, &devt, device_match_devt);
>  }
>  
> +#ifdef CONFIG_ACPI
> +/**
> + * driver_find_device_by_acpi_dev : device iterator for locating a particular
> + * device matching the ACPI_COMPANION device.
> + * @driver: the driver we're iterating
> + * @adev: ACPI_COMPANION device to match.
> + */
> +static inline struct device *
> +driver_find_device_by_acpi_dev(struct device_driver *drv,
> +			       const struct acpi_device *adev)
> +{
> +	return driver_find_device(drv, NULL, adev, device_match_acpi_dev);
> +}
> +#else
> +static inline struct device *
> +driver_find_device_by_acpi_dev(struct device_driver *drv, const void *adev)
> +{
> +	return NULL;
> +}
> +#endif
> +
>  void driver_deferred_probe_add(struct device *dev);
>  int driver_deferred_probe_check_state(struct device *dev);
>  int driver_deferred_probe_check_state_continue(struct device *dev);
> @@ -620,6 +664,27 @@ static inline struct device *class_find_device_by_devt(struct class *class,
>  	return class_find_device(class, NULL, &devt, device_match_devt);
>  }
>  
> +#ifdef CONFIG_ACPI
> +struct acpi_device;
> +/**
> + * class_find_device_by_acpi_dev : device iterator for locating a particular
> + * device matching the ACPI_COMPANION device.
> + * @class: class type
> + * @adev: ACPI_COMPANION device to match.
> + */
> +static inline struct device *
> +class_find_device_by_acpi_dev(struct class *class, const struct acpi_device *adev)
> +{
> +	return class_find_device(class, NULL, adev, device_match_acpi_dev);
> +}
> +#else
> +static inline struct device *
> +class_find_device_by_acpi_dev(struct class *class, const void *adev)
> +{
> +	return NULL;
> +}
> +#endif
> +
>  struct class_attribute {
>  	struct attribute attr;
>  	ssize_t (*show)(struct class *class, struct class_attribute *attr,
> -- 
> 2.21.0
> 

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 3/7] drivers: Introduce device lookup variants by fwnode
  2019-07-23 22:18   ` Suzuki K Poulose
@ 2019-07-29 14:36     ` Heikki Krogerus
  -1 siblings, 0 replies; 71+ messages in thread
From: Heikki Krogerus @ 2019-07-29 14:36 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: linux-kernel, gregkh, rafael, linux-arm-kernel, David S. Miller,
	Doug Ledford, Jason Gunthorpe, linux-usb, Ulf Hansson,
	Joe Perches, Mathieu Poirier, Will Deacon, Robin Murphy,
	Joerg Roedel

On Tue, Jul 23, 2019 at 11:18:34PM +0100, Suzuki K Poulose wrote:
> Add a helper to match the firmware node handle of a device and provide
> wrappers for {bus/class/driver}_find_device() APIs to avoid proliferation
> of duplicate custom match functions.
> 
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Doug Ledford <dledford@redhat.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: linux-usb@vger.kernel.org
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: Joe Perches <joe@perches.com>
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Joerg Roedel <joro@8bytes.org>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/base/core.c                           |  6 +++
>  drivers/base/devcon.c                         |  8 +---
>  .../hwtracing/coresight/coresight-platform.c  | 11 +-----
>  drivers/hwtracing/coresight/coresight-priv.h  |  2 -
>  drivers/hwtracing/coresight/coresight.c       |  4 +-
>  drivers/infiniband/hw/hns/hns_roce_hw_v1.c    |  8 +---
>  drivers/iommu/arm-smmu-v3.c                   |  9 +----
>  drivers/iommu/arm-smmu.c                      |  9 +----
>  .../ethernet/hisilicon/hns/hns_dsaf_misc.c    |  8 +---
>  drivers/usb/roles/class.c                     |  8 +---
>  drivers/usb/typec/class.c                     |  8 +---
>  include/linux/device.h                        | 39 +++++++++++++++++++
>  12 files changed, 57 insertions(+), 63 deletions(-)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index fb83647d685a..e8f81a667545 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -3368,3 +3368,9 @@ int device_match_of_node(struct device *dev, const void *np)
>  	return dev->of_node == np;
>  }
>  EXPORT_SYMBOL_GPL(device_match_of_node);
> +
> +int device_match_fwnode(struct device *dev, const void *fwnode)
> +{
> +	return dev_fwnode(dev) == fwnode;
> +}
> +EXPORT_SYMBOL_GPL(device_match_fwnode);
> diff --git a/drivers/base/devcon.c b/drivers/base/devcon.c
> index 09f28479b243..1d488dc5dd0c 100644
> --- a/drivers/base/devcon.c
> +++ b/drivers/base/devcon.c
> @@ -133,19 +133,13 @@ static struct bus_type *generic_match_buses[] = {
>  	NULL,
>  };
>  
> -static int device_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>  static void *device_connection_fwnode_match(struct device_connection *con)
>  {
>  	struct bus_type *bus;
>  	struct device *dev;
>  
>  	for (bus = generic_match_buses[0]; bus; bus++) {
> -		dev = bus_find_device(bus, NULL, (void *)con->fwnode,
> -				      device_fwnode_match);
> +		dev = bus_find_device_by_fwnode(bus, con->fwnode);
>  		if (dev && !strncmp(dev_name(dev), con->id, strlen(con->id)))
>  			return dev;
>  
> diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
> index dad7d96c5943..3c5bee429105 100644
> --- a/drivers/hwtracing/coresight/coresight-platform.c
> +++ b/drivers/hwtracing/coresight/coresight-platform.c
> @@ -37,11 +37,6 @@ static int coresight_alloc_conns(struct device *dev,
>  	return 0;
>  }
>  
> -int coresight_device_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>  static struct device *
>  coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
>  {
> @@ -51,8 +46,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
>  	 * If we have a non-configurable replicator, it will be found on the
>  	 * platform bus.
>  	 */
> -	dev = bus_find_device(&platform_bus_type, NULL,
> -			      fwnode, coresight_device_fwnode_match);
> +	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
>  	if (dev)
>  		return dev;
>  
> @@ -60,8 +54,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
>  	 * We have a configurable component - circle through the AMBA bus
>  	 * looking for the device that matches the endpoint node.
>  	 */
> -	return bus_find_device(&amba_bustype, NULL,
> -			       fwnode, coresight_device_fwnode_match);
> +	return bus_find_device_by_fwnode(&amba_bustype, fwnode);
>  }
>  
>  #ifdef CONFIG_OF
> diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
> index 7d401790dd7e..61d7f9ff054d 100644
> --- a/drivers/hwtracing/coresight/coresight-priv.h
> +++ b/drivers/hwtracing/coresight/coresight-priv.h
> @@ -202,6 +202,4 @@ static inline void *coresight_get_uci_data(const struct amba_id *id)
>  
>  void coresight_release_platform_data(struct coresight_platform_data *pdata);
>  
> -int coresight_device_fwnode_match(struct device *dev, const void *fwnode);
> -
>  #endif
> diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
> index 55db77f6410b..6453c67a4d01 100644
> --- a/drivers/hwtracing/coresight/coresight.c
> +++ b/drivers/hwtracing/coresight/coresight.c
> @@ -1046,9 +1046,7 @@ static void coresight_fixup_device_conns(struct coresight_device *csdev)
>  		struct coresight_connection *conn = &csdev->pdata->conns[i];
>  		struct device *dev = NULL;
>  
> -		dev = bus_find_device(&coresight_bustype, NULL,
> -				      (void *)conn->child_fwnode,
> -				      coresight_device_fwnode_match);
> +		dev = bus_find_device_by_fwnode(&coresight_bustype, conn->child_fwnode);
>  		if (dev) {
>  			conn->child_dev = to_coresight_device(dev);
>  			/* and put reference from 'bus_find_device()' */
> diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> index 81e6dedb1e02..fa05e943038a 100644
> --- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> @@ -4499,19 +4499,13 @@ static const struct acpi_device_id hns_roce_acpi_match[] = {
>  };
>  MODULE_DEVICE_TABLE(acpi, hns_roce_acpi_match);
>  
> -static int hns_roce_node_match(struct device *dev, const void *fwnode)
> -{
> -	return dev->fwnode == fwnode;
> -}
> -
>  static struct
>  platform_device *hns_roce_find_pdev(struct fwnode_handle *fwnode)
>  {
>  	struct device *dev;
>  
>  	/* get the 'device' corresponding to the matching 'fwnode' */
> -	dev = bus_find_device(&platform_bus_type, NULL,
> -			      fwnode, hns_roce_node_match);
> +	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
>  	/* get the platform device */
>  	return dev ? to_platform_device(dev) : NULL;
>  }
> diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c
> index a9a9fabd3968..6f0e13fa5e1a 100644
> --- a/drivers/iommu/arm-smmu-v3.c
> +++ b/drivers/iommu/arm-smmu-v3.c
> @@ -2034,16 +2034,11 @@ arm_smmu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova)
>  
>  static struct platform_driver arm_smmu_driver;
>  
> -static int arm_smmu_match_node(struct device *dev, const void *data)
> -{
> -	return dev->fwnode == data;
> -}
> -
>  static
>  struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
>  {
> -	struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL,
> -						fwnode, arm_smmu_match_node);
> +	struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver,
> +							  fwnode);
>  	put_device(dev);
>  	return dev ? dev_get_drvdata(dev) : NULL;
>  }
> diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
> index 64977c131ee6..aa06498f291d 100644
> --- a/drivers/iommu/arm-smmu.c
> +++ b/drivers/iommu/arm-smmu.c
> @@ -1426,16 +1426,11 @@ static bool arm_smmu_capable(enum iommu_cap cap)
>  	}
>  }
>  
> -static int arm_smmu_match_node(struct device *dev, const void *data)
> -{
> -	return dev->fwnode == data;
> -}
> -
>  static
>  struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
>  {
> -	struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL,
> -						fwnode, arm_smmu_match_node);
> +	struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver,
> +							  fwnode);
>  	put_device(dev);
>  	return dev ? dev_get_drvdata(dev) : NULL;
>  }
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
> index bb6586d0e5af..ed3829ae4ef1 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
> @@ -754,17 +754,11 @@ struct dsaf_misc_op *hns_misc_op_get(struct dsaf_device *dsaf_dev)
>  	return (void *)misc_op;
>  }
>  
> -static int hns_dsaf_dev_match(struct device *dev, const void *fwnode)
> -{
> -	return dev->fwnode == fwnode;
> -}
> -
>  struct
>  platform_device *hns_dsaf_find_platform_device(struct fwnode_handle *fwnode)
>  {
>  	struct device *dev;
>  
> -	dev = bus_find_device(&platform_bus_type, NULL,
> -			      fwnode, hns_dsaf_dev_match);
> +	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
>  	return dev ? to_platform_device(dev) : NULL;
>  }
> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
> index c8efe60e2465..0526efbc4922 100644
> --- a/drivers/usb/roles/class.c
> +++ b/drivers/usb/roles/class.c
> @@ -85,11 +85,6 @@ enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw)
>  }
>  EXPORT_SYMBOL_GPL(usb_role_switch_get_role);
>  
> -static int switch_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>  static void *usb_role_switch_match(struct device_connection *con, int ep,
>  				   void *data)
>  {
> @@ -99,8 +94,7 @@ static void *usb_role_switch_match(struct device_connection *con, int ep,
>  		if (con->id && !fwnode_property_present(con->fwnode, con->id))
>  			return NULL;
>  
> -		dev = class_find_device(role_class, NULL, con->fwnode,
> -					switch_fwnode_match);
> +		dev = class_find_device_by_fwnode(role_class, con->fwnode);
>  	} else {
>  		dev = class_find_device_by_name(role_class, con->endpoint[ep]);
>  	}
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 9b0d15b487e5..94a3eda62add 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -205,11 +205,6 @@ static void typec_altmode_put_partner(struct altmode *altmode)
>  	put_device(&adev->dev);
>  }
>  
> -static int typec_port_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>  static void *typec_port_match(struct device_connection *con, int ep, void *data)
>  {
>  	struct device *dev;
> @@ -219,8 +214,7 @@ static void *typec_port_match(struct device_connection *con, int ep, void *data)
>  	 * we need to return ERR_PTR(-PROBE_DEFER) when there is no device.
>  	 */
>  	if (con->fwnode)
> -		return class_find_device(typec_class, NULL, con->fwnode,
> -					 typec_port_fwnode_match);
> +		return class_find_device_by_fwnode(typec_class, con->fwnode);
>  
>  	dev = class_find_device_by_name(typec_class, con->endpoint[ep]);
>  
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 29d8d7ad41e6..7133fc1c285d 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -166,6 +166,7 @@ void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
>  
>  int device_match_name(struct device *dev, const void *name);
>  int device_match_of_node(struct device *dev, const void *np);
> +int device_match_fwnode(struct device *dev, const void *fwnode);
>  
>  int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
>  		     int (*fn)(struct device *dev, void *data));
> @@ -198,6 +199,18 @@ bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
>  	return bus_find_device(bus, NULL, np, device_match_of_node);
>  }
>  
> +/**
> + * bus_find_device_by_fwnode : device iterator for locating a particular device
> + * matching the fwnode.
> + * @bus: bus type
> + * @fwnode: fwnode of the device to match.
> + */
> +static inline struct device *
> +bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwnode)
> +{
> +	return bus_find_device(bus, NULL, fwnode, device_match_fwnode);
> +}
> +
>  struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
>  					struct device *hint);
>  int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
> @@ -391,6 +404,19 @@ driver_find_device_by_of_node(struct device_driver *drv,
>  	return driver_find_device(drv, NULL, np, device_match_of_node);
>  }
>  
> +/**
> + * driver_find_device_by_fwnode- device iterator for locating a particular device
> + * by fwnode pointer.
> + * @driver: the driver we're iterating
> + * @fwnode: fwnode pointer to match.
> + */
> +static inline struct device *
> +driver_find_device_by_fwnode(struct device_driver *drv,
> +			     const struct fwnode_handle *fwnode)
> +{
> +	return driver_find_device(drv, NULL, fwnode, device_match_fwnode);
> +}
> +
>  void driver_deferred_probe_add(struct device *dev);
>  int driver_deferred_probe_check_state(struct device *dev);
>  int driver_deferred_probe_check_state_continue(struct device *dev);
> @@ -544,6 +570,19 @@ class_find_device_by_of_node(struct class *class, const struct device_node *np)
>  	return class_find_device(class, NULL, np, device_match_of_node);
>  }
>  
> +/**
> + * class_find_device_by_fwnode : device iterator for locating a particular device
> + * matching the fwnode.
> + * @class: class type
> + * @fwnode: fwnode of the device to match.
> + */
> +static inline struct device *
> +class_find_device_by_fwnode(struct class *class,
> +			    const struct fwnode_handle *fwnode)
> +{
> +	return class_find_device(class, NULL, fwnode, device_match_fwnode);
> +}
> +
>  struct class_attribute {
>  	struct attribute attr;
>  	ssize_t (*show)(struct class *class, struct class_attribute *attr,
> -- 
> 2.21.0

thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 3/7] drivers: Introduce device lookup variants by fwnode
@ 2019-07-29 14:36     ` Heikki Krogerus
  0 siblings, 0 replies; 71+ messages in thread
From: Heikki Krogerus @ 2019-07-29 14:36 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Ulf Hansson, Mathieu Poirier, rafael, gregkh, Joerg Roedel,
	linux-usb, Will Deacon, linux-kernel, Jason Gunthorpe,
	Doug Ledford, Joe Perches, Robin Murphy, David S. Miller,
	linux-arm-kernel

On Tue, Jul 23, 2019 at 11:18:34PM +0100, Suzuki K Poulose wrote:
> Add a helper to match the firmware node handle of a device and provide
> wrappers for {bus/class/driver}_find_device() APIs to avoid proliferation
> of duplicate custom match functions.
> 
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Doug Ledford <dledford@redhat.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: linux-usb@vger.kernel.org
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: Joe Perches <joe@perches.com>
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Joerg Roedel <joro@8bytes.org>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/base/core.c                           |  6 +++
>  drivers/base/devcon.c                         |  8 +---
>  .../hwtracing/coresight/coresight-platform.c  | 11 +-----
>  drivers/hwtracing/coresight/coresight-priv.h  |  2 -
>  drivers/hwtracing/coresight/coresight.c       |  4 +-
>  drivers/infiniband/hw/hns/hns_roce_hw_v1.c    |  8 +---
>  drivers/iommu/arm-smmu-v3.c                   |  9 +----
>  drivers/iommu/arm-smmu.c                      |  9 +----
>  .../ethernet/hisilicon/hns/hns_dsaf_misc.c    |  8 +---
>  drivers/usb/roles/class.c                     |  8 +---
>  drivers/usb/typec/class.c                     |  8 +---
>  include/linux/device.h                        | 39 +++++++++++++++++++
>  12 files changed, 57 insertions(+), 63 deletions(-)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index fb83647d685a..e8f81a667545 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -3368,3 +3368,9 @@ int device_match_of_node(struct device *dev, const void *np)
>  	return dev->of_node == np;
>  }
>  EXPORT_SYMBOL_GPL(device_match_of_node);
> +
> +int device_match_fwnode(struct device *dev, const void *fwnode)
> +{
> +	return dev_fwnode(dev) == fwnode;
> +}
> +EXPORT_SYMBOL_GPL(device_match_fwnode);
> diff --git a/drivers/base/devcon.c b/drivers/base/devcon.c
> index 09f28479b243..1d488dc5dd0c 100644
> --- a/drivers/base/devcon.c
> +++ b/drivers/base/devcon.c
> @@ -133,19 +133,13 @@ static struct bus_type *generic_match_buses[] = {
>  	NULL,
>  };
>  
> -static int device_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>  static void *device_connection_fwnode_match(struct device_connection *con)
>  {
>  	struct bus_type *bus;
>  	struct device *dev;
>  
>  	for (bus = generic_match_buses[0]; bus; bus++) {
> -		dev = bus_find_device(bus, NULL, (void *)con->fwnode,
> -				      device_fwnode_match);
> +		dev = bus_find_device_by_fwnode(bus, con->fwnode);
>  		if (dev && !strncmp(dev_name(dev), con->id, strlen(con->id)))
>  			return dev;
>  
> diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
> index dad7d96c5943..3c5bee429105 100644
> --- a/drivers/hwtracing/coresight/coresight-platform.c
> +++ b/drivers/hwtracing/coresight/coresight-platform.c
> @@ -37,11 +37,6 @@ static int coresight_alloc_conns(struct device *dev,
>  	return 0;
>  }
>  
> -int coresight_device_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>  static struct device *
>  coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
>  {
> @@ -51,8 +46,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
>  	 * If we have a non-configurable replicator, it will be found on the
>  	 * platform bus.
>  	 */
> -	dev = bus_find_device(&platform_bus_type, NULL,
> -			      fwnode, coresight_device_fwnode_match);
> +	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
>  	if (dev)
>  		return dev;
>  
> @@ -60,8 +54,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
>  	 * We have a configurable component - circle through the AMBA bus
>  	 * looking for the device that matches the endpoint node.
>  	 */
> -	return bus_find_device(&amba_bustype, NULL,
> -			       fwnode, coresight_device_fwnode_match);
> +	return bus_find_device_by_fwnode(&amba_bustype, fwnode);
>  }
>  
>  #ifdef CONFIG_OF
> diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
> index 7d401790dd7e..61d7f9ff054d 100644
> --- a/drivers/hwtracing/coresight/coresight-priv.h
> +++ b/drivers/hwtracing/coresight/coresight-priv.h
> @@ -202,6 +202,4 @@ static inline void *coresight_get_uci_data(const struct amba_id *id)
>  
>  void coresight_release_platform_data(struct coresight_platform_data *pdata);
>  
> -int coresight_device_fwnode_match(struct device *dev, const void *fwnode);
> -
>  #endif
> diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
> index 55db77f6410b..6453c67a4d01 100644
> --- a/drivers/hwtracing/coresight/coresight.c
> +++ b/drivers/hwtracing/coresight/coresight.c
> @@ -1046,9 +1046,7 @@ static void coresight_fixup_device_conns(struct coresight_device *csdev)
>  		struct coresight_connection *conn = &csdev->pdata->conns[i];
>  		struct device *dev = NULL;
>  
> -		dev = bus_find_device(&coresight_bustype, NULL,
> -				      (void *)conn->child_fwnode,
> -				      coresight_device_fwnode_match);
> +		dev = bus_find_device_by_fwnode(&coresight_bustype, conn->child_fwnode);
>  		if (dev) {
>  			conn->child_dev = to_coresight_device(dev);
>  			/* and put reference from 'bus_find_device()' */
> diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> index 81e6dedb1e02..fa05e943038a 100644
> --- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> @@ -4499,19 +4499,13 @@ static const struct acpi_device_id hns_roce_acpi_match[] = {
>  };
>  MODULE_DEVICE_TABLE(acpi, hns_roce_acpi_match);
>  
> -static int hns_roce_node_match(struct device *dev, const void *fwnode)
> -{
> -	return dev->fwnode == fwnode;
> -}
> -
>  static struct
>  platform_device *hns_roce_find_pdev(struct fwnode_handle *fwnode)
>  {
>  	struct device *dev;
>  
>  	/* get the 'device' corresponding to the matching 'fwnode' */
> -	dev = bus_find_device(&platform_bus_type, NULL,
> -			      fwnode, hns_roce_node_match);
> +	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
>  	/* get the platform device */
>  	return dev ? to_platform_device(dev) : NULL;
>  }
> diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c
> index a9a9fabd3968..6f0e13fa5e1a 100644
> --- a/drivers/iommu/arm-smmu-v3.c
> +++ b/drivers/iommu/arm-smmu-v3.c
> @@ -2034,16 +2034,11 @@ arm_smmu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova)
>  
>  static struct platform_driver arm_smmu_driver;
>  
> -static int arm_smmu_match_node(struct device *dev, const void *data)
> -{
> -	return dev->fwnode == data;
> -}
> -
>  static
>  struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
>  {
> -	struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL,
> -						fwnode, arm_smmu_match_node);
> +	struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver,
> +							  fwnode);
>  	put_device(dev);
>  	return dev ? dev_get_drvdata(dev) : NULL;
>  }
> diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
> index 64977c131ee6..aa06498f291d 100644
> --- a/drivers/iommu/arm-smmu.c
> +++ b/drivers/iommu/arm-smmu.c
> @@ -1426,16 +1426,11 @@ static bool arm_smmu_capable(enum iommu_cap cap)
>  	}
>  }
>  
> -static int arm_smmu_match_node(struct device *dev, const void *data)
> -{
> -	return dev->fwnode == data;
> -}
> -
>  static
>  struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
>  {
> -	struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL,
> -						fwnode, arm_smmu_match_node);
> +	struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver,
> +							  fwnode);
>  	put_device(dev);
>  	return dev ? dev_get_drvdata(dev) : NULL;
>  }
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
> index bb6586d0e5af..ed3829ae4ef1 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
> @@ -754,17 +754,11 @@ struct dsaf_misc_op *hns_misc_op_get(struct dsaf_device *dsaf_dev)
>  	return (void *)misc_op;
>  }
>  
> -static int hns_dsaf_dev_match(struct device *dev, const void *fwnode)
> -{
> -	return dev->fwnode == fwnode;
> -}
> -
>  struct
>  platform_device *hns_dsaf_find_platform_device(struct fwnode_handle *fwnode)
>  {
>  	struct device *dev;
>  
> -	dev = bus_find_device(&platform_bus_type, NULL,
> -			      fwnode, hns_dsaf_dev_match);
> +	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
>  	return dev ? to_platform_device(dev) : NULL;
>  }
> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
> index c8efe60e2465..0526efbc4922 100644
> --- a/drivers/usb/roles/class.c
> +++ b/drivers/usb/roles/class.c
> @@ -85,11 +85,6 @@ enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw)
>  }
>  EXPORT_SYMBOL_GPL(usb_role_switch_get_role);
>  
> -static int switch_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>  static void *usb_role_switch_match(struct device_connection *con, int ep,
>  				   void *data)
>  {
> @@ -99,8 +94,7 @@ static void *usb_role_switch_match(struct device_connection *con, int ep,
>  		if (con->id && !fwnode_property_present(con->fwnode, con->id))
>  			return NULL;
>  
> -		dev = class_find_device(role_class, NULL, con->fwnode,
> -					switch_fwnode_match);
> +		dev = class_find_device_by_fwnode(role_class, con->fwnode);
>  	} else {
>  		dev = class_find_device_by_name(role_class, con->endpoint[ep]);
>  	}
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 9b0d15b487e5..94a3eda62add 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -205,11 +205,6 @@ static void typec_altmode_put_partner(struct altmode *altmode)
>  	put_device(&adev->dev);
>  }
>  
> -static int typec_port_fwnode_match(struct device *dev, const void *fwnode)
> -{
> -	return dev_fwnode(dev) == fwnode;
> -}
> -
>  static void *typec_port_match(struct device_connection *con, int ep, void *data)
>  {
>  	struct device *dev;
> @@ -219,8 +214,7 @@ static void *typec_port_match(struct device_connection *con, int ep, void *data)
>  	 * we need to return ERR_PTR(-PROBE_DEFER) when there is no device.
>  	 */
>  	if (con->fwnode)
> -		return class_find_device(typec_class, NULL, con->fwnode,
> -					 typec_port_fwnode_match);
> +		return class_find_device_by_fwnode(typec_class, con->fwnode);
>  
>  	dev = class_find_device_by_name(typec_class, con->endpoint[ep]);
>  
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 29d8d7ad41e6..7133fc1c285d 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -166,6 +166,7 @@ void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
>  
>  int device_match_name(struct device *dev, const void *name);
>  int device_match_of_node(struct device *dev, const void *np);
> +int device_match_fwnode(struct device *dev, const void *fwnode);
>  
>  int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
>  		     int (*fn)(struct device *dev, void *data));
> @@ -198,6 +199,18 @@ bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
>  	return bus_find_device(bus, NULL, np, device_match_of_node);
>  }
>  
> +/**
> + * bus_find_device_by_fwnode : device iterator for locating a particular device
> + * matching the fwnode.
> + * @bus: bus type
> + * @fwnode: fwnode of the device to match.
> + */
> +static inline struct device *
> +bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwnode)
> +{
> +	return bus_find_device(bus, NULL, fwnode, device_match_fwnode);
> +}
> +
>  struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
>  					struct device *hint);
>  int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
> @@ -391,6 +404,19 @@ driver_find_device_by_of_node(struct device_driver *drv,
>  	return driver_find_device(drv, NULL, np, device_match_of_node);
>  }
>  
> +/**
> + * driver_find_device_by_fwnode- device iterator for locating a particular device
> + * by fwnode pointer.
> + * @driver: the driver we're iterating
> + * @fwnode: fwnode pointer to match.
> + */
> +static inline struct device *
> +driver_find_device_by_fwnode(struct device_driver *drv,
> +			     const struct fwnode_handle *fwnode)
> +{
> +	return driver_find_device(drv, NULL, fwnode, device_match_fwnode);
> +}
> +
>  void driver_deferred_probe_add(struct device *dev);
>  int driver_deferred_probe_check_state(struct device *dev);
>  int driver_deferred_probe_check_state_continue(struct device *dev);
> @@ -544,6 +570,19 @@ class_find_device_by_of_node(struct class *class, const struct device_node *np)
>  	return class_find_device(class, NULL, np, device_match_of_node);
>  }
>  
> +/**
> + * class_find_device_by_fwnode : device iterator for locating a particular device
> + * matching the fwnode.
> + * @class: class type
> + * @fwnode: fwnode of the device to match.
> + */
> +static inline struct device *
> +class_find_device_by_fwnode(struct class *class,
> +			    const struct fwnode_handle *fwnode)
> +{
> +	return class_find_device(class, NULL, fwnode, device_match_fwnode);
> +}
> +
>  struct class_attribute {
>  	struct attribute attr;
>  	ssize_t (*show)(struct class *class, struct class_attribute *attr,
> -- 
> 2.21.0

thanks,

-- 
heikki

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 1/7] drivers: Introduce device lookup variants by name
  2019-07-23 22:18   ` Suzuki K Poulose
@ 2019-07-29 14:37     ` Heikki Krogerus
  -1 siblings, 0 replies; 71+ messages in thread
From: Heikki Krogerus @ 2019-07-29 14:37 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: linux-kernel, gregkh, rafael, linux-arm-kernel, Alessandro Zummo,
	Alexander Aring, Alexander Shishkin, Alexandre Belloni,
	Arnd Bergmann, Dan Murphy, Harald Freudenberger, Heiko Carstens,
	Jacek Anaszewski, Lee Jones, linux-leds, linux-rtc, linux-usb,
	linux-wpan, Maxime Coquelin, Pavel Machek, Peter Oberparleiter,
	Stefan Schmidt, Rafael J. Wysocki

On Tue, Jul 23, 2019 at 11:18:32PM +0100, Suzuki K Poulose wrote:
> Add a helper to match the device name for device lookup. Also
> reuse this generic exported helper for the existing bus_find_device_by_name().
> and add similar variants for driver/class.
> 
> Cc: Alessandro Zummo <a.zummo@towertech.it>
> Cc: Alexander Aring <alex.aring@gmail.com>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Dan Murphy <dmurphy@ti.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Harald Freudenberger <freude@linux.ibm.com>
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
> Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com>
> Cc: Lee Jones <lee.jones@linaro.org>
> Cc: linux-leds@vger.kernel.org
> Cc: linux-rtc@vger.kernel.org
> Cc: linux-usb@vger.kernel.org
> Cc: linux-wpan@vger.kernel.org
> Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
> Cc: Pavel Machek <pavel@ucw.cz>
> Cc: Peter Oberparleiter <oberpar@linux.ibm.com>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Stefan Schmidt <stefan@datenfreihafen.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.coM>

> ---
>  drivers/base/bus.c               | 24 ------------------
>  drivers/base/core.c              |  6 +++++
>  drivers/hwtracing/stm/core.c     |  9 +------
>  drivers/leds/led-class.c         |  9 +------
>  drivers/rtc/interface.c          | 11 +--------
>  drivers/s390/cio/ccwgroup.c      | 10 +-------
>  drivers/s390/cio/device.c        | 15 +-----------
>  drivers/s390/crypto/zcrypt_api.c | 11 +--------
>  drivers/usb/roles/class.c        |  8 +-----
>  drivers/usb/typec/class.c        |  8 +-----
>  include/linux/device.h           | 42 +++++++++++++++++++++++++++++---
>  net/ieee802154/core.c            |  7 +-----
>  12 files changed, 54 insertions(+), 106 deletions(-)
> 
> diff --git a/drivers/base/bus.c b/drivers/base/bus.c
> index df3cac739813..a1d1e8256324 100644
> --- a/drivers/base/bus.c
> +++ b/drivers/base/bus.c
> @@ -342,30 +342,6 @@ struct device *bus_find_device(struct bus_type *bus,
>  }
>  EXPORT_SYMBOL_GPL(bus_find_device);
>  
> -static int match_name(struct device *dev, const void *data)
> -{
> -	const char *name = data;
> -
> -	return sysfs_streq(name, dev_name(dev));
> -}
> -
> -/**
> - * bus_find_device_by_name - device iterator for locating a particular device of a specific name
> - * @bus: bus type
> - * @start: Device to begin with
> - * @name: name of the device to match
> - *
> - * This is similar to the bus_find_device() function above, but it handles
> - * searching by a name automatically, no need to write another strcmp matching
> - * function.
> - */
> -struct device *bus_find_device_by_name(struct bus_type *bus,
> -				       struct device *start, const char *name)
> -{
> -	return bus_find_device(bus, start, (void *)name, match_name);
> -}
> -EXPORT_SYMBOL_GPL(bus_find_device_by_name);
> -
>  /**
>   * subsys_find_device_by_id - find a device with a specific enumeration number
>   * @subsys: subsystem
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index da84a73f2ba6..fb83647d685a 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -3357,6 +3357,12 @@ void device_set_of_node_from_dev(struct device *dev, const struct device *dev2)
>  }
>  EXPORT_SYMBOL_GPL(device_set_of_node_from_dev);
>  
> +int device_match_name(struct device *dev, const void *name)
> +{
> +	return sysfs_streq(dev_name(dev), name);
> +}
> +EXPORT_SYMBOL_GPL(device_match_name);
> +
>  int device_match_of_node(struct device *dev, const void *np)
>  {
>  	return dev->of_node == np;
> diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
> index e55b902560de..2b6bd42632e8 100644
> --- a/drivers/hwtracing/stm/core.c
> +++ b/drivers/hwtracing/stm/core.c
> @@ -89,13 +89,6 @@ static struct class stm_class = {
>  	.dev_groups	= stm_groups,
>  };
>  
> -static int stm_dev_match(struct device *dev, const void *data)
> -{
> -	const char *name = data;
> -
> -	return sysfs_streq(name, dev_name(dev));
> -}
> -
>  /**
>   * stm_find_device() - find stm device by name
>   * @buf:	character buffer containing the name
> @@ -116,7 +109,7 @@ struct stm_device *stm_find_device(const char *buf)
>  	if (!stm_core_up)
>  		return NULL;
>  
> -	dev = class_find_device(&stm_class, NULL, buf, stm_dev_match);
> +	dev = class_find_device_by_name(&stm_class, buf);
>  	if (!dev)
>  		return NULL;
>  
> diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
> index 4793e77808e2..d54c8e4d8954 100644
> --- a/drivers/leds/led-class.c
> +++ b/drivers/leds/led-class.c
> @@ -213,13 +213,6 @@ static int led_resume(struct device *dev)
>  
>  static SIMPLE_DEV_PM_OPS(leds_class_dev_pm_ops, led_suspend, led_resume);
>  
> -static int match_name(struct device *dev, const void *data)
> -{
> -	if (!dev_name(dev))
> -		return 0;
> -	return !strcmp(dev_name(dev), (char *)data);
> -}
> -
>  static int led_classdev_next_name(const char *init_name, char *name,
>  				  size_t len)
>  {
> @@ -230,7 +223,7 @@ static int led_classdev_next_name(const char *init_name, char *name,
>  	strlcpy(name, init_name, len);
>  
>  	while ((ret < len) &&
> -	       (dev = class_find_device(leds_class, NULL, name, match_name))) {
> +	       (dev = class_find_device_by_name(leds_class, name))) {
>  		put_device(dev);
>  		ret = snprintf(name, len, "%s_%u", init_name, ++i);
>  	}
> diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
> index 72b7ddc43116..c93ef33b01d3 100644
> --- a/drivers/rtc/interface.c
> +++ b/drivers/rtc/interface.c
> @@ -663,21 +663,12 @@ void rtc_update_irq(struct rtc_device *rtc,
>  }
>  EXPORT_SYMBOL_GPL(rtc_update_irq);
>  
> -static int __rtc_match(struct device *dev, const void *data)
> -{
> -	const char *name = data;
> -
> -	if (strcmp(dev_name(dev), name) == 0)
> -		return 1;
> -	return 0;
> -}
> -
>  struct rtc_device *rtc_class_open(const char *name)
>  {
>  	struct device *dev;
>  	struct rtc_device *rtc = NULL;
>  
> -	dev = class_find_device(rtc_class, NULL, name, __rtc_match);
> +	dev = class_find_device_by_name(rtc_class, name);
>  	if (dev)
>  		rtc = to_rtc_device(dev);
>  
> diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
> index c522e9313c50..d843e362c167 100644
> --- a/drivers/s390/cio/ccwgroup.c
> +++ b/drivers/s390/cio/ccwgroup.c
> @@ -608,13 +608,6 @@ void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver)
>  }
>  EXPORT_SYMBOL(ccwgroup_driver_unregister);
>  
> -static int __ccwgroupdev_check_busid(struct device *dev, const void *id)
> -{
> -	const char *bus_id = id;
> -
> -	return (strcmp(bus_id, dev_name(dev)) == 0);
> -}
> -
>  /**
>   * get_ccwgroupdev_by_busid() - obtain device from a bus id
>   * @gdrv: driver the device is owned by
> @@ -631,8 +624,7 @@ struct ccwgroup_device *get_ccwgroupdev_by_busid(struct ccwgroup_driver *gdrv,
>  {
>  	struct device *dev;
>  
> -	dev = driver_find_device(&gdrv->driver, NULL, bus_id,
> -				 __ccwgroupdev_check_busid);
> +	dev = driver_find_device_by_name(&gdrv->driver, bus_id);
>  
>  	return dev ? to_ccwgroupdev(dev) : NULL;
>  }
> diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
> index c421899be20f..131430bd48d9 100644
> --- a/drivers/s390/cio/device.c
> +++ b/drivers/s390/cio/device.c
> @@ -1695,18 +1695,6 @@ int ccw_device_force_console(struct ccw_device *cdev)
>  EXPORT_SYMBOL_GPL(ccw_device_force_console);
>  #endif
>  
> -/*
> - * get ccw_device matching the busid, but only if owned by cdrv
> - */
> -static int
> -__ccwdev_check_busid(struct device *dev, const void *id)
> -{
> -	const char *bus_id = id;
> -
> -	return (strcmp(bus_id, dev_name(dev)) == 0);
> -}
> -
> -
>  /**
>   * get_ccwdev_by_busid() - obtain device from a bus id
>   * @cdrv: driver the device is owned by
> @@ -1723,8 +1711,7 @@ struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
>  {
>  	struct device *dev;
>  
> -	dev = driver_find_device(&cdrv->driver, NULL, (void *)bus_id,
> -				 __ccwdev_check_busid);
> +	dev = driver_find_device_by_name(&cdrv->driver, bus_id);
>  
>  	return dev ? to_ccwdev(dev) : NULL;
>  }
> diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c
> index 1058b4b5cc1e..38a5a47b8c9c 100644
> --- a/drivers/s390/crypto/zcrypt_api.c
> +++ b/drivers/s390/crypto/zcrypt_api.c
> @@ -133,12 +133,6 @@ struct zcdn_device {
>  static int zcdn_create(const char *name);
>  static int zcdn_destroy(const char *name);
>  
> -/* helper function, matches the name for find_zcdndev_by_name() */
> -static int __match_zcdn_name(struct device *dev, const void *data)
> -{
> -	return strcmp(dev_name(dev), (const char *)data) == 0;
> -}
> -
>  /* helper function, matches the devt value for find_zcdndev_by_devt() */
>  static int __match_zcdn_devt(struct device *dev, const void *data)
>  {
> @@ -152,10 +146,7 @@ static int __match_zcdn_devt(struct device *dev, const void *data)
>   */
>  static inline struct zcdn_device *find_zcdndev_by_name(const char *name)
>  {
> -	struct device *dev =
> -		class_find_device(zcrypt_class, NULL,
> -				  (void *) name,
> -				  __match_zcdn_name);
> +	struct device *dev = class_find_device_by_name(zcrypt_class, name);
>  
>  	return dev ? to_zcdn_dev(dev) : NULL;
>  }
> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
> index 86defca6623e..c8efe60e2465 100644
> --- a/drivers/usb/roles/class.c
> +++ b/drivers/usb/roles/class.c
> @@ -90,11 +90,6 @@ static int switch_fwnode_match(struct device *dev, const void *fwnode)
>  	return dev_fwnode(dev) == fwnode;
>  }
>  
> -static int switch_name_match(struct device *dev, const void *name)
> -{
> -	return !strcmp((const char *)name, dev_name(dev));
> -}
> -
>  static void *usb_role_switch_match(struct device_connection *con, int ep,
>  				   void *data)
>  {
> @@ -107,8 +102,7 @@ static void *usb_role_switch_match(struct device_connection *con, int ep,
>  		dev = class_find_device(role_class, NULL, con->fwnode,
>  					switch_fwnode_match);
>  	} else {
> -		dev = class_find_device(role_class, NULL, con->endpoint[ep],
> -					switch_name_match);
> +		dev = class_find_device_by_name(role_class, con->endpoint[ep]);
>  	}
>  
>  	return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index a18285a990a8..9b0d15b487e5 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -210,11 +210,6 @@ static int typec_port_fwnode_match(struct device *dev, const void *fwnode)
>  	return dev_fwnode(dev) == fwnode;
>  }
>  
> -static int typec_port_name_match(struct device *dev, const void *name)
> -{
> -	return !strcmp((const char *)name, dev_name(dev));
> -}
> -
>  static void *typec_port_match(struct device_connection *con, int ep, void *data)
>  {
>  	struct device *dev;
> @@ -227,8 +222,7 @@ static void *typec_port_match(struct device_connection *con, int ep, void *data)
>  		return class_find_device(typec_class, NULL, con->fwnode,
>  					 typec_port_fwnode_match);
>  
> -	dev = class_find_device(typec_class, NULL, con->endpoint[ep],
> -				typec_port_name_match);
> +	dev = class_find_device_by_name(typec_class, con->endpoint[ep]);
>  
>  	return dev ? dev : ERR_PTR(-EPROBE_DEFER);
>  }
> diff --git a/include/linux/device.h b/include/linux/device.h
> index c330b75c6c57..3ba376b8b456 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -164,6 +164,7 @@ void subsys_dev_iter_init(struct subsys_dev_iter *iter,
>  struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter);
>  void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
>  
> +int device_match_name(struct device *dev, const void *name);
>  int device_match_of_node(struct device *dev, const void *np);
>  
>  int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
> @@ -171,9 +172,20 @@ int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
>  struct device *bus_find_device(struct bus_type *bus, struct device *start,
>  			       const void *data,
>  			       int (*match)(struct device *dev, const void *data));
> -struct device *bus_find_device_by_name(struct bus_type *bus,
> -				       struct device *start,
> -				       const char *name);
> +/**
> + * bus_find_device_by_name - device iterator for locating a particular device
> + * of a specific name.
> + * @bus: bus type
> + * @start: Device to begin with
> + * @name: name of the device to match
> + */
> +static inline struct device *bus_find_device_by_name(struct bus_type *bus,
> +						     struct device *start,
> +						     const char *name)
> +{
> +	return bus_find_device(bus, start, name, device_match_name);
> +}
> +
>  struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
>  					struct device *hint);
>  int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
> @@ -342,6 +354,18 @@ struct device *driver_find_device(struct device_driver *drv,
>  				  struct device *start, const void *data,
>  				  int (*match)(struct device *dev, const void *data));
>  
> +/**
> + * driver_find_device_by_name - device iterator for locating a particular device
> + * of a specific name.
> + * @driver: the driver we're iterating
> + * @name: name of the device to match
> + */
> +static inline struct device *driver_find_device_by_name(struct device_driver *drv,
> +							const char *name)
> +{
> +	return driver_find_device(drv, NULL, name, device_match_name);
> +}
> +
>  void driver_deferred_probe_add(struct device *dev);
>  int driver_deferred_probe_check_state(struct device *dev);
>  int driver_deferred_probe_check_state_continue(struct device *dev);
> @@ -471,6 +495,18 @@ extern struct device *class_find_device(struct class *class,
>  					struct device *start, const void *data,
>  					int (*match)(struct device *, const void *));
>  
> +/**
> + * class_find_device_by_name - device iterator for locating a particular device
> + * of a specific name.
> + * @class: class type
> + * @name: name of the device to match
> + */
> +static inline struct device *class_find_device_by_name(struct class *class,
> +						       const char *name)
> +{
> +	return class_find_device(class, NULL, name, device_match_name);
> +}
> +
>  struct class_attribute {
>  	struct attribute attr;
>  	ssize_t (*show)(struct class *class, struct class_attribute *attr,
> diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
> index 60b7ac56a1f5..de259b5170ab 100644
> --- a/net/ieee802154/core.c
> +++ b/net/ieee802154/core.c
> @@ -23,11 +23,6 @@
>  LIST_HEAD(cfg802154_rdev_list);
>  int cfg802154_rdev_list_generation;
>  
> -static int wpan_phy_match(struct device *dev, const void *data)
> -{
> -	return !strcmp(dev_name(dev), (const char *)data);
> -}
> -
>  struct wpan_phy *wpan_phy_find(const char *str)
>  {
>  	struct device *dev;
> @@ -35,7 +30,7 @@ struct wpan_phy *wpan_phy_find(const char *str)
>  	if (WARN_ON(!str))
>  		return NULL;
>  
> -	dev = class_find_device(&wpan_phy_class, NULL, str, wpan_phy_match);
> +	dev = class_find_device_by_name(&wpan_phy_class, str);
>  	if (!dev)
>  		return NULL;
>  
> -- 
> 2.21.0

thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 1/7] drivers: Introduce device lookup variants by name
@ 2019-07-29 14:37     ` Heikki Krogerus
  0 siblings, 0 replies; 71+ messages in thread
From: Heikki Krogerus @ 2019-07-29 14:37 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Alexander Aring, rafael, Alexander Shishkin, Heiko Carstens,
	Alexandre Belloni, Peter Oberparleiter, Pavel Machek, Lee Jones,
	linux-leds, linux-rtc, Rafael J. Wysocki, Stefan Schmidt,
	Arnd Bergmann, Harald Freudenberger, Dan Murphy,
	linux-arm-kernel, Alessandro Zummo, gregkh, linux-usb,
	linux-kernel, Maxime Coquelin, linux-wpan, Jacek Anaszewski

On Tue, Jul 23, 2019 at 11:18:32PM +0100, Suzuki K Poulose wrote:
> Add a helper to match the device name for device lookup. Also
> reuse this generic exported helper for the existing bus_find_device_by_name().
> and add similar variants for driver/class.
> 
> Cc: Alessandro Zummo <a.zummo@towertech.it>
> Cc: Alexander Aring <alex.aring@gmail.com>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Dan Murphy <dmurphy@ti.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Harald Freudenberger <freude@linux.ibm.com>
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
> Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com>
> Cc: Lee Jones <lee.jones@linaro.org>
> Cc: linux-leds@vger.kernel.org
> Cc: linux-rtc@vger.kernel.org
> Cc: linux-usb@vger.kernel.org
> Cc: linux-wpan@vger.kernel.org
> Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
> Cc: Pavel Machek <pavel@ucw.cz>
> Cc: Peter Oberparleiter <oberpar@linux.ibm.com>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Stefan Schmidt <stefan@datenfreihafen.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.coM>

> ---
>  drivers/base/bus.c               | 24 ------------------
>  drivers/base/core.c              |  6 +++++
>  drivers/hwtracing/stm/core.c     |  9 +------
>  drivers/leds/led-class.c         |  9 +------
>  drivers/rtc/interface.c          | 11 +--------
>  drivers/s390/cio/ccwgroup.c      | 10 +-------
>  drivers/s390/cio/device.c        | 15 +-----------
>  drivers/s390/crypto/zcrypt_api.c | 11 +--------
>  drivers/usb/roles/class.c        |  8 +-----
>  drivers/usb/typec/class.c        |  8 +-----
>  include/linux/device.h           | 42 +++++++++++++++++++++++++++++---
>  net/ieee802154/core.c            |  7 +-----
>  12 files changed, 54 insertions(+), 106 deletions(-)
> 
> diff --git a/drivers/base/bus.c b/drivers/base/bus.c
> index df3cac739813..a1d1e8256324 100644
> --- a/drivers/base/bus.c
> +++ b/drivers/base/bus.c
> @@ -342,30 +342,6 @@ struct device *bus_find_device(struct bus_type *bus,
>  }
>  EXPORT_SYMBOL_GPL(bus_find_device);
>  
> -static int match_name(struct device *dev, const void *data)
> -{
> -	const char *name = data;
> -
> -	return sysfs_streq(name, dev_name(dev));
> -}
> -
> -/**
> - * bus_find_device_by_name - device iterator for locating a particular device of a specific name
> - * @bus: bus type
> - * @start: Device to begin with
> - * @name: name of the device to match
> - *
> - * This is similar to the bus_find_device() function above, but it handles
> - * searching by a name automatically, no need to write another strcmp matching
> - * function.
> - */
> -struct device *bus_find_device_by_name(struct bus_type *bus,
> -				       struct device *start, const char *name)
> -{
> -	return bus_find_device(bus, start, (void *)name, match_name);
> -}
> -EXPORT_SYMBOL_GPL(bus_find_device_by_name);
> -
>  /**
>   * subsys_find_device_by_id - find a device with a specific enumeration number
>   * @subsys: subsystem
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index da84a73f2ba6..fb83647d685a 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -3357,6 +3357,12 @@ void device_set_of_node_from_dev(struct device *dev, const struct device *dev2)
>  }
>  EXPORT_SYMBOL_GPL(device_set_of_node_from_dev);
>  
> +int device_match_name(struct device *dev, const void *name)
> +{
> +	return sysfs_streq(dev_name(dev), name);
> +}
> +EXPORT_SYMBOL_GPL(device_match_name);
> +
>  int device_match_of_node(struct device *dev, const void *np)
>  {
>  	return dev->of_node == np;
> diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
> index e55b902560de..2b6bd42632e8 100644
> --- a/drivers/hwtracing/stm/core.c
> +++ b/drivers/hwtracing/stm/core.c
> @@ -89,13 +89,6 @@ static struct class stm_class = {
>  	.dev_groups	= stm_groups,
>  };
>  
> -static int stm_dev_match(struct device *dev, const void *data)
> -{
> -	const char *name = data;
> -
> -	return sysfs_streq(name, dev_name(dev));
> -}
> -
>  /**
>   * stm_find_device() - find stm device by name
>   * @buf:	character buffer containing the name
> @@ -116,7 +109,7 @@ struct stm_device *stm_find_device(const char *buf)
>  	if (!stm_core_up)
>  		return NULL;
>  
> -	dev = class_find_device(&stm_class, NULL, buf, stm_dev_match);
> +	dev = class_find_device_by_name(&stm_class, buf);
>  	if (!dev)
>  		return NULL;
>  
> diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
> index 4793e77808e2..d54c8e4d8954 100644
> --- a/drivers/leds/led-class.c
> +++ b/drivers/leds/led-class.c
> @@ -213,13 +213,6 @@ static int led_resume(struct device *dev)
>  
>  static SIMPLE_DEV_PM_OPS(leds_class_dev_pm_ops, led_suspend, led_resume);
>  
> -static int match_name(struct device *dev, const void *data)
> -{
> -	if (!dev_name(dev))
> -		return 0;
> -	return !strcmp(dev_name(dev), (char *)data);
> -}
> -
>  static int led_classdev_next_name(const char *init_name, char *name,
>  				  size_t len)
>  {
> @@ -230,7 +223,7 @@ static int led_classdev_next_name(const char *init_name, char *name,
>  	strlcpy(name, init_name, len);
>  
>  	while ((ret < len) &&
> -	       (dev = class_find_device(leds_class, NULL, name, match_name))) {
> +	       (dev = class_find_device_by_name(leds_class, name))) {
>  		put_device(dev);
>  		ret = snprintf(name, len, "%s_%u", init_name, ++i);
>  	}
> diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
> index 72b7ddc43116..c93ef33b01d3 100644
> --- a/drivers/rtc/interface.c
> +++ b/drivers/rtc/interface.c
> @@ -663,21 +663,12 @@ void rtc_update_irq(struct rtc_device *rtc,
>  }
>  EXPORT_SYMBOL_GPL(rtc_update_irq);
>  
> -static int __rtc_match(struct device *dev, const void *data)
> -{
> -	const char *name = data;
> -
> -	if (strcmp(dev_name(dev), name) == 0)
> -		return 1;
> -	return 0;
> -}
> -
>  struct rtc_device *rtc_class_open(const char *name)
>  {
>  	struct device *dev;
>  	struct rtc_device *rtc = NULL;
>  
> -	dev = class_find_device(rtc_class, NULL, name, __rtc_match);
> +	dev = class_find_device_by_name(rtc_class, name);
>  	if (dev)
>  		rtc = to_rtc_device(dev);
>  
> diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
> index c522e9313c50..d843e362c167 100644
> --- a/drivers/s390/cio/ccwgroup.c
> +++ b/drivers/s390/cio/ccwgroup.c
> @@ -608,13 +608,6 @@ void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver)
>  }
>  EXPORT_SYMBOL(ccwgroup_driver_unregister);
>  
> -static int __ccwgroupdev_check_busid(struct device *dev, const void *id)
> -{
> -	const char *bus_id = id;
> -
> -	return (strcmp(bus_id, dev_name(dev)) == 0);
> -}
> -
>  /**
>   * get_ccwgroupdev_by_busid() - obtain device from a bus id
>   * @gdrv: driver the device is owned by
> @@ -631,8 +624,7 @@ struct ccwgroup_device *get_ccwgroupdev_by_busid(struct ccwgroup_driver *gdrv,
>  {
>  	struct device *dev;
>  
> -	dev = driver_find_device(&gdrv->driver, NULL, bus_id,
> -				 __ccwgroupdev_check_busid);
> +	dev = driver_find_device_by_name(&gdrv->driver, bus_id);
>  
>  	return dev ? to_ccwgroupdev(dev) : NULL;
>  }
> diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
> index c421899be20f..131430bd48d9 100644
> --- a/drivers/s390/cio/device.c
> +++ b/drivers/s390/cio/device.c
> @@ -1695,18 +1695,6 @@ int ccw_device_force_console(struct ccw_device *cdev)
>  EXPORT_SYMBOL_GPL(ccw_device_force_console);
>  #endif
>  
> -/*
> - * get ccw_device matching the busid, but only if owned by cdrv
> - */
> -static int
> -__ccwdev_check_busid(struct device *dev, const void *id)
> -{
> -	const char *bus_id = id;
> -
> -	return (strcmp(bus_id, dev_name(dev)) == 0);
> -}
> -
> -
>  /**
>   * get_ccwdev_by_busid() - obtain device from a bus id
>   * @cdrv: driver the device is owned by
> @@ -1723,8 +1711,7 @@ struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
>  {
>  	struct device *dev;
>  
> -	dev = driver_find_device(&cdrv->driver, NULL, (void *)bus_id,
> -				 __ccwdev_check_busid);
> +	dev = driver_find_device_by_name(&cdrv->driver, bus_id);
>  
>  	return dev ? to_ccwdev(dev) : NULL;
>  }
> diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c
> index 1058b4b5cc1e..38a5a47b8c9c 100644
> --- a/drivers/s390/crypto/zcrypt_api.c
> +++ b/drivers/s390/crypto/zcrypt_api.c
> @@ -133,12 +133,6 @@ struct zcdn_device {
>  static int zcdn_create(const char *name);
>  static int zcdn_destroy(const char *name);
>  
> -/* helper function, matches the name for find_zcdndev_by_name() */
> -static int __match_zcdn_name(struct device *dev, const void *data)
> -{
> -	return strcmp(dev_name(dev), (const char *)data) == 0;
> -}
> -
>  /* helper function, matches the devt value for find_zcdndev_by_devt() */
>  static int __match_zcdn_devt(struct device *dev, const void *data)
>  {
> @@ -152,10 +146,7 @@ static int __match_zcdn_devt(struct device *dev, const void *data)
>   */
>  static inline struct zcdn_device *find_zcdndev_by_name(const char *name)
>  {
> -	struct device *dev =
> -		class_find_device(zcrypt_class, NULL,
> -				  (void *) name,
> -				  __match_zcdn_name);
> +	struct device *dev = class_find_device_by_name(zcrypt_class, name);
>  
>  	return dev ? to_zcdn_dev(dev) : NULL;
>  }
> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
> index 86defca6623e..c8efe60e2465 100644
> --- a/drivers/usb/roles/class.c
> +++ b/drivers/usb/roles/class.c
> @@ -90,11 +90,6 @@ static int switch_fwnode_match(struct device *dev, const void *fwnode)
>  	return dev_fwnode(dev) == fwnode;
>  }
>  
> -static int switch_name_match(struct device *dev, const void *name)
> -{
> -	return !strcmp((const char *)name, dev_name(dev));
> -}
> -
>  static void *usb_role_switch_match(struct device_connection *con, int ep,
>  				   void *data)
>  {
> @@ -107,8 +102,7 @@ static void *usb_role_switch_match(struct device_connection *con, int ep,
>  		dev = class_find_device(role_class, NULL, con->fwnode,
>  					switch_fwnode_match);
>  	} else {
> -		dev = class_find_device(role_class, NULL, con->endpoint[ep],
> -					switch_name_match);
> +		dev = class_find_device_by_name(role_class, con->endpoint[ep]);
>  	}
>  
>  	return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index a18285a990a8..9b0d15b487e5 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -210,11 +210,6 @@ static int typec_port_fwnode_match(struct device *dev, const void *fwnode)
>  	return dev_fwnode(dev) == fwnode;
>  }
>  
> -static int typec_port_name_match(struct device *dev, const void *name)
> -{
> -	return !strcmp((const char *)name, dev_name(dev));
> -}
> -
>  static void *typec_port_match(struct device_connection *con, int ep, void *data)
>  {
>  	struct device *dev;
> @@ -227,8 +222,7 @@ static void *typec_port_match(struct device_connection *con, int ep, void *data)
>  		return class_find_device(typec_class, NULL, con->fwnode,
>  					 typec_port_fwnode_match);
>  
> -	dev = class_find_device(typec_class, NULL, con->endpoint[ep],
> -				typec_port_name_match);
> +	dev = class_find_device_by_name(typec_class, con->endpoint[ep]);
>  
>  	return dev ? dev : ERR_PTR(-EPROBE_DEFER);
>  }
> diff --git a/include/linux/device.h b/include/linux/device.h
> index c330b75c6c57..3ba376b8b456 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -164,6 +164,7 @@ void subsys_dev_iter_init(struct subsys_dev_iter *iter,
>  struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter);
>  void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
>  
> +int device_match_name(struct device *dev, const void *name);
>  int device_match_of_node(struct device *dev, const void *np);
>  
>  int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
> @@ -171,9 +172,20 @@ int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
>  struct device *bus_find_device(struct bus_type *bus, struct device *start,
>  			       const void *data,
>  			       int (*match)(struct device *dev, const void *data));
> -struct device *bus_find_device_by_name(struct bus_type *bus,
> -				       struct device *start,
> -				       const char *name);
> +/**
> + * bus_find_device_by_name - device iterator for locating a particular device
> + * of a specific name.
> + * @bus: bus type
> + * @start: Device to begin with
> + * @name: name of the device to match
> + */
> +static inline struct device *bus_find_device_by_name(struct bus_type *bus,
> +						     struct device *start,
> +						     const char *name)
> +{
> +	return bus_find_device(bus, start, name, device_match_name);
> +}
> +
>  struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
>  					struct device *hint);
>  int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
> @@ -342,6 +354,18 @@ struct device *driver_find_device(struct device_driver *drv,
>  				  struct device *start, const void *data,
>  				  int (*match)(struct device *dev, const void *data));
>  
> +/**
> + * driver_find_device_by_name - device iterator for locating a particular device
> + * of a specific name.
> + * @driver: the driver we're iterating
> + * @name: name of the device to match
> + */
> +static inline struct device *driver_find_device_by_name(struct device_driver *drv,
> +							const char *name)
> +{
> +	return driver_find_device(drv, NULL, name, device_match_name);
> +}
> +
>  void driver_deferred_probe_add(struct device *dev);
>  int driver_deferred_probe_check_state(struct device *dev);
>  int driver_deferred_probe_check_state_continue(struct device *dev);
> @@ -471,6 +495,18 @@ extern struct device *class_find_device(struct class *class,
>  					struct device *start, const void *data,
>  					int (*match)(struct device *, const void *));
>  
> +/**
> + * class_find_device_by_name - device iterator for locating a particular device
> + * of a specific name.
> + * @class: class type
> + * @name: name of the device to match
> + */
> +static inline struct device *class_find_device_by_name(struct class *class,
> +						       const char *name)
> +{
> +	return class_find_device(class, NULL, name, device_match_name);
> +}
> +
>  struct class_attribute {
>  	struct attribute attr;
>  	ssize_t (*show)(struct class *class, struct class_attribute *attr,
> diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
> index 60b7ac56a1f5..de259b5170ab 100644
> --- a/net/ieee802154/core.c
> +++ b/net/ieee802154/core.c
> @@ -23,11 +23,6 @@
>  LIST_HEAD(cfg802154_rdev_list);
>  int cfg802154_rdev_list_generation;
>  
> -static int wpan_phy_match(struct device *dev, const void *data)
> -{
> -	return !strcmp(dev_name(dev), (const char *)data);
> -}
> -
>  struct wpan_phy *wpan_phy_find(const char *str)
>  {
>  	struct device *dev;
> @@ -35,7 +30,7 @@ struct wpan_phy *wpan_phy_find(const char *str)
>  	if (WARN_ON(!str))
>  		return NULL;
>  
> -	dev = class_find_device(&wpan_phy_class, NULL, str, wpan_phy_match);
> +	dev = class_find_device_by_name(&wpan_phy_class, str);
>  	if (!dev)
>  		return NULL;
>  
> -- 
> 2.21.0

thanks,

-- 
heikki

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
  2019-07-25 13:54     ` Lee Jones
  (?)
  (?)
@ 2019-07-30 11:03       ` Greg KH
  -1 siblings, 0 replies; 71+ messages in thread
From: Greg KH @ 2019-07-30 11:03 UTC (permalink / raw)
  To: Lee Jones
  Cc: Suzuki K Poulose, linux-kernel, rafael, linux-arm-kernel,
	Maarten Lankhorst, Maxime Ripard, dri-devel, David Airlie,
	Daniel Vetter, devicetree, Florian Fainelli, Frank Rowand,
	Heiko Stuebner, Liam Girdwood, linux-i2c, linux-rockchip,
	linux-spi, Mathieu Poirier, Rob Herring, Srinivas Kandagatla,
	Takashi Iwai, Wolfram Sang, Alan Tull, Moritz Fischer,
	linux-fpga, Peter Rosin, Mark Brown, Heiner Kallweit,
	David S. Miller, Andrew Lunn, Thor Thayer, Jiri Slaby

On Thu, Jul 25, 2019 at 02:54:02PM +0100, Lee Jones wrote:
> On Tue, 23 Jul 2019, Suzuki K Poulose wrote:
> 
> > Introduce wrappers for {bus/driver/class}_find_device() to
> > locate devices by its of_node.
> > 
> > Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> > Cc: Maxime Ripard <maxime.ripard@bootlin.com>
> > Cc: dri-devel@lists.freedesktop.org
> > Cc: David Airlie <airlied@linux.ie>
> > Cc: Daniel Vetter <daniel@ffwll.ch>
> > Cc: devicetree@vger.kernel.org
> > Cc: Florian Fainelli <f.fainelli@gmail.com>
> > Cc: Frank Rowand <frowand.list@gmail.com>
> > Cc: Heiko Stuebner <heiko@sntech.de>
> > Cc: Liam Girdwood <lgirdwood@gmail.com>
> > Cc: linux-i2c@vger.kernel.org
> > Cc: linux-rockchip@lists.infradead.org
> > Cc: linux-spi@vger.kernel.org
> > Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> > Cc: Rob Herring <robh+dt@kernel.org>
> > Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> > Cc: Takashi Iwai <tiwai@suse.com>
> > Cc: Wolfram Sang <wsa@the-dreams.de>
> > Cc: Alan Tull <atull@kernel.org>
> > Cc: Moritz Fischer <mdf@kernel.org>
> > Cc: linux-fpga@vger.kernel.org
> > Cc: Peter Rosin <peda@axentia.se>
> > Cc: Mark Brown <broonie@kernel.org>
> > Cc: Florian Fainelli <f.fainelli@gmail.com>
> > Cc: Heiner Kallweit <hkallweit1@gmail.com>
> > Cc: "David S. Miller" <davem@davemloft.net>
> > Cc: Andrew Lunn <andrew@lunn.ch>
> > Cc: Liam Girdwood <lgirdwood@gmail.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> > Cc: Lee Jones <lee.jones@linaro.org>
> > Cc: Thor Thayer <thor.thayer@linux.intel.com>
> > Cc: Jiri Slaby <jslaby@suse.com>
> > Cc: Mark Brown <broonie@kernel.org>
> > Cc: Andrew Lunn <andrew@lunn.ch>
> > Cc: Peter Rosin <peda@axentia.se>
> > Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> > ---
> >  - Dropped the reviewed-by tags from Thor, Mark, Andrew and Peter as the
> >    patches are mereged, though there are no functional changes.
> > ---
> >  drivers/amba/tegra-ahb.c              | 11 +-------
> >  drivers/fpga/fpga-bridge.c            |  8 +-----
> >  drivers/fpga/fpga-mgr.c               |  8 +-----
> >  drivers/gpu/drm/drm_mipi_dsi.c        |  7 +----
> >  drivers/i2c/i2c-core-of.c             |  7 +----
> >  drivers/mfd/altera-sysmgr.c           | 14 ++--------
> 
> For my own reference:
>   Acked-for-MFD-by: Lee Jones <lee.jones@linaro.org>
> 
> What's the merge plan for this patch?
> 
> Is anyone prepared to create an immutable branch for us to pull from?
> I'm happy to do it if no one else steps up.

I'll take it, and create a branch for everyone to pull from.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
@ 2019-07-30 11:03       ` Greg KH
  0 siblings, 0 replies; 71+ messages in thread
From: Greg KH @ 2019-07-30 11:03 UTC (permalink / raw)
  To: Lee Jones
  Cc: Andrew Lunn, Thor Thayer, rafael, Maxime Ripard, linux-fpga,
	dri-devel, Liam Girdwood, David S. Miller, Srinivas Kandagatla,
	linux-i2c, Frank Rowand, Florian Fainelli, linux-rockchip,
	Wolfram Sang, David Airlie, Jiri Slaby, devicetree, Alan Tull,
	Suzuki K Poulose, Rob Herring, Moritz Fischer, Takashi Iwai,
	linux-arm-kernel, Mathieu Poirier, linux-kernel

On Thu, Jul 25, 2019 at 02:54:02PM +0100, Lee Jones wrote:
> On Tue, 23 Jul 2019, Suzuki K Poulose wrote:
> 
> > Introduce wrappers for {bus/driver/class}_find_device() to
> > locate devices by its of_node.
> > 
> > Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> > Cc: Maxime Ripard <maxime.ripard@bootlin.com>
> > Cc: dri-devel@lists.freedesktop.org
> > Cc: David Airlie <airlied@linux.ie>
> > Cc: Daniel Vetter <daniel@ffwll.ch>
> > Cc: devicetree@vger.kernel.org
> > Cc: Florian Fainelli <f.fainelli@gmail.com>
> > Cc: Frank Rowand <frowand.list@gmail.com>
> > Cc: Heiko Stuebner <heiko@sntech.de>
> > Cc: Liam Girdwood <lgirdwood@gmail.com>
> > Cc: linux-i2c@vger.kernel.org
> > Cc: linux-rockchip@lists.infradead.org
> > Cc: linux-spi@vger.kernel.org
> > Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> > Cc: Rob Herring <robh+dt@kernel.org>
> > Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> > Cc: Takashi Iwai <tiwai@suse.com>
> > Cc: Wolfram Sang <wsa@the-dreams.de>
> > Cc: Alan Tull <atull@kernel.org>
> > Cc: Moritz Fischer <mdf@kernel.org>
> > Cc: linux-fpga@vger.kernel.org
> > Cc: Peter Rosin <peda@axentia.se>
> > Cc: Mark Brown <broonie@kernel.org>
> > Cc: Florian Fainelli <f.fainelli@gmail.com>
> > Cc: Heiner Kallweit <hkallweit1@gmail.com>
> > Cc: "David S. Miller" <davem@davemloft.net>
> > Cc: Andrew Lunn <andrew@lunn.ch>
> > Cc: Liam Girdwood <lgirdwood@gmail.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> > Cc: Lee Jones <lee.jones@linaro.org>
> > Cc: Thor Thayer <thor.thayer@linux.intel.com>
> > Cc: Jiri Slaby <jslaby@suse.com>
> > Cc: Mark Brown <broonie@kernel.org>
> > Cc: Andrew Lunn <andrew@lunn.ch>
> > Cc: Peter Rosin <peda@axentia.se>
> > Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> > ---
> >  - Dropped the reviewed-by tags from Thor, Mark, Andrew and Peter as the
> >    patches are mereged, though there are no functional changes.
> > ---
> >  drivers/amba/tegra-ahb.c              | 11 +-------
> >  drivers/fpga/fpga-bridge.c            |  8 +-----
> >  drivers/fpga/fpga-mgr.c               |  8 +-----
> >  drivers/gpu/drm/drm_mipi_dsi.c        |  7 +----
> >  drivers/i2c/i2c-core-of.c             |  7 +----
> >  drivers/mfd/altera-sysmgr.c           | 14 ++--------
> 
> For my own reference:
>   Acked-for-MFD-by: Lee Jones <lee.jones@linaro.org>
> 
> What's the merge plan for this patch?
> 
> Is anyone prepared to create an immutable branch for us to pull from?
> I'm happy to do it if no one else steps up.

I'll take it, and create a branch for everyone to pull from.

thanks,

greg k-h
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
@ 2019-07-30 11:03       ` Greg KH
  0 siblings, 0 replies; 71+ messages in thread
From: Greg KH @ 2019-07-30 11:03 UTC (permalink / raw)
  To: Lee Jones
  Cc: Andrew Lunn, Thor Thayer, rafael, Maxime Ripard, linux-fpga,
	dri-devel, Liam Girdwood, David S. Miller, Srinivas Kandagatla,
	linux-i2c, Frank Rowand, Florian Fainelli, linux-rockchip,
	Wolfram Sang, David Airlie, Jiri Slaby, devicetree, Alan Tull,
	Suzuki K Poulose, Rob Herring, Moritz Fischer, Takashi Iwai,
	linux-arm-kernel, Mathieu Poirier, linux-kernel, li

On Thu, Jul 25, 2019 at 02:54:02PM +0100, Lee Jones wrote:
> On Tue, 23 Jul 2019, Suzuki K Poulose wrote:
> 
> > Introduce wrappers for {bus/driver/class}_find_device() to
> > locate devices by its of_node.
> > 
> > Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> > Cc: Maxime Ripard <maxime.ripard@bootlin.com>
> > Cc: dri-devel@lists.freedesktop.org
> > Cc: David Airlie <airlied@linux.ie>
> > Cc: Daniel Vetter <daniel@ffwll.ch>
> > Cc: devicetree@vger.kernel.org
> > Cc: Florian Fainelli <f.fainelli@gmail.com>
> > Cc: Frank Rowand <frowand.list@gmail.com>
> > Cc: Heiko Stuebner <heiko@sntech.de>
> > Cc: Liam Girdwood <lgirdwood@gmail.com>
> > Cc: linux-i2c@vger.kernel.org
> > Cc: linux-rockchip@lists.infradead.org
> > Cc: linux-spi@vger.kernel.org
> > Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> > Cc: Rob Herring <robh+dt@kernel.org>
> > Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> > Cc: Takashi Iwai <tiwai@suse.com>
> > Cc: Wolfram Sang <wsa@the-dreams.de>
> > Cc: Alan Tull <atull@kernel.org>
> > Cc: Moritz Fischer <mdf@kernel.org>
> > Cc: linux-fpga@vger.kernel.org
> > Cc: Peter Rosin <peda@axentia.se>
> > Cc: Mark Brown <broonie@kernel.org>
> > Cc: Florian Fainelli <f.fainelli@gmail.com>
> > Cc: Heiner Kallweit <hkallweit1@gmail.com>
> > Cc: "David S. Miller" <davem@davemloft.net>
> > Cc: Andrew Lunn <andrew@lunn.ch>
> > Cc: Liam Girdwood <lgirdwood@gmail.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> > Cc: Lee Jones <lee.jones@linaro.org>
> > Cc: Thor Thayer <thor.thayer@linux.intel.com>
> > Cc: Jiri Slaby <jslaby@suse.com>
> > Cc: Mark Brown <broonie@kernel.org>
> > Cc: Andrew Lunn <andrew@lunn.ch>
> > Cc: Peter Rosin <peda@axentia.se>
> > Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> > ---
> >  - Dropped the reviewed-by tags from Thor, Mark, Andrew and Peter as the
> >    patches are mereged, though there are no functional changes.
> > ---
> >  drivers/amba/tegra-ahb.c              | 11 +-------
> >  drivers/fpga/fpga-bridge.c            |  8 +-----
> >  drivers/fpga/fpga-mgr.c               |  8 +-----
> >  drivers/gpu/drm/drm_mipi_dsi.c        |  7 +----
> >  drivers/i2c/i2c-core-of.c             |  7 +----
> >  drivers/mfd/altera-sysmgr.c           | 14 ++--------
> 
> For my own reference:
>   Acked-for-MFD-by: Lee Jones <lee.jones@linaro.org>
> 
> What's the merge plan for this patch?
> 
> Is anyone prepared to create an immutable branch for us to pull from?
> I'm happy to do it if no one else steps up.

I'll take it, and create a branch for everyone to pull from.

thanks,

greg k-h
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 2/7] drivers: Introduce device lookup variants by of_node
@ 2019-07-30 11:03       ` Greg KH
  0 siblings, 0 replies; 71+ messages in thread
From: Greg KH @ 2019-07-30 11:03 UTC (permalink / raw)
  To: Lee Jones
  Cc: Andrew Lunn, Thor Thayer, Heiko Stuebner, rafael, Maxime Ripard,
	linux-fpga, dri-devel, Liam Girdwood, David S. Miller,
	Srinivas Kandagatla, linux-i2c, Frank Rowand, Florian Fainelli,
	linux-rockchip, Wolfram Sang, David Airlie, Jiri Slaby,
	devicetree, Alan Tull, Suzuki K Poulose, Maarten Lankhorst,
	Rob Herring, Moritz Fischer, Takashi Iwai, linux-arm-kernel,
	Mathieu Poirier, linux-kernel, linux-spi, Mark Brown,
	Daniel Vetter, Peter Rosin, Heiner Kallweit

On Thu, Jul 25, 2019 at 02:54:02PM +0100, Lee Jones wrote:
> On Tue, 23 Jul 2019, Suzuki K Poulose wrote:
> 
> > Introduce wrappers for {bus/driver/class}_find_device() to
> > locate devices by its of_node.
> > 
> > Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> > Cc: Maxime Ripard <maxime.ripard@bootlin.com>
> > Cc: dri-devel@lists.freedesktop.org
> > Cc: David Airlie <airlied@linux.ie>
> > Cc: Daniel Vetter <daniel@ffwll.ch>
> > Cc: devicetree@vger.kernel.org
> > Cc: Florian Fainelli <f.fainelli@gmail.com>
> > Cc: Frank Rowand <frowand.list@gmail.com>
> > Cc: Heiko Stuebner <heiko@sntech.de>
> > Cc: Liam Girdwood <lgirdwood@gmail.com>
> > Cc: linux-i2c@vger.kernel.org
> > Cc: linux-rockchip@lists.infradead.org
> > Cc: linux-spi@vger.kernel.org
> > Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> > Cc: Rob Herring <robh+dt@kernel.org>
> > Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> > Cc: Takashi Iwai <tiwai@suse.com>
> > Cc: Wolfram Sang <wsa@the-dreams.de>
> > Cc: Alan Tull <atull@kernel.org>
> > Cc: Moritz Fischer <mdf@kernel.org>
> > Cc: linux-fpga@vger.kernel.org
> > Cc: Peter Rosin <peda@axentia.se>
> > Cc: Mark Brown <broonie@kernel.org>
> > Cc: Florian Fainelli <f.fainelli@gmail.com>
> > Cc: Heiner Kallweit <hkallweit1@gmail.com>
> > Cc: "David S. Miller" <davem@davemloft.net>
> > Cc: Andrew Lunn <andrew@lunn.ch>
> > Cc: Liam Girdwood <lgirdwood@gmail.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> > Cc: Lee Jones <lee.jones@linaro.org>
> > Cc: Thor Thayer <thor.thayer@linux.intel.com>
> > Cc: Jiri Slaby <jslaby@suse.com>
> > Cc: Mark Brown <broonie@kernel.org>
> > Cc: Andrew Lunn <andrew@lunn.ch>
> > Cc: Peter Rosin <peda@axentia.se>
> > Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> > ---
> >  - Dropped the reviewed-by tags from Thor, Mark, Andrew and Peter as the
> >    patches are mereged, though there are no functional changes.
> > ---
> >  drivers/amba/tegra-ahb.c              | 11 +-------
> >  drivers/fpga/fpga-bridge.c            |  8 +-----
> >  drivers/fpga/fpga-mgr.c               |  8 +-----
> >  drivers/gpu/drm/drm_mipi_dsi.c        |  7 +----
> >  drivers/i2c/i2c-core-of.c             |  7 +----
> >  drivers/mfd/altera-sysmgr.c           | 14 ++--------
> 
> For my own reference:
>   Acked-for-MFD-by: Lee Jones <lee.jones@linaro.org>
> 
> What's the merge plan for this patch?
> 
> Is anyone prepared to create an immutable branch for us to pull from?
> I'm happy to do it if no one else steps up.

I'll take it, and create a branch for everyone to pull from.

thanks,

greg k-h

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 0/7] drivers: Add generic device lookup helpers
  2019-07-23 22:18 ` Suzuki K Poulose
  (?)
@ 2019-07-30 11:56   ` Greg KH
  -1 siblings, 0 replies; 71+ messages in thread
From: Greg KH @ 2019-07-30 11:56 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Andrew Lunn, Alexander Aring, Heikki Krogerus, Jacek Anaszewski,
	rafael, Alexander Shishkin, linux-fpga, Heiko Carstens,
	Alexandre Belloni, dri-devel, Liam Girdwood, Elie Morisse,
	Srinivas Kandagatla, linux-i2c, Pavel Machek, Shyam Sundar S K,
	Frank Rowand, linux-leds, linux-rtc, Maxime Ripard,
	Florian Fainelli, linux-acpi, Jason Gunthorpe, Lee Jones

On Tue, Jul 23, 2019 at 11:18:31PM +0100, Suzuki K Poulose wrote:
> We have device iterators to find a particular device matching a criteria
> for a given bus/class/driver. i.e, {bus,class,driver}_find_device()
> APIs. The matching criteria is a function pointer for the APIs. Often the
> lookup is based on a generic property of a device (e.g, name, fwnode, of node
> pointer or device type) rather than a driver specific information. However, each
> driver writes up its own "match" function, spilling the similar match functions
> all over the driver subsystems.
> 
> This series adds device match helpers by generic device properties of a device.
> Using these generic match functions, introduce wrappers to the existing
>  *_find_device() helpers and converts the existing users to use the new wrappers.
>  i.e,
> 	{bus/class/driver}_find_device_by_name()
> 	{bus/class/driver}_find_device_by_fwnode()
> 	{bus/class/driver}_find_device_by_devt()
> 	{bus/class/driver}_find_device_by_acpi_dev()
> 
> Also adds a wrapper for finding a platform device by driver, to avoid
> spilling the platform_bus internals in the individual drivers. Applies
> on 5.3-rc1.
> 
>    [0] git://linux-arm.org/linux-skp.git driver-cleanup/v3
> RFC[1] https://marc.info/?i=1559577023-558-1-git-send-email-suzuki.poulose@arm.com
> V1 [2] https://marc.info/?i=1559747630-28065-1-git-send-email-suzuki.poulose@arm.com
> V2 [3] https://marc.info/?i=1560534863-15115-1-git-send-email-suzuki.poulose@arm.com

There is now a persistent tag/branch in my driver-core tree for any
subsystem that wants to pull this tree in to make it easier for merges:


The following changes since commit 5f9e832c137075045d15cd6899ab0505cfb2ca4b:

  Linus 5.3-rc1 (2019-07-21 14:05:38 -0700)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git tags/generic_lookup_helpers

for you to fetch changes up to 36f3313d6bff91ab2a9e47698c27d15363640a4e:

  platform: Add platform_find_device_by_driver() helper (2019-07-30 13:07:42 +0200)

----------------------------------------------------------------
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>

----------------------------------------------------------------
Suzuki K Poulose (7):
      drivers: Introduce device lookup variants by name
      drivers: Introduce device lookup variants by of_node
      drivers: Introduce device lookup variants by fwnode
      drivers: Introduce device lookup variants by device type
      drivers: Introduce device lookup variants by ACPI_COMPANION device
      drivers: Add generic helper to match any device
      platform: Add platform_find_device_by_driver() helper

 drivers/amba/tegra-ahb.c                           |  11 +-
 drivers/base/bus.c                                 |  24 ---
 drivers/base/core.c                                |  39 +++-
 drivers/base/devcon.c                              |   8 +-
 drivers/base/platform.c                            |  14 ++
 drivers/fpga/fpga-bridge.c                         |   8 +-
 drivers/fpga/fpga-mgr.c                            |   8 +-
 drivers/gpu/drm/drm_mipi_dsi.c                     |   7 +-
 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 +-
 drivers/hwtracing/coresight/coresight-platform.c   |  11 +-
 drivers/hwtracing/coresight/coresight-priv.h       |   2 -
 drivers/hwtracing/coresight/coresight.c            |   4 +-
 drivers/hwtracing/intel_th/core.c                  |  10 +-
 drivers/hwtracing/stm/core.c                       |   9 +-
 drivers/i2c/busses/i2c-amd-mp2-pci.c               |   8 +-
 drivers/i2c/i2c-core-acpi.c                        |  11 +-
 drivers/i2c/i2c-core-of.c                          |   7 +-
 drivers/infiniband/hw/hns/hns_roce_hw_v1.c         |   8 +-
 drivers/iommu/arm-smmu-v3.c                        |   9 +-
 drivers/iommu/arm-smmu.c                           |   9 +-
 drivers/leds/led-class.c                           |   9 +-
 drivers/mfd/altera-sysmgr.c                        |  14 +-
 drivers/misc/mei/main.c                            |   9 +-
 drivers/mux/core.c                                 |   7 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c |   8 +-
 drivers/net/phy/mdio_bus.c                         |   9 +-
 drivers/nvmem/core.c                               |   7 +-
 drivers/of/of_mdio.c                               |   8 +-
 drivers/of/platform.c                              |   7 +-
 drivers/pci/probe.c                                |   7 +-
 drivers/regulator/of_regulator.c                   |   7 +-
 drivers/rtc/interface.c                            |  11 +-
 drivers/s390/cio/ccwgroup.c                        |  18 +-
 drivers/s390/cio/device.c                          |  15 +-
 drivers/s390/crypto/zcrypt_api.c                   |  22 +-
 drivers/scsi/scsi_proc.c                           |   9 +-
 drivers/spi/spi.c                                  |  28 +--
 drivers/tty/tty_io.c                               |   8 +-
 drivers/usb/core/devio.c                           |   8 +-
 drivers/usb/roles/class.c                          |  16 +-
 drivers/usb/typec/class.c                          |  16 +-
 include/linux/device.h                             | 237 ++++++++++++++++++++-
 include/linux/platform_device.h                    |   3 +
 net/ieee802154/core.c                              |   7 +-
 sound/soc/rockchip/rk3399_gru_sound.c              |   9 +-
 48 files changed, 341 insertions(+), 383 deletions(-)
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 0/7] drivers: Add generic device lookup helpers
@ 2019-07-30 11:56   ` Greg KH
  0 siblings, 0 replies; 71+ messages in thread
From: Greg KH @ 2019-07-30 11:56 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Andrew Lunn, Alexander Aring, Heikki Krogerus, Jacek Anaszewski,
	rafael, Alexander Shishkin, linux-fpga, Heiko Carstens,
	Alexandre Belloni, dri-devel, Liam Girdwood, Elie Morisse,
	Srinivas Kandagatla, linux-i2c, Pavel Machek, Shyam Sundar S K,
	Frank Rowand, linux-leds, linux-rtc, Maxime Ripard,
	Florian Fainelli, linux-acpi, Jason Gunthorpe, Lee Jones

On Tue, Jul 23, 2019 at 11:18:31PM +0100, Suzuki K Poulose wrote:
> We have device iterators to find a particular device matching a criteria
> for a given bus/class/driver. i.e, {bus,class,driver}_find_device()
> APIs. The matching criteria is a function pointer for the APIs. Often the
> lookup is based on a generic property of a device (e.g, name, fwnode, of node
> pointer or device type) rather than a driver specific information. However, each
> driver writes up its own "match" function, spilling the similar match functions
> all over the driver subsystems.
> 
> This series adds device match helpers by generic device properties of a device.
> Using these generic match functions, introduce wrappers to the existing
>  *_find_device() helpers and converts the existing users to use the new wrappers.
>  i.e,
> 	{bus/class/driver}_find_device_by_name()
> 	{bus/class/driver}_find_device_by_fwnode()
> 	{bus/class/driver}_find_device_by_devt()
> 	{bus/class/driver}_find_device_by_acpi_dev()
> 
> Also adds a wrapper for finding a platform device by driver, to avoid
> spilling the platform_bus internals in the individual drivers. Applies
> on 5.3-rc1.
> 
>    [0] git://linux-arm.org/linux-skp.git driver-cleanup/v3
> RFC[1] https://marc.info/?i=1559577023-558-1-git-send-email-suzuki.poulose@arm.com
> V1 [2] https://marc.info/?i=1559747630-28065-1-git-send-email-suzuki.poulose@arm.com
> V2 [3] https://marc.info/?i=1560534863-15115-1-git-send-email-suzuki.poulose@arm.com

There is now a persistent tag/branch in my driver-core tree for any
subsystem that wants to pull this tree in to make it easier for merges:


The following changes since commit 5f9e832c137075045d15cd6899ab0505cfb2ca4b:

  Linus 5.3-rc1 (2019-07-21 14:05:38 -0700)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git tags/generic_lookup_helpers

for you to fetch changes up to 36f3313d6bff91ab2a9e47698c27d15363640a4e:

  platform: Add platform_find_device_by_driver() helper (2019-07-30 13:07:42 +0200)

----------------------------------------------------------------
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>

----------------------------------------------------------------
Suzuki K Poulose (7):
      drivers: Introduce device lookup variants by name
      drivers: Introduce device lookup variants by of_node
      drivers: Introduce device lookup variants by fwnode
      drivers: Introduce device lookup variants by device type
      drivers: Introduce device lookup variants by ACPI_COMPANION device
      drivers: Add generic helper to match any device
      platform: Add platform_find_device_by_driver() helper

 drivers/amba/tegra-ahb.c                           |  11 +-
 drivers/base/bus.c                                 |  24 ---
 drivers/base/core.c                                |  39 +++-
 drivers/base/devcon.c                              |   8 +-
 drivers/base/platform.c                            |  14 ++
 drivers/fpga/fpga-bridge.c                         |   8 +-
 drivers/fpga/fpga-mgr.c                            |   8 +-
 drivers/gpu/drm/drm_mipi_dsi.c                     |   7 +-
 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 +-
 drivers/hwtracing/coresight/coresight-platform.c   |  11 +-
 drivers/hwtracing/coresight/coresight-priv.h       |   2 -
 drivers/hwtracing/coresight/coresight.c            |   4 +-
 drivers/hwtracing/intel_th/core.c                  |  10 +-
 drivers/hwtracing/stm/core.c                       |   9 +-
 drivers/i2c/busses/i2c-amd-mp2-pci.c               |   8 +-
 drivers/i2c/i2c-core-acpi.c                        |  11 +-
 drivers/i2c/i2c-core-of.c                          |   7 +-
 drivers/infiniband/hw/hns/hns_roce_hw_v1.c         |   8 +-
 drivers/iommu/arm-smmu-v3.c                        |   9 +-
 drivers/iommu/arm-smmu.c                           |   9 +-
 drivers/leds/led-class.c                           |   9 +-
 drivers/mfd/altera-sysmgr.c                        |  14 +-
 drivers/misc/mei/main.c                            |   9 +-
 drivers/mux/core.c                                 |   7 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c |   8 +-
 drivers/net/phy/mdio_bus.c                         |   9 +-
 drivers/nvmem/core.c                               |   7 +-
 drivers/of/of_mdio.c                               |   8 +-
 drivers/of/platform.c                              |   7 +-
 drivers/pci/probe.c                                |   7 +-
 drivers/regulator/of_regulator.c                   |   7 +-
 drivers/rtc/interface.c                            |  11 +-
 drivers/s390/cio/ccwgroup.c                        |  18 +-
 drivers/s390/cio/device.c                          |  15 +-
 drivers/s390/crypto/zcrypt_api.c                   |  22 +-
 drivers/scsi/scsi_proc.c                           |   9 +-
 drivers/spi/spi.c                                  |  28 +--
 drivers/tty/tty_io.c                               |   8 +-
 drivers/usb/core/devio.c                           |   8 +-
 drivers/usb/roles/class.c                          |  16 +-
 drivers/usb/typec/class.c                          |  16 +-
 include/linux/device.h                             | 237 ++++++++++++++++++++-
 include/linux/platform_device.h                    |   3 +
 net/ieee802154/core.c                              |   7 +-
 sound/soc/rockchip/rk3399_gru_sound.c              |   9 +-
 48 files changed, 341 insertions(+), 383 deletions(-)
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 0/7] drivers: Add generic device lookup helpers
@ 2019-07-30 11:56   ` Greg KH
  0 siblings, 0 replies; 71+ messages in thread
From: Greg KH @ 2019-07-30 11:56 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: linux-kernel, rafael, linux-arm-kernel, Alan Tull,
	Alessandro Zummo, Alexander Aring, Alexander Shishkin,
	Alexandre Belloni, Andrew Lunn, Arnd Bergmann, Bjorn Helgaas,
	Daniel Vetter, Dan Murphy, David Airlie, David S. Miller,
	devicetree, Doug Ledford, dri-devel, Elie Morisse, Eric Anholt,
	Florian Fainelli, Frank Rowand, Harald Freudenberger,
	Heikki Krogerus, Heiko Carstens, Heiko Stübner,
	Heiner Kallweit, Inki Dae, Jacek Anaszewski,
	James E.J. Bottomley, Jason Gunthorpe, Jiri Slaby, Joe Perches,
	Joerg Roedel, Lee Jones, Len Brown, Liam Girdwood, linux-acpi,
	linux-fpga, linux-i2c, linux-leds, linux-rockchip, linux-rtc,
	linux-spi, linux-usb, linux-wpan, Maarten Lankhorst, Mark Brown,
	Martin K. Petersen, Mathieu Poirier, Maxime Coquelin,
	Maxime Ripard, Mika Westerberg, Moritz Fischer, Nehal Shah,
	Oliver Neukum, Pavel Machek, Peter Oberparleiter, Peter Rosin,
	Rafael J. Wysocki, Rob Herring, Robin Murphy, Sandy Huang,
	Sebastian Andrzej Siewior, Seung-Woo Kim, Shyam Sundar S K,
	Srinivas Kandagatla, Stefan Schmidt, Takashi Iwai, Thor Thayer,
	Tomas Winkler, Ulf Hansson, Will Deacon, Wolfram Sang

On Tue, Jul 23, 2019 at 11:18:31PM +0100, Suzuki K Poulose wrote:
> We have device iterators to find a particular device matching a criteria
> for a given bus/class/driver. i.e, {bus,class,driver}_find_device()
> APIs. The matching criteria is a function pointer for the APIs. Often the
> lookup is based on a generic property of a device (e.g, name, fwnode, of node
> pointer or device type) rather than a driver specific information. However, each
> driver writes up its own "match" function, spilling the similar match functions
> all over the driver subsystems.
> 
> This series adds device match helpers by generic device properties of a device.
> Using these generic match functions, introduce wrappers to the existing
>  *_find_device() helpers and converts the existing users to use the new wrappers.
>  i.e,
> 	{bus/class/driver}_find_device_by_name()
> 	{bus/class/driver}_find_device_by_fwnode()
> 	{bus/class/driver}_find_device_by_devt()
> 	{bus/class/driver}_find_device_by_acpi_dev()
> 
> Also adds a wrapper for finding a platform device by driver, to avoid
> spilling the platform_bus internals in the individual drivers. Applies
> on 5.3-rc1.
> 
>    [0] git://linux-arm.org/linux-skp.git driver-cleanup/v3
> RFC[1] https://marc.info/?i=1559577023-558-1-git-send-email-suzuki.poulose@arm.com
> V1 [2] https://marc.info/?i=1559747630-28065-1-git-send-email-suzuki.poulose@arm.com
> V2 [3] https://marc.info/?i=1560534863-15115-1-git-send-email-suzuki.poulose@arm.com

There is now a persistent tag/branch in my driver-core tree for any
subsystem that wants to pull this tree in to make it easier for merges:


The following changes since commit 5f9e832c137075045d15cd6899ab0505cfb2ca4b:

  Linus 5.3-rc1 (2019-07-21 14:05:38 -0700)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git tags/generic_lookup_helpers

for you to fetch changes up to 36f3313d6bff91ab2a9e47698c27d15363640a4e:

  platform: Add platform_find_device_by_driver() helper (2019-07-30 13:07:42 +0200)

----------------------------------------------------------------
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>

----------------------------------------------------------------
Suzuki K Poulose (7):
      drivers: Introduce device lookup variants by name
      drivers: Introduce device lookup variants by of_node
      drivers: Introduce device lookup variants by fwnode
      drivers: Introduce device lookup variants by device type
      drivers: Introduce device lookup variants by ACPI_COMPANION device
      drivers: Add generic helper to match any device
      platform: Add platform_find_device_by_driver() helper

 drivers/amba/tegra-ahb.c                           |  11 +-
 drivers/base/bus.c                                 |  24 ---
 drivers/base/core.c                                |  39 +++-
 drivers/base/devcon.c                              |   8 +-
 drivers/base/platform.c                            |  14 ++
 drivers/fpga/fpga-bridge.c                         |   8 +-
 drivers/fpga/fpga-mgr.c                            |   8 +-
 drivers/gpu/drm/drm_mipi_dsi.c                     |   7 +-
 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 +-
 drivers/hwtracing/coresight/coresight-platform.c   |  11 +-
 drivers/hwtracing/coresight/coresight-priv.h       |   2 -
 drivers/hwtracing/coresight/coresight.c            |   4 +-
 drivers/hwtracing/intel_th/core.c                  |  10 +-
 drivers/hwtracing/stm/core.c                       |   9 +-
 drivers/i2c/busses/i2c-amd-mp2-pci.c               |   8 +-
 drivers/i2c/i2c-core-acpi.c                        |  11 +-
 drivers/i2c/i2c-core-of.c                          |   7 +-
 drivers/infiniband/hw/hns/hns_roce_hw_v1.c         |   8 +-
 drivers/iommu/arm-smmu-v3.c                        |   9 +-
 drivers/iommu/arm-smmu.c                           |   9 +-
 drivers/leds/led-class.c                           |   9 +-
 drivers/mfd/altera-sysmgr.c                        |  14 +-
 drivers/misc/mei/main.c                            |   9 +-
 drivers/mux/core.c                                 |   7 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c |   8 +-
 drivers/net/phy/mdio_bus.c                         |   9 +-
 drivers/nvmem/core.c                               |   7 +-
 drivers/of/of_mdio.c                               |   8 +-
 drivers/of/platform.c                              |   7 +-
 drivers/pci/probe.c                                |   7 +-
 drivers/regulator/of_regulator.c                   |   7 +-
 drivers/rtc/interface.c                            |  11 +-
 drivers/s390/cio/ccwgroup.c                        |  18 +-
 drivers/s390/cio/device.c                          |  15 +-
 drivers/s390/crypto/zcrypt_api.c                   |  22 +-
 drivers/scsi/scsi_proc.c                           |   9 +-
 drivers/spi/spi.c                                  |  28 +--
 drivers/tty/tty_io.c                               |   8 +-
 drivers/usb/core/devio.c                           |   8 +-
 drivers/usb/roles/class.c                          |  16 +-
 drivers/usb/typec/class.c                          |  16 +-
 include/linux/device.h                             | 237 ++++++++++++++++++++-
 include/linux/platform_device.h                    |   3 +
 net/ieee802154/core.c                              |   7 +-
 sound/soc/rockchip/rk3399_gru_sound.c              |   9 +-
 48 files changed, 341 insertions(+), 383 deletions(-)

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 5/7] drivers: Introduce device lookup variants by ACPI_COMPANION device
  2019-07-26 20:23     ` Wolfram Sang
  (?)
@ 2019-08-01 11:58       ` Andy Shevchenko
  -1 siblings, 0 replies; 71+ messages in thread
From: Andy Shevchenko @ 2019-08-01 11:58 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Suzuki K Poulose, Mika Westerberg, Jarkko Nikula, linux-kernel,
	gregkh, rafael, linux-arm-kernel, Len Brown, linux-acpi,
	linux-spi, Mark Brown, linux-i2c

On Fri, Jul 26, 2019 at 10:23:54PM +0200, Wolfram Sang wrote:
> On Tue, Jul 23, 2019 at 11:18:36PM +0100, Suzuki K Poulose wrote:
> > Add a generic helper to match a device by the ACPI_COMPANION device
> > and provide wrappers for the device lookup APIs.
> > 
> > Cc: Len Brown <lenb@kernel.org>
> > Cc: linux-acpi@vger.kernel.org
> > Cc: linux-spi@vger.kernel.org
> > Cc: Mark Brown <broonie@kernel.org>
> > Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
> > Cc: Wolfram Sang <wsa@the-dreams.de>
> > Cc: linux-i2c@vger.kernel.org
> > Cc: Mark Brown <broonie@kernel.org>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> > Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> 
> From my side, OK:
> 
> Acked-by: Wolfram Sang <wsa@the-dreams.de> # I2C parts
> 
> yet you missed to cc the I2C ACPI maintainers. Done so now.

Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Thanks, Wolfram, for notifying.

> 
> > ---
> >  drivers/base/core.c         |  6 ++++
> >  drivers/i2c/i2c-core-acpi.c | 11 ++-----
> >  drivers/spi/spi.c           |  8 +----
> >  include/linux/device.h      | 65 +++++++++++++++++++++++++++++++++++++
> >  4 files changed, 74 insertions(+), 16 deletions(-)
> > 
> > diff --git a/drivers/base/core.c b/drivers/base/core.c
> > index 3abc32b60c0a..57d71bc2c559 100644
> > --- a/drivers/base/core.c
> > +++ b/drivers/base/core.c
> > @@ -3373,3 +3373,9 @@ int device_match_devt(struct device *dev, const void *pdevt)
> >  	return dev->devt == *(dev_t *)pdevt;
> >  }
> >  EXPORT_SYMBOL_GPL(device_match_devt);
> > +
> > +int device_match_acpi_dev(struct device *dev, const void *adev)
> > +{
> > +	return ACPI_COMPANION(dev) == adev;
> > +}
> > +EXPORT_SYMBOL(device_match_acpi_dev);
> > diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
> > index 4dbbc9a35f65..bc80aafb521f 100644
> > --- a/drivers/i2c/i2c-core-acpi.c
> > +++ b/drivers/i2c/i2c-core-acpi.c
> > @@ -354,17 +354,11 @@ static int i2c_acpi_find_match_adapter(struct device *dev, const void *data)
> >  	return ACPI_HANDLE(dev) == (acpi_handle)data;
> >  }
> >  
> > -static int i2c_acpi_find_match_device(struct device *dev, const void *data)
> > -{
> > -	return ACPI_COMPANION(dev) == data;
> > -}
> >  
> >  struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle)
> >  {
> > -	struct device *dev;
> > +	struct device *dev = bus_find_device_by_acpi_dev(&i2c_bus_type, handle);
> >  
> > -	dev = bus_find_device(&i2c_bus_type, NULL, handle,
> > -			      i2c_acpi_find_match_adapter);
> >  	return dev ? i2c_verify_adapter(dev) : NULL;
> >  }
> >  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)
> >  {
> >  	struct device *dev;
> >  
> > -	dev = bus_find_device(&i2c_bus_type, NULL, adev,
> > -			      i2c_acpi_find_match_device);
> > +	dev = bus_find_device_by_acpi_dev(&i2c_bus_type, adev);
> >  	return dev ? i2c_verify_client(dev) : NULL;
> >  }
> >  
> > diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> > index a591da87981a..c486a6f84c2c 100644
> > --- a/drivers/spi/spi.c
> > +++ b/drivers/spi/spi.c
> > @@ -3741,11 +3741,6 @@ static int spi_acpi_controller_match(struct device *dev, const void *data)
> >  	return ACPI_COMPANION(dev->parent) == data;
> >  }
> >  
> > -static int spi_acpi_device_match(struct device *dev, const void *data)
> > -{
> > -	return ACPI_COMPANION(dev) == data;
> > -}
> > -
> >  static struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev)
> >  {
> >  	struct device *dev;
> > @@ -3765,8 +3760,7 @@ static struct spi_device *acpi_spi_find_device_by_adev(struct acpi_device *adev)
> >  {
> >  	struct device *dev;
> >  
> > -	dev = bus_find_device(&spi_bus_type, NULL, adev, spi_acpi_device_match);
> > -
> > +	dev = bus_find_device_by_acpi_dev(&spi_bus_type, adev);
> >  	return dev ? to_spi_device(dev) : NULL;
> >  }
> >  
> > diff --git a/include/linux/device.h b/include/linux/device.h
> > index 93b2f55ef44e..7514ef3d3f1a 100644
> > --- a/include/linux/device.h
> > +++ b/include/linux/device.h
> > @@ -168,6 +168,7 @@ int device_match_name(struct device *dev, const void *name);
> >  int device_match_of_node(struct device *dev, const void *np);
> >  int device_match_fwnode(struct device *dev, const void *fwnode);
> >  int device_match_devt(struct device *dev, const void *pdevt);
> > +int device_match_acpi_dev(struct device *dev, const void *adev);
> >  
> >  int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
> >  		     int (*fn)(struct device *dev, void *data));
> > @@ -224,6 +225,28 @@ static inline struct device *bus_find_device_by_devt(struct bus_type *bus,
> >  	return bus_find_device(bus, NULL, &devt, device_match_devt);
> >  }
> >  
> > +#ifdef CONFIG_ACPI
> > +struct acpi_device;
> > +
> > +/**
> > + * bus_find_device_by_acpi_dev : device iterator for locating a particular device
> > + * matching the ACPI COMPANION device.
> > + * @bus: bus type
> > + * @adev: ACPI COMPANION device to match.
> > + */
> > +static inline struct device *
> > +bus_find_device_by_acpi_dev(struct bus_type *bus, const struct acpi_device *adev)
> > +{
> > +	return bus_find_device(bus, NULL, adev, device_match_acpi_dev);
> > +}
> > +#else
> > +static inline struct device *
> > +bus_find_device_by_acpi_dev(struct bus_type *bus, const void *adev)
> > +{
> > +	return NULL;
> > +}
> > +#endif
> > +
> >  struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
> >  					struct device *hint);
> >  int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
> > @@ -442,6 +465,27 @@ static inline struct device *driver_find_device_by_devt(struct device_driver *dr
> >  	return driver_find_device(drv, NULL, &devt, device_match_devt);
> >  }
> >  
> > +#ifdef CONFIG_ACPI
> > +/**
> > + * driver_find_device_by_acpi_dev : device iterator for locating a particular
> > + * device matching the ACPI_COMPANION device.
> > + * @driver: the driver we're iterating
> > + * @adev: ACPI_COMPANION device to match.
> > + */
> > +static inline struct device *
> > +driver_find_device_by_acpi_dev(struct device_driver *drv,
> > +			       const struct acpi_device *adev)
> > +{
> > +	return driver_find_device(drv, NULL, adev, device_match_acpi_dev);
> > +}
> > +#else
> > +static inline struct device *
> > +driver_find_device_by_acpi_dev(struct device_driver *drv, const void *adev)
> > +{
> > +	return NULL;
> > +}
> > +#endif
> > +
> >  void driver_deferred_probe_add(struct device *dev);
> >  int driver_deferred_probe_check_state(struct device *dev);
> >  int driver_deferred_probe_check_state_continue(struct device *dev);
> > @@ -620,6 +664,27 @@ static inline struct device *class_find_device_by_devt(struct class *class,
> >  	return class_find_device(class, NULL, &devt, device_match_devt);
> >  }
> >  
> > +#ifdef CONFIG_ACPI
> > +struct acpi_device;
> > +/**
> > + * class_find_device_by_acpi_dev : device iterator for locating a particular
> > + * device matching the ACPI_COMPANION device.
> > + * @class: class type
> > + * @adev: ACPI_COMPANION device to match.
> > + */
> > +static inline struct device *
> > +class_find_device_by_acpi_dev(struct class *class, const struct acpi_device *adev)
> > +{
> > +	return class_find_device(class, NULL, adev, device_match_acpi_dev);
> > +}
> > +#else
> > +static inline struct device *
> > +class_find_device_by_acpi_dev(struct class *class, const void *adev)
> > +{
> > +	return NULL;
> > +}
> > +#endif
> > +
> >  struct class_attribute {
> >  	struct attribute attr;
> >  	ssize_t (*show)(struct class *class, struct class_attribute *attr,
> > -- 
> > 2.21.0
> > 



-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 5/7] drivers: Introduce device lookup variants by ACPI_COMPANION device
@ 2019-08-01 11:58       ` Andy Shevchenko
  0 siblings, 0 replies; 71+ messages in thread
From: Andy Shevchenko @ 2019-08-01 11:58 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: rafael, gregkh, Suzuki K Poulose, linux-kernel, linux-spi,
	linux-acpi, Mark Brown, Jarkko Nikula, linux-i2c,
	Mika Westerberg, linux-arm-kernel, Len Brown

On Fri, Jul 26, 2019 at 10:23:54PM +0200, Wolfram Sang wrote:
> On Tue, Jul 23, 2019 at 11:18:36PM +0100, Suzuki K Poulose wrote:
> > Add a generic helper to match a device by the ACPI_COMPANION device
> > and provide wrappers for the device lookup APIs.
> > 
> > Cc: Len Brown <lenb@kernel.org>
> > Cc: linux-acpi@vger.kernel.org
> > Cc: linux-spi@vger.kernel.org
> > Cc: Mark Brown <broonie@kernel.org>
> > Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
> > Cc: Wolfram Sang <wsa@the-dreams.de>
> > Cc: linux-i2c@vger.kernel.org
> > Cc: Mark Brown <broonie@kernel.org>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> > Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> 
> From my side, OK:
> 
> Acked-by: Wolfram Sang <wsa@the-dreams.de> # I2C parts
> 
> yet you missed to cc the I2C ACPI maintainers. Done so now.

Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Thanks, Wolfram, for notifying.

> 
> > ---
> >  drivers/base/core.c         |  6 ++++
> >  drivers/i2c/i2c-core-acpi.c | 11 ++-----
> >  drivers/spi/spi.c           |  8 +----
> >  include/linux/device.h      | 65 +++++++++++++++++++++++++++++++++++++
> >  4 files changed, 74 insertions(+), 16 deletions(-)
> > 
> > diff --git a/drivers/base/core.c b/drivers/base/core.c
> > index 3abc32b60c0a..57d71bc2c559 100644
> > --- a/drivers/base/core.c
> > +++ b/drivers/base/core.c
> > @@ -3373,3 +3373,9 @@ int device_match_devt(struct device *dev, const void *pdevt)
> >  	return dev->devt == *(dev_t *)pdevt;
> >  }
> >  EXPORT_SYMBOL_GPL(device_match_devt);
> > +
> > +int device_match_acpi_dev(struct device *dev, const void *adev)
> > +{
> > +	return ACPI_COMPANION(dev) == adev;
> > +}
> > +EXPORT_SYMBOL(device_match_acpi_dev);
> > diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
> > index 4dbbc9a35f65..bc80aafb521f 100644
> > --- a/drivers/i2c/i2c-core-acpi.c
> > +++ b/drivers/i2c/i2c-core-acpi.c
> > @@ -354,17 +354,11 @@ static int i2c_acpi_find_match_adapter(struct device *dev, const void *data)
> >  	return ACPI_HANDLE(dev) == (acpi_handle)data;
> >  }
> >  
> > -static int i2c_acpi_find_match_device(struct device *dev, const void *data)
> > -{
> > -	return ACPI_COMPANION(dev) == data;
> > -}
> >  
> >  struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle)
> >  {
> > -	struct device *dev;
> > +	struct device *dev = bus_find_device_by_acpi_dev(&i2c_bus_type, handle);
> >  
> > -	dev = bus_find_device(&i2c_bus_type, NULL, handle,
> > -			      i2c_acpi_find_match_adapter);
> >  	return dev ? i2c_verify_adapter(dev) : NULL;
> >  }
> >  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)
> >  {
> >  	struct device *dev;
> >  
> > -	dev = bus_find_device(&i2c_bus_type, NULL, adev,
> > -			      i2c_acpi_find_match_device);
> > +	dev = bus_find_device_by_acpi_dev(&i2c_bus_type, adev);
> >  	return dev ? i2c_verify_client(dev) : NULL;
> >  }
> >  
> > diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> > index a591da87981a..c486a6f84c2c 100644
> > --- a/drivers/spi/spi.c
> > +++ b/drivers/spi/spi.c
> > @@ -3741,11 +3741,6 @@ static int spi_acpi_controller_match(struct device *dev, const void *data)
> >  	return ACPI_COMPANION(dev->parent) == data;
> >  }
> >  
> > -static int spi_acpi_device_match(struct device *dev, const void *data)
> > -{
> > -	return ACPI_COMPANION(dev) == data;
> > -}
> > -
> >  static struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev)
> >  {
> >  	struct device *dev;
> > @@ -3765,8 +3760,7 @@ static struct spi_device *acpi_spi_find_device_by_adev(struct acpi_device *adev)
> >  {
> >  	struct device *dev;
> >  
> > -	dev = bus_find_device(&spi_bus_type, NULL, adev, spi_acpi_device_match);
> > -
> > +	dev = bus_find_device_by_acpi_dev(&spi_bus_type, adev);
> >  	return dev ? to_spi_device(dev) : NULL;
> >  }
> >  
> > diff --git a/include/linux/device.h b/include/linux/device.h
> > index 93b2f55ef44e..7514ef3d3f1a 100644
> > --- a/include/linux/device.h
> > +++ b/include/linux/device.h
> > @@ -168,6 +168,7 @@ int device_match_name(struct device *dev, const void *name);
> >  int device_match_of_node(struct device *dev, const void *np);
> >  int device_match_fwnode(struct device *dev, const void *fwnode);
> >  int device_match_devt(struct device *dev, const void *pdevt);
> > +int device_match_acpi_dev(struct device *dev, const void *adev);
> >  
> >  int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
> >  		     int (*fn)(struct device *dev, void *data));
> > @@ -224,6 +225,28 @@ static inline struct device *bus_find_device_by_devt(struct bus_type *bus,
> >  	return bus_find_device(bus, NULL, &devt, device_match_devt);
> >  }
> >  
> > +#ifdef CONFIG_ACPI
> > +struct acpi_device;
> > +
> > +/**
> > + * bus_find_device_by_acpi_dev : device iterator for locating a particular device
> > + * matching the ACPI COMPANION device.
> > + * @bus: bus type
> > + * @adev: ACPI COMPANION device to match.
> > + */
> > +static inline struct device *
> > +bus_find_device_by_acpi_dev(struct bus_type *bus, const struct acpi_device *adev)
> > +{
> > +	return bus_find_device(bus, NULL, adev, device_match_acpi_dev);
> > +}
> > +#else
> > +static inline struct device *
> > +bus_find_device_by_acpi_dev(struct bus_type *bus, const void *adev)
> > +{
> > +	return NULL;
> > +}
> > +#endif
> > +
> >  struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
> >  					struct device *hint);
> >  int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
> > @@ -442,6 +465,27 @@ static inline struct device *driver_find_device_by_devt(struct device_driver *dr
> >  	return driver_find_device(drv, NULL, &devt, device_match_devt);
> >  }
> >  
> > +#ifdef CONFIG_ACPI
> > +/**
> > + * driver_find_device_by_acpi_dev : device iterator for locating a particular
> > + * device matching the ACPI_COMPANION device.
> > + * @driver: the driver we're iterating
> > + * @adev: ACPI_COMPANION device to match.
> > + */
> > +static inline struct device *
> > +driver_find_device_by_acpi_dev(struct device_driver *drv,
> > +			       const struct acpi_device *adev)
> > +{
> > +	return driver_find_device(drv, NULL, adev, device_match_acpi_dev);
> > +}
> > +#else
> > +static inline struct device *
> > +driver_find_device_by_acpi_dev(struct device_driver *drv, const void *adev)
> > +{
> > +	return NULL;
> > +}
> > +#endif
> > +
> >  void driver_deferred_probe_add(struct device *dev);
> >  int driver_deferred_probe_check_state(struct device *dev);
> >  int driver_deferred_probe_check_state_continue(struct device *dev);
> > @@ -620,6 +664,27 @@ static inline struct device *class_find_device_by_devt(struct class *class,
> >  	return class_find_device(class, NULL, &devt, device_match_devt);
> >  }
> >  
> > +#ifdef CONFIG_ACPI
> > +struct acpi_device;
> > +/**
> > + * class_find_device_by_acpi_dev : device iterator for locating a particular
> > + * device matching the ACPI_COMPANION device.
> > + * @class: class type
> > + * @adev: ACPI_COMPANION device to match.
> > + */
> > +static inline struct device *
> > +class_find_device_by_acpi_dev(struct class *class, const struct acpi_device *adev)
> > +{
> > +	return class_find_device(class, NULL, adev, device_match_acpi_dev);
> > +}
> > +#else
> > +static inline struct device *
> > +class_find_device_by_acpi_dev(struct class *class, const void *adev)
> > +{
> > +	return NULL;
> > +}
> > +#endif
> > +
> >  struct class_attribute {
> >  	struct attribute attr;
> >  	ssize_t (*show)(struct class *class, struct class_attribute *attr,
> > -- 
> > 2.21.0
> > 



-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 5/7] drivers: Introduce device lookup variants by ACPI_COMPANION device
@ 2019-08-01 11:58       ` Andy Shevchenko
  0 siblings, 0 replies; 71+ messages in thread
From: Andy Shevchenko @ 2019-08-01 11:58 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: rafael, gregkh, Suzuki K Poulose, linux-kernel, linux-spi,
	linux-acpi, Mark Brown, Jarkko Nikula, linux-i2c,
	Mika Westerberg, linux-arm-kernel, Len Brown

On Fri, Jul 26, 2019 at 10:23:54PM +0200, Wolfram Sang wrote:
> On Tue, Jul 23, 2019 at 11:18:36PM +0100, Suzuki K Poulose wrote:
> > Add a generic helper to match a device by the ACPI_COMPANION device
> > and provide wrappers for the device lookup APIs.
> > 
> > Cc: Len Brown <lenb@kernel.org>
> > Cc: linux-acpi@vger.kernel.org
> > Cc: linux-spi@vger.kernel.org
> > Cc: Mark Brown <broonie@kernel.org>
> > Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
> > Cc: Wolfram Sang <wsa@the-dreams.de>
> > Cc: linux-i2c@vger.kernel.org
> > Cc: Mark Brown <broonie@kernel.org>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> > Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> 
> From my side, OK:
> 
> Acked-by: Wolfram Sang <wsa@the-dreams.de> # I2C parts
> 
> yet you missed to cc the I2C ACPI maintainers. Done so now.

Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Thanks, Wolfram, for notifying.

> 
> > ---
> >  drivers/base/core.c         |  6 ++++
> >  drivers/i2c/i2c-core-acpi.c | 11 ++-----
> >  drivers/spi/spi.c           |  8 +----
> >  include/linux/device.h      | 65 +++++++++++++++++++++++++++++++++++++
> >  4 files changed, 74 insertions(+), 16 deletions(-)
> > 
> > diff --git a/drivers/base/core.c b/drivers/base/core.c
> > index 3abc32b60c0a..57d71bc2c559 100644
> > --- a/drivers/base/core.c
> > +++ b/drivers/base/core.c
> > @@ -3373,3 +3373,9 @@ int device_match_devt(struct device *dev, const void *pdevt)
> >  	return dev->devt == *(dev_t *)pdevt;
> >  }
> >  EXPORT_SYMBOL_GPL(device_match_devt);
> > +
> > +int device_match_acpi_dev(struct device *dev, const void *adev)
> > +{
> > +	return ACPI_COMPANION(dev) == adev;
> > +}
> > +EXPORT_SYMBOL(device_match_acpi_dev);
> > diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
> > index 4dbbc9a35f65..bc80aafb521f 100644
> > --- a/drivers/i2c/i2c-core-acpi.c
> > +++ b/drivers/i2c/i2c-core-acpi.c
> > @@ -354,17 +354,11 @@ static int i2c_acpi_find_match_adapter(struct device *dev, const void *data)
> >  	return ACPI_HANDLE(dev) == (acpi_handle)data;
> >  }
> >  
> > -static int i2c_acpi_find_match_device(struct device *dev, const void *data)
> > -{
> > -	return ACPI_COMPANION(dev) == data;
> > -}
> >  
> >  struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle)
> >  {
> > -	struct device *dev;
> > +	struct device *dev = bus_find_device_by_acpi_dev(&i2c_bus_type, handle);
> >  
> > -	dev = bus_find_device(&i2c_bus_type, NULL, handle,
> > -			      i2c_acpi_find_match_adapter);
> >  	return dev ? i2c_verify_adapter(dev) : NULL;
> >  }
> >  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)
> >  {
> >  	struct device *dev;
> >  
> > -	dev = bus_find_device(&i2c_bus_type, NULL, adev,
> > -			      i2c_acpi_find_match_device);
> > +	dev = bus_find_device_by_acpi_dev(&i2c_bus_type, adev);
> >  	return dev ? i2c_verify_client(dev) : NULL;
> >  }
> >  
> > diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> > index a591da87981a..c486a6f84c2c 100644
> > --- a/drivers/spi/spi.c
> > +++ b/drivers/spi/spi.c
> > @@ -3741,11 +3741,6 @@ static int spi_acpi_controller_match(struct device *dev, const void *data)
> >  	return ACPI_COMPANION(dev->parent) == data;
> >  }
> >  
> > -static int spi_acpi_device_match(struct device *dev, const void *data)
> > -{
> > -	return ACPI_COMPANION(dev) == data;
> > -}
> > -
> >  static struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev)
> >  {
> >  	struct device *dev;
> > @@ -3765,8 +3760,7 @@ static struct spi_device *acpi_spi_find_device_by_adev(struct acpi_device *adev)
> >  {
> >  	struct device *dev;
> >  
> > -	dev = bus_find_device(&spi_bus_type, NULL, adev, spi_acpi_device_match);
> > -
> > +	dev = bus_find_device_by_acpi_dev(&spi_bus_type, adev);
> >  	return dev ? to_spi_device(dev) : NULL;
> >  }
> >  
> > diff --git a/include/linux/device.h b/include/linux/device.h
> > index 93b2f55ef44e..7514ef3d3f1a 100644
> > --- a/include/linux/device.h
> > +++ b/include/linux/device.h
> > @@ -168,6 +168,7 @@ int device_match_name(struct device *dev, const void *name);
> >  int device_match_of_node(struct device *dev, const void *np);
> >  int device_match_fwnode(struct device *dev, const void *fwnode);
> >  int device_match_devt(struct device *dev, const void *pdevt);
> > +int device_match_acpi_dev(struct device *dev, const void *adev);
> >  
> >  int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
> >  		     int (*fn)(struct device *dev, void *data));
> > @@ -224,6 +225,28 @@ static inline struct device *bus_find_device_by_devt(struct bus_type *bus,
> >  	return bus_find_device(bus, NULL, &devt, device_match_devt);
> >  }
> >  
> > +#ifdef CONFIG_ACPI
> > +struct acpi_device;
> > +
> > +/**
> > + * bus_find_device_by_acpi_dev : device iterator for locating a particular device
> > + * matching the ACPI COMPANION device.
> > + * @bus: bus type
> > + * @adev: ACPI COMPANION device to match.
> > + */
> > +static inline struct device *
> > +bus_find_device_by_acpi_dev(struct bus_type *bus, const struct acpi_device *adev)
> > +{
> > +	return bus_find_device(bus, NULL, adev, device_match_acpi_dev);
> > +}
> > +#else
> > +static inline struct device *
> > +bus_find_device_by_acpi_dev(struct bus_type *bus, const void *adev)
> > +{
> > +	return NULL;
> > +}
> > +#endif
> > +
> >  struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
> >  					struct device *hint);
> >  int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
> > @@ -442,6 +465,27 @@ static inline struct device *driver_find_device_by_devt(struct device_driver *dr
> >  	return driver_find_device(drv, NULL, &devt, device_match_devt);
> >  }
> >  
> > +#ifdef CONFIG_ACPI
> > +/**
> > + * driver_find_device_by_acpi_dev : device iterator for locating a particular
> > + * device matching the ACPI_COMPANION device.
> > + * @driver: the driver we're iterating
> > + * @adev: ACPI_COMPANION device to match.
> > + */
> > +static inline struct device *
> > +driver_find_device_by_acpi_dev(struct device_driver *drv,
> > +			       const struct acpi_device *adev)
> > +{
> > +	return driver_find_device(drv, NULL, adev, device_match_acpi_dev);
> > +}
> > +#else
> > +static inline struct device *
> > +driver_find_device_by_acpi_dev(struct device_driver *drv, const void *adev)
> > +{
> > +	return NULL;
> > +}
> > +#endif
> > +
> >  void driver_deferred_probe_add(struct device *dev);
> >  int driver_deferred_probe_check_state(struct device *dev);
> >  int driver_deferred_probe_check_state_continue(struct device *dev);
> > @@ -620,6 +664,27 @@ static inline struct device *class_find_device_by_devt(struct class *class,
> >  	return class_find_device(class, NULL, &devt, device_match_devt);
> >  }
> >  
> > +#ifdef CONFIG_ACPI
> > +struct acpi_device;
> > +/**
> > + * class_find_device_by_acpi_dev : device iterator for locating a particular
> > + * device matching the ACPI_COMPANION device.
> > + * @class: class type
> > + * @adev: ACPI_COMPANION device to match.
> > + */
> > +static inline struct device *
> > +class_find_device_by_acpi_dev(struct class *class, const struct acpi_device *adev)
> > +{
> > +	return class_find_device(class, NULL, adev, device_match_acpi_dev);
> > +}
> > +#else
> > +static inline struct device *
> > +class_find_device_by_acpi_dev(struct class *class, const void *adev)
> > +{
> > +	return NULL;
> > +}
> > +#endif
> > +
> >  struct class_attribute {
> >  	struct attribute attr;
> >  	ssize_t (*show)(struct class *class, struct class_attribute *attr,
> > -- 
> > 2.21.0
> > 



-- 
With Best Regards,
Andy Shevchenko



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 5/7] drivers: Introduce device lookup variants by ACPI_COMPANION device
  2019-08-01 11:58       ` Andy Shevchenko
@ 2019-08-01 12:08         ` Wolfram Sang
  -1 siblings, 0 replies; 71+ messages in thread
From: Wolfram Sang @ 2019-08-01 12:08 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Suzuki K Poulose, Mika Westerberg, Jarkko Nikula, linux-kernel,
	gregkh, rafael, linux-arm-kernel, Len Brown, linux-acpi,
	linux-spi, Mark Brown, linux-i2c

[-- Attachment #1: Type: text/plain, Size: 1287 bytes --]

On Thu, Aug 01, 2019 at 02:58:56PM +0300, Andy Shevchenko wrote:
> On Fri, Jul 26, 2019 at 10:23:54PM +0200, Wolfram Sang wrote:
> > On Tue, Jul 23, 2019 at 11:18:36PM +0100, Suzuki K Poulose wrote:
> > > Add a generic helper to match a device by the ACPI_COMPANION device
> > > and provide wrappers for the device lookup APIs.
> > > 
> > > Cc: Len Brown <lenb@kernel.org>
> > > Cc: linux-acpi@vger.kernel.org
> > > Cc: linux-spi@vger.kernel.org
> > > Cc: Mark Brown <broonie@kernel.org>
> > > Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
> > > Cc: Wolfram Sang <wsa@the-dreams.de>
> > > Cc: linux-i2c@vger.kernel.org
> > > Cc: Mark Brown <broonie@kernel.org>
> > > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > > Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> > > Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> > 
> > From my side, OK:
> > 
> > Acked-by: Wolfram Sang <wsa@the-dreams.de> # I2C parts
> > 
> > yet you missed to cc the I2C ACPI maintainers. Done so now.
> 
> Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> Thanks, Wolfram, for notifying.

Sure. There seems to be a problem, though? Please check:

[PATCH 1/3] i2c: Revert incorrect conversion to use generic helper

which came in today.


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 5/7] drivers: Introduce device lookup variants by ACPI_COMPANION device
@ 2019-08-01 12:08         ` Wolfram Sang
  0 siblings, 0 replies; 71+ messages in thread
From: Wolfram Sang @ 2019-08-01 12:08 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: rafael, gregkh, Suzuki K Poulose, linux-kernel, linux-spi,
	linux-acpi, Mark Brown, Jarkko Nikula, linux-i2c,
	Mika Westerberg, linux-arm-kernel, Len Brown


[-- Attachment #1.1: Type: text/plain, Size: 1287 bytes --]

On Thu, Aug 01, 2019 at 02:58:56PM +0300, Andy Shevchenko wrote:
> On Fri, Jul 26, 2019 at 10:23:54PM +0200, Wolfram Sang wrote:
> > On Tue, Jul 23, 2019 at 11:18:36PM +0100, Suzuki K Poulose wrote:
> > > Add a generic helper to match a device by the ACPI_COMPANION device
> > > and provide wrappers for the device lookup APIs.
> > > 
> > > Cc: Len Brown <lenb@kernel.org>
> > > Cc: linux-acpi@vger.kernel.org
> > > Cc: linux-spi@vger.kernel.org
> > > Cc: Mark Brown <broonie@kernel.org>
> > > Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
> > > Cc: Wolfram Sang <wsa@the-dreams.de>
> > > Cc: linux-i2c@vger.kernel.org
> > > Cc: Mark Brown <broonie@kernel.org>
> > > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > > Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> > > Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> > 
> > From my side, OK:
> > 
> > Acked-by: Wolfram Sang <wsa@the-dreams.de> # I2C parts
> > 
> > yet you missed to cc the I2C ACPI maintainers. Done so now.
> 
> Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> Thanks, Wolfram, for notifying.

Sure. There seems to be a problem, though? Please check:

[PATCH 1/3] i2c: Revert incorrect conversion to use generic helper

which came in today.


[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 5/7] drivers: Introduce device lookup variants by ACPI_COMPANION device
  2019-08-01 12:08         ` Wolfram Sang
@ 2019-08-01 12:21           ` Andy Shevchenko
  -1 siblings, 0 replies; 71+ messages in thread
From: Andy Shevchenko @ 2019-08-01 12:21 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Suzuki K Poulose, Mika Westerberg, Jarkko Nikula, linux-kernel,
	gregkh, rafael, linux-arm-kernel, Len Brown, linux-acpi,
	linux-spi, Mark Brown, linux-i2c

On Thu, Aug 01, 2019 at 02:08:30PM +0200, Wolfram Sang wrote:
> On Thu, Aug 01, 2019 at 02:58:56PM +0300, Andy Shevchenko wrote:
> > On Fri, Jul 26, 2019 at 10:23:54PM +0200, Wolfram Sang wrote:
> > > On Tue, Jul 23, 2019 at 11:18:36PM +0100, Suzuki K Poulose wrote:
> > > > Add a generic helper to match a device by the ACPI_COMPANION device
> > > > and provide wrappers for the device lookup APIs.
> > > > 
> > > > Cc: Len Brown <lenb@kernel.org>
> > > > Cc: linux-acpi@vger.kernel.org
> > > > Cc: linux-spi@vger.kernel.org
> > > > Cc: Mark Brown <broonie@kernel.org>
> > > > Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
> > > > Cc: Wolfram Sang <wsa@the-dreams.de>
> > > > Cc: linux-i2c@vger.kernel.org
> > > > Cc: Mark Brown <broonie@kernel.org>
> > > > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > > > Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> > > > Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> > > 
> > > From my side, OK:
> > > 
> > > Acked-by: Wolfram Sang <wsa@the-dreams.de> # I2C parts
> > > 
> > > yet you missed to cc the I2C ACPI maintainers. Done so now.
> > 
> > Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > 
> > Thanks, Wolfram, for notifying.
> 
> Sure. There seems to be a problem, though? Please check:
> 
> [PATCH 1/3] i2c: Revert incorrect conversion to use generic helper
> 
> which came in today.

It's again not Cc'ed to all parties.
But OK, looks good to me.
Tough may be Jarkko can test all this.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 5/7] drivers: Introduce device lookup variants by ACPI_COMPANION device
@ 2019-08-01 12:21           ` Andy Shevchenko
  0 siblings, 0 replies; 71+ messages in thread
From: Andy Shevchenko @ 2019-08-01 12:21 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: rafael, gregkh, Suzuki K Poulose, linux-kernel, linux-spi,
	linux-acpi, Mark Brown, Jarkko Nikula, linux-i2c,
	Mika Westerberg, linux-arm-kernel, Len Brown

On Thu, Aug 01, 2019 at 02:08:30PM +0200, Wolfram Sang wrote:
> On Thu, Aug 01, 2019 at 02:58:56PM +0300, Andy Shevchenko wrote:
> > On Fri, Jul 26, 2019 at 10:23:54PM +0200, Wolfram Sang wrote:
> > > On Tue, Jul 23, 2019 at 11:18:36PM +0100, Suzuki K Poulose wrote:
> > > > Add a generic helper to match a device by the ACPI_COMPANION device
> > > > and provide wrappers for the device lookup APIs.
> > > > 
> > > > Cc: Len Brown <lenb@kernel.org>
> > > > Cc: linux-acpi@vger.kernel.org
> > > > Cc: linux-spi@vger.kernel.org
> > > > Cc: Mark Brown <broonie@kernel.org>
> > > > Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
> > > > Cc: Wolfram Sang <wsa@the-dreams.de>
> > > > Cc: linux-i2c@vger.kernel.org
> > > > Cc: Mark Brown <broonie@kernel.org>
> > > > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > > > Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> > > > Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> > > 
> > > From my side, OK:
> > > 
> > > Acked-by: Wolfram Sang <wsa@the-dreams.de> # I2C parts
> > > 
> > > yet you missed to cc the I2C ACPI maintainers. Done so now.
> > 
> > Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > 
> > Thanks, Wolfram, for notifying.
> 
> Sure. There seems to be a problem, though? Please check:
> 
> [PATCH 1/3] i2c: Revert incorrect conversion to use generic helper
> 
> which came in today.

It's again not Cc'ed to all parties.
But OK, looks good to me.
Tough may be Jarkko can test all this.

-- 
With Best Regards,
Andy Shevchenko



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 5/7] drivers: Introduce device lookup variants by ACPI_COMPANION device
  2019-08-01 12:21           ` Andy Shevchenko
@ 2019-08-01 12:27             ` Wolfram Sang
  -1 siblings, 0 replies; 71+ messages in thread
From: Wolfram Sang @ 2019-08-01 12:27 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Suzuki K Poulose, Mika Westerberg, Jarkko Nikula, linux-kernel,
	gregkh, rafael, linux-arm-kernel, Len Brown, linux-acpi,
	linux-spi, Mark Brown, linux-i2c

[-- Attachment #1: Type: text/plain, Size: 220 bytes --]


> It's again not Cc'ed to all parties.
> But OK, looks good to me.
> Tough may be Jarkko can test all this.

To be fair, only Mika is listed as I2C ACPI maintainer. Feel free to add
more :) I assume Mika doesn't mind.


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH v3 5/7] drivers: Introduce device lookup variants by ACPI_COMPANION device
@ 2019-08-01 12:27             ` Wolfram Sang
  0 siblings, 0 replies; 71+ messages in thread
From: Wolfram Sang @ 2019-08-01 12:27 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: rafael, gregkh, Suzuki K Poulose, linux-kernel, linux-spi,
	linux-acpi, Mark Brown, Jarkko Nikula, linux-i2c,
	Mika Westerberg, linux-arm-kernel, Len Brown


[-- Attachment #1.1: Type: text/plain, Size: 220 bytes --]


> It's again not Cc'ed to all parties.
> But OK, looks good to me.
> Tough may be Jarkko can test all this.

To be fair, only Mika is listed as I2C ACPI maintainer. Feel free to add
more :) I assume Mika doesn't mind.


[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 71+ messages in thread

end of thread, other threads:[~2019-08-01 12:27 UTC | newest]

Thread overview: 71+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-23 22:18 [PATCH v3 0/7] drivers: Add generic device lookup helpers Suzuki K Poulose
2019-07-23 22:18 ` Suzuki K Poulose
2019-07-23 22:18 ` [PATCH v3 1/7] drivers: Introduce device lookup variants by name Suzuki K Poulose
2019-07-23 22:18   ` Suzuki K Poulose
2019-07-25 15:42   ` Alexandre Belloni
2019-07-25 15:42     ` Alexandre Belloni
2019-07-29 14:37   ` Heikki Krogerus
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-23 22:18   ` Suzuki K Poulose
2019-07-23 22:18   ` Suzuki K Poulose
2019-07-23 22:18   ` Suzuki K Poulose
2019-07-25 13:54   ` Lee Jones
2019-07-25 13:54     ` Lee Jones
2019-07-25 13:54     ` Lee Jones
2019-07-30 11:03     ` Greg KH
2019-07-30 11:03       ` Greg KH
2019-07-30 11:03       ` Greg KH
2019-07-30 11:03       ` Greg KH
2019-07-25 19:25   ` Wolfram Sang
2019-07-25 19:25     ` Wolfram Sang
2019-07-25 19:25     ` Wolfram Sang
2019-07-25 19:25     ` Wolfram Sang
2019-07-25 21:01   ` Moritz Fischer
2019-07-25 21:01     ` Moritz Fischer
2019-07-25 21:01     ` Moritz Fischer
2019-07-25 21:01     ` Moritz Fischer
2019-07-26 17:18   ` Mark Brown
2019-07-26 17:18     ` Mark Brown
2019-07-26 17:18     ` Mark Brown
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-23 22:18   ` Suzuki K Poulose
2019-07-24 10:16   ` Robin Murphy
2019-07-24 10:16     ` Robin Murphy
2019-07-25 17:10   ` Mathieu Poirier
2019-07-25 17:10     ` Mathieu Poirier
2019-07-29 14:36   ` Heikki Krogerus
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   ` 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-23 22:18   ` Suzuki K Poulose
2019-07-26 17:18   ` Mark Brown
2019-07-26 17:18     ` Mark Brown
2019-07-26 20:23   ` Wolfram Sang
2019-07-26 20:23     ` Wolfram Sang
2019-07-26 20:23     ` Wolfram Sang
2019-08-01 11:58     ` Andy Shevchenko
2019-08-01 11:58       ` Andy Shevchenko
2019-08-01 11:58       ` Andy Shevchenko
2019-08-01 12:08       ` Wolfram Sang
2019-08-01 12:08         ` Wolfram Sang
2019-08-01 12:21         ` Andy Shevchenko
2019-08-01 12:21           ` Andy Shevchenko
2019-08-01 12:27           ` Wolfram Sang
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:18   ` Suzuki K Poulose
2019-07-23 22:24   ` Bjorn Helgaas
2019-07-23 22:24     ` Bjorn Helgaas
2019-07-23 22:18 ` [PATCH v3 7/7] platform: Add platform_find_device_by_driver() helper Suzuki K Poulose
2019-07-23 22:18   ` Suzuki K Poulose
2019-07-24 10:44   ` Robin Murphy
2019-07-24 10:44     ` Robin Murphy
2019-07-25 14:10 ` [PATCH v3 0/7] drivers: Add generic device lookup helpers Greg KH
2019-07-25 14:10   ` Greg KH
2019-07-25 14:10   ` Greg KH
2019-07-30 11:56 ` Greg KH
2019-07-30 11:56   ` Greg KH
2019-07-30 11:56   ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.