Skip to contentSkip to conversation

drivers: Consolidate device lookup helpers

PATCH Applied Suzuki K Poulose 14 participants 58 messages Jun 14, 2019 – Jul 25, 2019

Subsystems (60)
lore
Share & tools
lore

Suzuki K Poulose

author maintainer
#0 lore raw

v2 cover drivers: Consolidate device lookup helpers

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.

Additionally the prototype for the "match" functions accepted by the above APIs have a minute difference which prevents us otherwise sharing the match functions. i.e,
int (*match)(struct device *dev, void *data) for {bus/driver}_find_device()
vs
int (*match)(struct device *dev, const void *) for class_find_device()

If we promote the former to accept a "const void*" parameter, we could share one single match function for all the helpers. This series achieves the following:

a) [Patches 03-05] Unify the prototype for "match" functions accepted by the device lookup APIs.
b) [Patches 06-11] Introduce generic match functions to match devices by the generic attributes of a device (e.g, name, fwnode, of_node and devt).

c) [Patches 12-27] Also, in order to prevent creation of such match functions in the future, we introduce wrapper functions for the look up APIs, which automatically uses the appropriate match functions.

i.e,
{bus/class/driver}_find_device_by_name {bus/class/driver}_find_device_by_of_node {bus/class/driver}_find_device_by_fwnode {bus/class/driver}_find_device_by_devt {bus/class/driver}_find_device_by_acpi_dev {bus/class/driver}_find_next_device

and converts the existing users to switch to the new helpers.

d) [Patch 28] Additionally, this series also adds wrapper for finding a device by matching a device driver for platform bus devices -

platform_find_device_by_driver()

to avoid a few drivers hard coding the platform bus specific details.

Applies on v5.2-rc4, available at [0]

    [0] git://linux-arm.org/linux-skp.git driver-cleanup/v2

RFC [1] https://marc.info/[email protected]
V1 [2] https://marc.info/[email protected]

Changes since v1:
- Drop start parameter for *_find_device_by_devt().
- Fix build warnings for s390
- Add *_find_device_by_acpi_dev() wrappers.
- Group wrappers and the consumers into single patch, reducing the total patches to 28 from 57. (Rafael).
- Better description for acpi cleanup patch.
- Added tags from v1.

Cc Alan Tull <[email protected]>
Cc Alessandro Zummo <[email protected]>
Cc Alexander Aring <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Alexandre Belloni <[email protected]>
Cc Andreas Noever <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Corey Minyard <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Dan Murphy <[email protected]>
Cc David Airlie <[email protected]>
Cc David Kershner <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Doug Ledford <[email protected]>
Cc Elie Morisse <[email protected]>
Cc Eric Anholt <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Frank Rowand <[email protected]>
Cc Grant Likely <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Grygorii Strashko <[email protected]>
Cc Harald Freudenberger <[email protected]>
Cc Hartmut Knaack <[email protected]>
Cc Heikki Krogerus <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc "Heiko Stübner" <[email protected]>
Cc Heiko Stuebner <[email protected]>
Cc Heiner Kallweit <[email protected]>
Cc Inki Dae <[email protected]>
Cc Jacek Anaszewski <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Jiri Slaby <[email protected]>
Cc Joe Perches <[email protected]>
Cc Joerg Roedel <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Jonathan Hunter <[email protected]>
Cc Lee Jones <[email protected]>
Cc Len Brown <[email protected]
Cc Liam Girdwood <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Mark Brown <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
Cc Mathieu Poirier <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Michael Jamet <[email protected]>
Cc Mika Westerberg <[email protected]>
Cc Moritz Fischer <[email protected]>
Cc Nehal Shah <[email protected]>
Cc Oliver Neukum <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Peter Oberparleiter <[email protected]>
Cc Peter Rosin <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Rafael J. Wysocki" <[email protected]>
Cc Rob Herring <[email protected]>
Cc Robin Murphy <[email protected]>
Cc Russell King <[email protected]>
Cc Sandy Huang <[email protected]>
Cc Sebastian Andrzej Siewior <[email protected]>
Cc Sebastian Ott <[email protected]>
Cc Seung-Woo Kim <[email protected]>
Cc Shyam Sundar S K <[email protected]>
Cc Srinivas Kandagatla <[email protected]>
Cc Stefan Schmidt <[email protected]>
Cc Takashi Iwai <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Thor Thayer <[email protected]>
Cc Tomas Winkler <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc Will Deacon <[email protected]>
Cc Wolfram Sang <[email protected]>

Suzuki K Poulose (28):
staging: most-core: Use bus_find_device_by_name
mfd: Remove unused helper syscon_regmap_lookup_by_pdevname
acpi: utils: Cleanup acpi_dev_match_cb
bus_find_device: Unify the match callback with class_find_device
driver_find_device: Unify the match function with class_find_device()
drivers: Add generic helper to match by of_node
drivers: Add generic helper to match by fwnode
drivers: Add generic helper to match by device type
drivers: Add generic match helper by ACPI_COMPANION device
drivers: Add generic helper to match by name
drivers: Add generic helper to match any device
drivers: Introduce class_find_device_by_name() helper
drivers: Introduce class_find_device_by_of_node() helper
drivers: Introduce class_find_device_by_fwnode() helper
drivers: Introduce class_find_device_by_devt() helper
drivers: Introduce class_find_device_by_acpi_dev() helper
drivers: Introduce bus_find_device_by_of_node() helper
drivers: Introduce bus_find_device_by_fwnode() helper
drivers: Introduce bus_find_device_by_devt() helper
drivers: Introduce bus_find_next_device() helper
drivers: Introduce bus_find_device_by_acpi_dev() helper
drivers: Introduce driver_find_device_by_name() helper
drivers: Introduce driver_find_device_by_of_node() helper
drivers: Introduce driver_find_device_by_fwnode() helper
drivers: Introduce driver_find_device_by_devt() helper
drivers: Introduce driver_find_next_device() helper
drivers: Introduce driver_find_device_by_acpi_dev() helper
platform: Add platform_find_device_by_driver() helper

 arch/powerpc/platforms/pseries/ibmebus.c           |   4 +-
 drivers/acpi/acpi_lpss.c                           |   4 +-
 drivers/acpi/sleep.c                               |   2 +-
 drivers/acpi/utils.c                               |  11 +-
 drivers/amba/tegra-ahb.c                           |  11 +-
 drivers/base/bus.c                                 |  28 +--
 drivers/base/core.c                                |  45 +++-
 drivers/base/devcon.c                              |   8 +-
 drivers/base/driver.c                              |   4 +-
 drivers/base/platform.c                            |  14 ++
 drivers/char/ipmi/ipmi_msghandler.c                |   8 +-
 drivers/char/ipmi/ipmi_si_platform.c               |   2 +-
 drivers/firmware/efi/dev-path-parser.c             |   4 +-
 drivers/fpga/fpga-bridge.c                         |   8 +-
 drivers/fpga/fpga-mgr.c                            |   8 +-
 drivers/fpga/of-fpga-region.c                      |   7 +-
 drivers/gpu/drm/drm_mipi_dsi.c                     |   7 +-
 drivers/gpu/drm/exynos/exynos_drm_drv.c            |   9 +-
 drivers/gpu/drm/rockchip/rockchip_drm_drv.c        |   3 +-
 drivers/gpu/drm/tegra/dc.c                         |   4 +-
 drivers/gpu/drm/vc4/vc4_drv.c                      |   3 +-
 drivers/hwtracing/coresight/coresight.c            |   6 +-
 drivers/hwtracing/coresight/of_coresight.c         |  11 +-
 drivers/hwtracing/intel_th/core.c                  |  11 +-
 drivers/hwtracing/stm/core.c                       |   9 +-
 drivers/i2c/busses/i2c-amd-mp2-pci.c               |   8 +-
 drivers/i2c/i2c-core-acpi.c                        |  10 +-
 drivers/i2c/i2c-core-of.c                          |   9 +-
 drivers/iio/inkern.c                               |   2 +-
 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/mfd/syscon.c                               |  21 --
 drivers/misc/mei/main.c                            |   9 +-
 drivers/mux/core.c                                 |   7 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c |   8 +-
 drivers/net/ethernet/ti/cpsw-phy-sel.c             |   4 +-
 drivers/net/ethernet/ti/davinci_emac.c             |   2 +-
 drivers/net/ethernet/toshiba/tc35815.c             |   4 +-
 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/pci/search.c                               |   4 +-
 drivers/regulator/of_regulator.c                   |   7 +-
 drivers/rtc/interface.c                            |  11 +-
 drivers/s390/cio/ccwgroup.c                        |  18 +-
 drivers/s390/cio/chsc_sch.c                        |   2 +-
 drivers/s390/cio/css.c                             |   4 +-
 drivers/s390/cio/device.c                          |  21 +-
 drivers/s390/cio/scm.c                             |   4 +-
 drivers/s390/crypto/ap_bus.c                       |   8 +-
 drivers/s390/crypto/zcrypt_api.c                   |  22 +-
 drivers/scsi/scsi_proc.c                           |   9 +-
 drivers/spi/spi.c                                  |  28 +--
 drivers/staging/most/core.c                        |   9 +-
 drivers/thunderbolt/switch.c                       |   4 +-
 drivers/tty/tty_io.c                               |   8 +-
 drivers/usb/core/devio.c                           |   8 +-
 drivers/usb/core/usb.c                             |   4 +-
 drivers/usb/phy/phy-am335x-control.c               |   4 +-
 drivers/usb/phy/phy-isp1301.c                      |   4 +-
 drivers/usb/roles/class.c                          |  16 +-
 drivers/usb/typec/class.c                          |  16 +-
 drivers/visorbus/visorbus_main.c                   |   4 +-
 include/linux/device.h                             | 247 ++++++++++++++++++++-
 include/linux/mfd/syscon.h                         |   6 -
 include/linux/platform_device.h                    |   3 +
 net/ieee802154/core.c                              |   7 +-
 sound/soc/rockchip/rk3399_gru_sound.c              |   9 +-
 73 files changed, 407 insertions(+), 482 deletions(-)
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#1 lore raw

PATCH v2 1/28 staging: most-core: Use bus_find_device_by_name

Use bus_find_device_by_name() helper instead of writing our own helper.

Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Christian Gromm <[email protected]>
Cc "Gustavo A. R. Silva" <[email protected]>
Cc Colin Ian King <[email protected]>

---
Hi,

This patch can be split from the series. But it will eventually conflict with the series. Hence included it here.

---
 drivers/staging/most/core.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/staging/most/core.c +1 -8
index 86a8545..b9841adb 100644
@@ -561,13 +561,6 @@ static int split_string(char *buf, char **a, char **b, char **c, char **d)
 	return 0;
 }
 
-static int match_bus_dev(struct device *dev, void *data)
-{
-	char *mdev_name = data;
-
-	return !strcmp(dev_name(dev), mdev_name);
-}
-
 /**
  * get_channel - get pointer to channel
  * @mdev: name of the device interface
@@ -579,7 +572,7 @@ static struct most_channel *get_channel(char *mdev, char *mdev_ch)
 	struct most_interface *iface;
 	struct most_channel *c, *tmp;
 
-	dev = bus_find_device(&mc.bus, NULL, mdev, match_bus_dev);
+	dev = bus_find_device_by_name(&mc.bus, NULL, mdev);
 	if (!dev)
 		return NULL;
 	iface = to_most_interface(dev);
Signature · 1 line
2.7.4
author maintainer
#2 lore raw

PATCH v2 2/28 mfd: Remove unused helper syscon_regmap_lookup_by_pdevname

In reply to Suzuki K Poulose

Nobody uses the exported helper syscon_regmap_lookup_by_pdevname, to lookup a device by name. Let us remove it.

Cc Arnd Bergman <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>

---
Hi,

This patch again, could be separate from the series. However, it will conflict with the series during the merge. I have included it here before the actual series changes appear. Please do the necessary.

---
 drivers/mfd/syscon.c       | 21 ---------------------
 include/linux/mfd/syscon.h |  6 ------
 2 files changed, 27 deletions(-)
drivers/mfd/syscon.c +0 -21
index 8ce1e41..b65e585 100644
@@ -190,27 +190,6 @@ struct regmap *syscon_regmap_lookup_by_compatible(const char *s)
 }
 EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_compatible);
 
-static int syscon_match_pdevname(struct device *dev, void *data)
-{
-	return !strcmp(dev_name(dev), (const char *)data);
-}
-
-struct regmap *syscon_regmap_lookup_by_pdevname(const char *s)
-{
-	struct device *dev;
-	struct syscon *syscon;
-
-	dev = driver_find_device(&syscon_driver.driver, NULL, (void *)s,
-				 syscon_match_pdevname);
-	if (!dev)
-		return ERR_PTR(-EPROBE_DEFER);
-
-	syscon = dev_get_drvdata(dev);
-
-	return syscon->regmap;
-}
-EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_pdevname);
-
 struct regmap *syscon_regmap_lookup_by_phandle(struct device_node *np,
 					const char *property)
 {
include/linux/mfd/syscon.h +0 -6
index f0273c9..8cfda05 100644
@@ -19,7 +19,6 @@ struct device_node;
 #ifdef CONFIG_MFD_SYSCON
 extern struct regmap *syscon_node_to_regmap(struct device_node *np);
 extern struct regmap *syscon_regmap_lookup_by_compatible(const char *s);
-extern struct regmap *syscon_regmap_lookup_by_pdevname(const char *s);
 extern struct regmap *syscon_regmap_lookup_by_phandle(
 					struct device_node *np,
 					const char *property);
@@ -34,11 +33,6 @@ static inline struct regmap *syscon_regmap_lookup_by_compatible(const char *s)
 	return ERR_PTR(-ENOTSUPP);
 }
 
-static inline struct regmap *syscon_regmap_lookup_by_pdevname(const char *s)
-{
-	return ERR_PTR(-ENOTSUPP);
-}
-
 static inline struct regmap *syscon_regmap_lookup_by_phandle(
 					struct device_node *np,
 					const char *property)
Signature · 1 line
2.7.4
Applied
#3 lore raw

Re: [PATCH v2 02/28] mfd: Remove unused helper syscon_regmap_lookup_by_pdevname

Quoted 11 lines · Suzuki K Poulose

Nobody uses the exported helper syscon_regmap_lookup_by_pdevname, to lookup a device by name. Let us remove it.

Cc Arnd Bergman <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>

---
Hi,

Quoted 7 lines

This patch again, could be separate from the series. However, it will conflict with the series during the merge. I have included it here before the actual series changes appear. Please do the necessary.

---
 drivers/mfd/syscon.c       | 21 ---------------------
 include/linux/mfd/syscon.h |  6 ------
 2 files changed, 27 deletions(-)

Applied, thanks.

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
author maintainer
#4 lore raw

PATCH v2 3/28 acpi: utils: Cleanup acpi_dev_match_cb

In reply to Suzuki K Poulose

The prototype of bus_find_device() will be unified with that of class_find_device() subsequently, but for this purpose the callback functions passed to it need to take (const void *) as the second argument. Consequently, they cannot modify the memory pointed to by that argument which currently is not the case for acpi_dev_match_cb(). However, acpi_dev_match_cb() really need not modify the "match" object passed to it, because acpi_dev_get_first_match_dev() which uses it via bus_find_device() can easily convert the result of bus_find_device() into the pointer to return.

For this reason, update acpi_dev_match_cb() to avoid the redundant memory updates.

Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
---
 drivers/acpi/utils.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/acpi/utils.c +1 -6
index 7def63a..1391b63 100644
@@ -725,8 +725,6 @@ bool acpi_dev_found(const char *hid)
 EXPORT_SYMBOL(acpi_dev_found);
 
 struct acpi_dev_match_info {
-	const char *dev_name;
-	struct acpi_device *adev;
 	struct acpi_device_id hid[2];
 	const char *uid;
 	s64 hrv;
@@ -746,9 +744,6 @@ static int acpi_dev_match_cb(struct device *dev, void *data)
 	    strcmp(adev->pnp.unique_id, match->uid)))
 		return 0;
 
-	match->dev_name = acpi_dev_name(adev);
-	match->adev = adev;
-
 	if (match->hrv == -1)
 		return 1;
 
@@ -818,7 +813,7 @@ acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
 	match.hrv = hrv;
 
 	dev = bus_find_device(&acpi_bus_type, NULL, &match, acpi_dev_match_cb);
-	return dev ? match.adev : NULL;
+	return dev ? to_acpi_device(dev) : NULL;
 }
 EXPORT_SYMBOL(acpi_dev_get_first_match_dev);
 
Signature · 1 line
2.7.4
maintainer Reviewed-by on v2 3/28
#5 lore raw

Re: [PATCH v2 03/28] acpi: utils: Cleanup acpi_dev_match_cb

Quoted 11 lines · Suzuki K Poulose

The prototype of bus_find_device() will be unified with that of class_find_device() subsequently, but for this purpose the callback functions passed to it need to take (const void *) as the second argument. Consequently, they cannot modify the memory pointed to by that argument which currently is not the case for acpi_dev_match_cb(). However, acpi_dev_match_cb() really need not modify the "match" object passed to it, because acpi_dev_get_first_match_dev() which uses it via bus_find_device() can easily convert the result of bus_find_device() into the pointer to return.

Quoted 8 lines

For this reason, update acpi_dev_match_cb() to avoid the redundant memory updates.

Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>

Or if you want me to take this patch, please let me know.

Quoted 39 lines
---
 drivers/acpi/utils.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/acpi/utils.c +1 -7
index 7def63a..1391b63 100644
@@ -725,8 +725,6 @@ bool acpi_dev_found(const char *hid)
 EXPORT_SYMBOL(acpi_dev_found);
 
 struct acpi_dev_match_info {
-       const char *dev_name;
-       struct acpi_device *adev;
        struct acpi_device_id hid[2];
        const char *uid;
        s64 hrv;
@@ -746,9 +744,6 @@ static int acpi_dev_match_cb(struct device *dev, void *data)
            strcmp(adev->pnp.unique_id, match->uid)))
                return 0;
 
-       match->dev_name = acpi_dev_name(adev);
-       match->adev = adev;
-
        if (match->hrv == -1)
                return 1;
 
@@ -818,7 +813,7 @@ acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
        match.hrv = hrv;
 
        dev = bus_find_device(&acpi_bus_type, NULL, &match, acpi_dev_match_cb);
-       return dev ? match.adev : NULL;
+       return dev ? to_acpi_device(dev) : NULL;
 }
 EXPORT_SYMBOL(acpi_dev_get_first_match_dev);
 
--

2.7.4

#6 lore raw

Re: [PATCH v2 03/28] acpi: utils: Cleanup acpi_dev_match_cb

Quoted 21 lines · Rafael J. Wysocki
Quoted 11 lines · Suzuki K Poulose

The prototype of bus_find_device() will be unified with that of class_find_device() subsequently, but for this purpose the callback functions passed to it need to take (const void *) as the second argument. Consequently, they cannot modify the memory pointed to by that argument which currently is not the case for acpi_dev_match_cb(). However, acpi_dev_match_cb() really need not modify the "match" object passed to it, because acpi_dev_get_first_match_dev() which uses it via bus_find_device() can easily convert the result of bus_find_device() into the pointer to return.

Quoted 8 lines

For this reason, update acpi_dev_match_cb() to avoid the redundant memory updates.

Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
Quoted 3 lines

Or if you want me to take this patch, please let me know.

I'll take it now, thanks.

greg k-h

author maintainer
#7 lore raw

PATCH v2 4/28 bus_find_device: Unify the match callback with class_find_device

In reply to Suzuki K Poulose

There is an arbitrary difference between the prototypes of bus_find_device() and class_find_device() preventing their callers from passing the same pair of data and match() arguments to both of them, which is the const qualifier used in the prototype of class_find_device(). If that qualifier is also used in the bus_find_device() prototype, it will be possible to pass the same match() callback function to both bus_find_device() and class_find_device(), which will allow some optimizations to be made in order to avoid code duplication going forward. Also with that, constify the "data" parameter as it is passed as a const to the match function.

For this reason, change the prototype of bus_find_device() to match the prototype of class_find_device() and adjust its callers to use the const qualifier in accordance with the new prototype of it.

Cc Alexander Shishkin <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Andreas Noever <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Corey Minyard <[email protected]>
Cc Christian Borntraeger <[email protected]>
Cc David Kershner <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc David Airlie <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Frank Rowand <[email protected]>
Cc Grygorii Strashko <[email protected]>
Cc Harald Freudenberger <[email protected]>
Cc Hartmut Knaack <[email protected]>
Cc Heiko Stuebner <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Cc Len Brown <[email protected]>
Cc Mark Brown <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Michael Jamet <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
Cc Peter Oberparleiter <[email protected]>
Cc Rob Herring <[email protected]>
Cc Sebastian Ott <[email protected]>
Cc Srinivas Kandagatla <[email protected]>
Cc Yehezkel Bernat <[email protected]>
Cc Wolfram Sang <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>

---
Changes since v1:
- Removed staging/core and mfd/syscon changes as they have been dealt with in other ways. Otherwise remains unchanged
- Fix warnings on s390 build

---
 arch/powerpc/platforms/pseries/ibmebus.c           | 4 ++--
 drivers/acpi/acpi_lpss.c                           | 4 ++--
 drivers/acpi/sleep.c                               | 2 +-
 drivers/acpi/utils.c                               | 4 ++--
 drivers/base/bus.c                                 | 6 +++---
 drivers/base/devcon.c                              | 2 +-
 drivers/char/ipmi/ipmi_si_platform.c               | 2 +-
 drivers/firmware/efi/dev-path-parser.c             | 4 ++--
 drivers/gpu/drm/drm_mipi_dsi.c                     | 2 +-
 drivers/hwtracing/coresight/coresight.c            | 6 +++---
 drivers/hwtracing/coresight/of_coresight.c         | 2 +-
 drivers/hwtracing/intel_th/core.c                  | 5 ++---
 drivers/i2c/i2c-core-acpi.c                        | 4 ++--
 drivers/i2c/i2c-core-of.c                          | 4 ++--
 drivers/iio/inkern.c                               | 2 +-
 drivers/infiniband/hw/hns/hns_roce_hw_v1.c         | 2 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 2 +-
 drivers/net/ethernet/ti/cpsw-phy-sel.c             | 4 ++--
 drivers/net/ethernet/ti/davinci_emac.c             | 2 +-
 drivers/net/ethernet/toshiba/tc35815.c             | 4 ++--
 drivers/nvmem/core.c                               | 2 +-
 drivers/of/of_mdio.c                               | 2 +-
 drivers/of/platform.c                              | 2 +-
 drivers/pci/probe.c                                | 2 +-
 drivers/pci/search.c                               | 4 ++--
 drivers/s390/cio/css.c                             | 4 ++--
 drivers/s390/cio/device.c                          | 4 ++--
 drivers/s390/cio/scm.c                             | 4 ++--
 drivers/s390/crypto/ap_bus.c                       | 8 ++++----
 drivers/scsi/scsi_proc.c                           | 2 +-
 drivers/spi/spi.c                                  | 4 ++--
 drivers/thunderbolt/switch.c                       | 4 ++--
 drivers/usb/core/devio.c                           | 4 ++--
 drivers/usb/core/usb.c                             | 4 ++--
 drivers/usb/phy/phy-am335x-control.c               | 4 ++--
 drivers/usb/phy/phy-isp1301.c                      | 4 ++--
 drivers/visorbus/visorbus_main.c                   | 4 ++--
 include/linux/device.h                             | 4 ++--
 sound/soc/rockchip/rk3399_gru_sound.c              | 2 +-
 39 files changed, 67 insertions(+), 68 deletions(-)
arch/powerpc/platforms/pseries/ibmebus.c +2 -2
index 84e8ec4..b91eb09 100644
@@ -147,13 +147,13 @@ static const struct dma_map_ops ibmebus_dma_ops = {
 	.unmap_page         = ibmebus_unmap_page,
 };
 
-static int ibmebus_match_path(struct device *dev, void *data)
+static int ibmebus_match_path(struct device *dev, const void *data)
 {
 	struct device_node *dn = to_platform_device(dev)->dev.of_node;
 	return (of_find_node_by_path(data) == dn);
 }
 
-static int ibmebus_match_node(struct device *dev, void *data)
+static int ibmebus_match_node(struct device *dev, const void *data)
 {
 	return to_platform_device(dev)->dev.of_node == data;
 }
drivers/acpi/acpi_lpss.c +2 -2
index cf76860..dc2ca78 100644
@@ -511,10 +511,10 @@ struct hid_uid {
 	const char *uid;
 };
 
-static int match_hid_uid(struct device *dev, void *data)
+static int match_hid_uid(struct device *dev, const void *data)
 {
 	struct acpi_device *adev = ACPI_COMPANION(dev);
-	struct hid_uid *id = data;
+	const struct hid_uid *id = data;
 
 	if (!adev)
 		return 0;
drivers/acpi/sleep.c +1 -1
index 8ff08e5..cd11070 100644
@@ -452,7 +452,7 @@ static int acpi_pm_prepare(void)
 	return error;
 }
 
-static int find_powerf_dev(struct device *dev, void *data)
+static int find_powerf_dev(struct device *dev, const void *data)
 {
 	struct acpi_device *device = to_acpi_device(dev);
 	const char *hid = acpi_device_hid(device);
drivers/acpi/utils.c +2 -2
index 1391b63..e3974a8 100644
@@ -730,10 +730,10 @@ struct acpi_dev_match_info {
 	s64 hrv;
 };
 
-static int acpi_dev_match_cb(struct device *dev, void *data)
+static int acpi_dev_match_cb(struct device *dev, const void *data)
 {
 	struct acpi_device *adev = to_acpi_device(dev);
-	struct acpi_dev_match_info *match = data;
+	const struct acpi_dev_match_info *match = data;
 	unsigned long long hrv;
 	acpi_status status;
 
drivers/base/bus.c +3 -3
index 0a58e96..df3cac7 100644
@@ -323,8 +323,8 @@ EXPORT_SYMBOL_GPL(bus_for_each_dev);
  * return to the caller and not iterate over any more devices.
  */
 struct device *bus_find_device(struct bus_type *bus,
-			       struct device *start, void *data,
-			       int (*match)(struct device *dev, void *data))
+			       struct device *start, const void *data,
+			       int (*match)(struct device *dev, const void *data))
 {
 	struct klist_iter i;
 	struct device *dev;
@@ -342,7 +342,7 @@ struct device *bus_find_device(struct bus_type *bus,
 }
 EXPORT_SYMBOL_GPL(bus_find_device);
 
-static int match_name(struct device *dev, void *data)
+static int match_name(struct device *dev, const void *data)
 {
 	const char *name = data;
 
drivers/base/devcon.c +1 -1
index 04db9ae..ac026d5 100644
@@ -107,7 +107,7 @@ static struct bus_type *generic_match_buses[] = {
 	NULL,
 };
 
-static int device_fwnode_match(struct device *dev, void *fwnode)
+static int device_fwnode_match(struct device *dev, const void *fwnode)
 {
 	return dev_fwnode(dev) == fwnode;
 }
drivers/char/ipmi/ipmi_si_platform.c +1 -1
index f2a91c4..fd94c42 100644
@@ -426,7 +426,7 @@ static int ipmi_remove(struct platform_device *pdev)
 	return ipmi_si_remove_by_dev(&pdev->dev);
 }
 
-static int pdev_match_name(struct device *dev, void *data)
+static int pdev_match_name(struct device *dev, const void *data)
 {
 	struct platform_device *pdev = to_platform_device(dev);
 	const char *name = data;
drivers/firmware/efi/dev-path-parser.c +2 -2
index 85ec99f..2012338 100644
@@ -17,9 +17,9 @@ struct acpi_hid_uid {
 	char uid[11]; /* UINT_MAX + null byte */
 };
 
-static int __init match_acpi_dev(struct device *dev, void *data)
+static int __init match_acpi_dev(struct device *dev, const void *data)
 {
-	struct acpi_hid_uid hid_uid = *(struct acpi_hid_uid *)data;
+	struct acpi_hid_uid hid_uid = *(const struct acpi_hid_uid *)data;
 	struct acpi_device *adev = to_acpi_device(dev);
 
 	if (acpi_match_device_ids(adev, hid_uid.hid))
drivers/gpu/drm/drm_mipi_dsi.c +1 -1
index 80b7550..ad19df0 100644
@@ -93,7 +93,7 @@ static struct bus_type mipi_dsi_bus_type = {
 	.pm = &mipi_dsi_device_pm_ops,
 };
 
-static int of_device_match(struct device *dev, void *data)
+static int of_device_match(struct device *dev, const void *data)
 {
 	return dev->of_node == data;
 }
drivers/hwtracing/coresight/coresight.c +3 -3
index 4b13028..b67ab6a 100644
@@ -498,9 +498,9 @@ struct coresight_device *coresight_get_sink(struct list_head *path)
 	return csdev;
 }
 
-static int coresight_enabled_sink(struct device *dev, void *data)
+static int coresight_enabled_sink(struct device *dev, const void *data)
 {
-	bool *reset = data;
+	const bool *reset = data;
 	struct coresight_device *csdev = to_coresight_device(dev);
 
 	if ((csdev->type == CORESIGHT_DEV_TYPE_SINK ||
@@ -544,7 +544,7 @@ struct coresight_device *coresight_get_enabled_sink(bool deactivate)
 	return dev ? to_coresight_device(dev) : NULL;
 }
 
-static int coresight_sink_by_id(struct device *dev, void *data)
+static int coresight_sink_by_id(struct device *dev, const void *data)
 {
 	struct coresight_device *csdev = to_coresight_device(dev);
 	unsigned long hash;
drivers/hwtracing/coresight/of_coresight.c +1 -1
index 7045930..3fc200e 100644
@@ -18,7 +18,7 @@
 #include <asm/smp_plat.h>
 
 
-static int of_dev_node_match(struct device *dev, void *data)
+static int of_dev_node_match(struct device *dev, const void *data)
 {
 	return dev->of_node == data;
 }
drivers/hwtracing/intel_th/core.c +2 -3
index 033dce5..5592289 100644
@@ -789,10 +789,9 @@ static int intel_th_populate(struct intel_th *th)
 	return 0;
 }
 
-static int match_devt(struct device *dev, void *data)
+static int match_devt(struct device *dev, const void *data)
 {
-	dev_t devt = (dev_t)(unsigned long)data;
-
+	dev_t devt = (dev_t)(unsigned long)(void *)data;
 	return dev->devt == devt;
 }
 
drivers/i2c/i2c-core-acpi.c +2 -2
index d840955..8af35f11 100644
@@ -318,7 +318,7 @@ u32 i2c_acpi_find_bus_speed(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(i2c_acpi_find_bus_speed);
 
-static int i2c_acpi_find_match_adapter(struct device *dev, void *data)
+static int i2c_acpi_find_match_adapter(struct device *dev, const void *data)
 {
 	struct i2c_adapter *adapter = i2c_verify_adapter(dev);
 
@@ -328,7 +328,7 @@ static int i2c_acpi_find_match_adapter(struct device *dev, void *data)
 	return ACPI_HANDLE(dev) == (acpi_handle)data;
 }
 
-static int i2c_acpi_find_match_device(struct device *dev, void *data)
+static int i2c_acpi_find_match_device(struct device *dev, const void *data)
 {
 	return ACPI_COMPANION(dev) == data;
 }
drivers/i2c/i2c-core-of.c +2 -2
index 406e5f6..2eb59a2 100644
@@ -112,12 +112,12 @@ void of_i2c_register_devices(struct i2c_adapter *adap)
 	of_node_put(bus);
 }
 
-static int of_dev_node_match(struct device *dev, void *data)
+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, void *data)
+static int of_dev_or_parent_node_match(struct device *dev, const void *data)
 {
 	if (dev->of_node == data)
 		return 1;
drivers/iio/inkern.c +1 -1
index 4a5eff3..c46fb59 100644
@@ -93,7 +93,7 @@ static const struct iio_chan_spec
 
 #ifdef CONFIG_OF
 
-static int iio_dev_node_match(struct device *dev, void *data)
+static int iio_dev_node_match(struct device *dev, const void *data)
 {
 	return dev->of_node == data && dev->type == &iio_device_type;
 }
drivers/infiniband/hw/hns/hns_roce_hw_v1.c +1 -1
index e068a02..3afd3e9 100644
@@ -4498,7 +4498,7 @@ 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, void *fwnode)
+static int hns_roce_node_match(struct device *dev, const void *fwnode)
 {
 	return dev->fwnode == fwnode;
 }
drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c +1 -1
index 09c16d8..bb6586d 100644
@@ -754,7 +754,7 @@ 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, void *fwnode)
+static int hns_dsaf_dev_match(struct device *dev, const void *fwnode)
 {
 	return dev->fwnode == fwnode;
 }
drivers/net/ethernet/ti/cpsw-phy-sel.c +2 -2
index 48e0924..4e184ee 100644
@@ -151,9 +151,9 @@ static void cpsw_gmii_sel_dra7xx(struct cpsw_phy_sel_priv *priv,
 }
 
 static struct platform_driver cpsw_phy_sel_driver;
-static int match(struct device *dev, void *data)
+static int match(struct device *dev, const void *data)
 {
-	struct device_node *node = (struct device_node *)data;
+	const struct device_node *node = (const struct device_node *)data;
 	return dev->of_node == node &&
 		dev->driver == &cpsw_phy_sel_driver.driver;
 }
drivers/net/ethernet/ti/davinci_emac.c +1 -1
index 4bf65ca..57d131a 100644
@@ -1371,7 +1371,7 @@ static int emac_devioctl(struct net_device *ndev, struct ifreq *ifrq, int cmd)
 		return -EOPNOTSUPP;
 }
 
-static int match_first_device(struct device *dev, void *data)
+static int match_first_device(struct device *dev, const void *data)
 {
 	if (dev->parent && dev->parent->of_node)
 		return of_device_is_compatible(dev->parent->of_node,
drivers/net/ethernet/toshiba/tc35815.c +2 -2
index c50a977..8479a44 100644
@@ -694,10 +694,10 @@ static int tc_mii_init(struct net_device *dev)
  * should provide a "tc35815-mac" device with a MAC address in its
  * platform_data.
  */
-static int tc35815_mac_match(struct device *dev, void *data)
+static int tc35815_mac_match(struct device *dev, const void *data)
 {
 	struct platform_device *plat_dev = to_platform_device(dev);
-	struct pci_dev *pci_dev = data;
+	const struct pci_dev *pci_dev = data;
 	unsigned int id = pci_dev->irq;
 	return !strcmp(plat_dev->name, "tc35815-mac") && plat_dev->id == id;
 }
drivers/nvmem/core.c +1 -1
index c7892c3..ac5d945 100644
@@ -76,7 +76,7 @@ static struct bus_type nvmem_bus_type = {
 	.name		= "nvmem",
 };
 
-static int of_nvmem_match(struct device *dev, void *nvmem_np)
+static int of_nvmem_match(struct device *dev, const void *nvmem_np)
 {
 	return dev->of_node == nvmem_np;
 }
drivers/of/of_mdio.c +1 -1
index 3b67896..44f5349 100644
@@ -281,7 +281,7 @@ 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, void *phy_np)
+static int of_phy_match(struct device *dev, const void *phy_np)
 {
 	return dev->of_node == phy_np;
 }
drivers/of/platform.c +1 -1
index 04ad312..008d79e 100644
@@ -37,7 +37,7 @@ static const struct of_device_id of_skipped_node_table[] = {
 	{} /* Empty terminated list */
 };
 
-static int of_dev_node_match(struct device *dev, void *data)
+static int of_dev_node_match(struct device *dev, const void *data)
 {
 	return dev->of_node == data;
 }
drivers/pci/probe.c +1 -1
index 0e8e2c1..f9ef7ad 100644
@@ -64,7 +64,7 @@ static struct resource *get_pci_domain_busn_res(int domain_nr)
 	return &r->res;
 }
 
-static int find_anything(struct device *dev, void *data)
+static int find_anything(struct device *dev, const void *data)
 {
 	return 1;
 }
drivers/pci/search.c +2 -2
index 5c79226..7f4e658 100644
@@ -236,10 +236,10 @@ struct pci_dev *pci_get_domain_bus_and_slot(int domain, unsigned int bus,
 }
 EXPORT_SYMBOL(pci_get_domain_bus_and_slot);
 
-static int match_pci_dev_by_id(struct device *dev, void *data)
+static int match_pci_dev_by_id(struct device *dev, const void *data)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
-	struct pci_device_id *id = data;
+	const struct pci_device_id *id = data;
 
 	if (pci_match_one_device(id, pdev))
 		return 1;
drivers/s390/cio/css.c +2 -2
index aea5029..a2c9783 100644
@@ -434,10 +434,10 @@ static int css_probe_device(struct subchannel_id schid, struct schib *schib)
 }
 
 static int
-check_subchannel(struct device * dev, void * data)
+check_subchannel(struct device *dev, const void *data)
 {
 	struct subchannel *sch;
-	struct subchannel_id *schid = data;
+	struct subchannel_id *schid = (void *)data;
 
 	sch = to_subchannel(dev);
 	return schid_equal(&sch->schid, schid);
drivers/s390/cio/device.c +2 -2
index 1540229..d32f373 100644
@@ -642,10 +642,10 @@ static int ccw_device_add(struct ccw_device *cdev)
 	return device_add(dev);
 }
 
-static int match_dev_id(struct device *dev, void *data)
+static int match_dev_id(struct device *dev, const void *data)
 {
 	struct ccw_device *cdev = to_ccwdev(dev);
-	struct ccw_dev_id *dev_id = data;
+	struct ccw_dev_id *dev_id = (void *)data;
 
 	return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id);
 }
drivers/s390/cio/scm.c +2 -2
index 6bca1d5..9f26d43 100644
@@ -174,10 +174,10 @@ static void scmdev_update(struct scm_device *scmdev, struct sale *sale)
 		kobject_uevent(&scmdev->dev.kobj, KOBJ_CHANGE);
 }
 
-static int check_address(struct device *dev, void *data)
+static int check_address(struct device *dev, const void *data)
 {
 	struct scm_device *scmdev = to_scm_dev(dev);
-	struct sale *sale = data;
+	const struct sale *sale = data;
 
 	return scmdev->address == sale->sa;
 }
drivers/s390/crypto/ap_bus.c +4 -4
index b9fc502..b7902b6 100644
@@ -1356,16 +1356,16 @@ static int ap_get_compatible_type(ap_qid_t qid, int rawtype, unsigned int func)
  * Helper function to be used with bus_find_dev
  * matches for the card device with the given id
  */
-static int __match_card_device_with_id(struct device *dev, void *data)
+static int __match_card_device_with_id(struct device *dev, const void *data)
 {
-	return is_card_dev(dev) && to_ap_card(dev)->id == (int)(long) data;
+	return is_card_dev(dev) && to_ap_card(dev)->id == (int)(long)(void *) data;
 }
 
 /*
  * Helper function to be used with bus_find_dev
  * matches for the queue device with a given qid
  */
-static int __match_queue_device_with_qid(struct device *dev, void *data)
+static int __match_queue_device_with_qid(struct device *dev, const void *data)
 {
 	return is_queue_dev(dev) && to_ap_queue(dev)->qid == (int)(long) data;
 }
@@ -1374,7 +1374,7 @@ static int __match_queue_device_with_qid(struct device *dev, void *data)
  * Helper function to be used with bus_find_dev
  * matches any queue device with given queue id
  */
-static int __match_queue_device_with_queue_id(struct device *dev, void *data)
+static int __match_queue_device_with_queue_id(struct device *dev, const void *data)
 {
 	return is_queue_dev(dev)
 		&& AP_QID_QUEUE(to_ap_queue(dev)->qid) == (int)(long) data;
drivers/scsi/scsi_proc.c +1 -1
index 7f0ceb6..c074631 100644
@@ -372,7 +372,7 @@ static ssize_t proc_scsi_write(struct file *file, const char __user *buf,
 	return err;
 }
 
-static int always_match(struct device *dev, void *data)
+static int always_match(struct device *dev, const void *data)
 {
 	return 1;
 }
drivers/spi/spi.c +2 -2
index 5e75944..3da1121 100644
@@ -3538,7 +3538,7 @@ EXPORT_SYMBOL_GPL(spi_write_then_read);
 /*-------------------------------------------------------------------------*/
 
 #if IS_ENABLED(CONFIG_OF)
-static int __spi_of_device_match(struct device *dev, void *data)
+static int __spi_of_device_match(struct device *dev, const void *data)
 {
 	return dev->of_node == data;
 }
@@ -3639,7 +3639,7 @@ 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, void *data)
+static int spi_acpi_device_match(struct device *dev, const void *data)
 {
 	return ACPI_COMPANION(dev) == data;
 }
drivers/thunderbolt/switch.c +2 -2
index c1b0165..c9a7e4a 100644
@@ -1946,10 +1946,10 @@ struct tb_sw_lookup {
 	u64 route;
 };
 
-static int tb_switch_match(struct device *dev, void *data)
+static int tb_switch_match(struct device *dev, const void *data)
 {
 	struct tb_switch *sw = tb_to_switch(dev);
-	struct tb_sw_lookup *lookup = data;
+	const struct tb_sw_lookup *lookup = data;
 
 	if (!sw)
 		return 0;
drivers/usb/core/devio.c +2 -2
index fa783531..7bd7de7 100644
@@ -947,9 +947,9 @@ static int parse_usbdevfs_streams(struct usb_dev_state *ps,
 	return ret;
 }
 
-static int match_devt(struct device *dev, void *data)
+static int match_devt(struct device *dev, const void *data)
 {
-	return dev->devt == (dev_t) (unsigned long) data;
+	return dev->devt == (dev_t)(unsigned long)(void *)data;
 }
 
 static struct usb_device *usbdev_lookup_by_devt(dev_t devt)
drivers/usb/core/usb.c +2 -2
index 7fcb9f7..1678e30 100644
@@ -325,9 +325,9 @@ struct find_interface_arg {
 	struct device_driver *drv;
 };
 
-static int __find_interface(struct device *dev, void *data)
+static int __find_interface(struct device *dev, const void *data)
 {
-	struct find_interface_arg *arg = data;
+	const struct find_interface_arg *arg = data;
 	struct usb_interface *intf;
 
 	if (!is_usb_interface(dev))
drivers/usb/phy/phy-am335x-control.c +2 -2
index a3cb25c..d16dfc3 100644
@@ -118,9 +118,9 @@ static const struct of_device_id omap_control_usb_id_table[] = {
 MODULE_DEVICE_TABLE(of, omap_control_usb_id_table);
 
 static struct platform_driver am335x_control_driver;
-static int match(struct device *dev, void *data)
+static int match(struct device *dev, const void *data)
 {
-	struct device_node *node = (struct device_node *)data;
+	const struct device_node *node = (const struct device_node *)data;
 	return dev->of_node == node &&
 		dev->driver == &am335x_control_driver.driver;
 }
drivers/usb/phy/phy-isp1301.c +2 -2
index 93b7d6a..6cf6fbd 100644
@@ -142,9 +142,9 @@ static struct i2c_driver isp1301_driver = {
 
 module_i2c_driver(isp1301_driver);
 
-static int match(struct device *dev, void *data)
+static int match(struct device *dev, const void *data)
 {
-	struct device_node *node = (struct device_node *)data;
+	const struct device_node *node = (const struct device_node *)data;
 	return (dev->of_node == node) &&
 		(dev->driver == &isp1301_driver.driver);
 }
drivers/visorbus/visorbus_main.c +2 -2
index 0b2434c..152fd29 100644
@@ -171,10 +171,10 @@ struct visor_busdev {
 	u32 dev_no;
 };
 
-static int match_visorbus_dev_by_id(struct device *dev, void *data)
+static int match_visorbus_dev_by_id(struct device *dev, const void *data)
 {
 	struct visor_device *vdev = to_visor_device(dev);
-	struct visor_busdev *id = data;
+	const struct visor_busdev *id = data;
 
 	if (vdev->chipset_bus_no == id->bus_no &&
 	    vdev->chipset_dev_no == id->dev_no)
include/linux/device.h +2 -2
index e85264f..cbbdcadc 100644
@@ -166,8 +166,8 @@ void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
 		     int (*fn)(struct device *dev, void *data));
 struct device *bus_find_device(struct bus_type *bus, struct device *start,
-			       void *data,
-			       int (*match)(struct device *dev, void *data));
+			       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);
sound/soc/rockchip/rk3399_gru_sound.c +1 -1
index 3d0cc6e..c04c9ed 100644
@@ -405,7 +405,7 @@ static const struct dailink_match_data dailink_match[] = {
 	},
 };
 
-static int of_dev_node_match(struct device *dev, void *data)
+static int of_dev_node_match(struct device *dev, const void *data)
 {
 	return dev->of_node == data;
 }
Signature · 1 line
2.7.4
Acked-by on v2 4/28
#8 lore raw

Re: [PATCH v2 04/28] bus_find_device: Unify the match callback with class_find_device

Quoted 11 lines · Suzuki K Poulose

There is an arbitrary difference between the prototypes of bus_find_device() and class_find_device() preventing their callers from passing the same pair of data and match() arguments to both of them, which is the const qualifier used in the prototype of class_find_device(). If that qualifier is also used in the bus_find_device() prototype, it will be possible to pass the same match() callback function to both bus_find_device() and class_find_device(), which will allow some optimizations to be made in order to avoid code duplication going forward. Also with that, constify the "data" parameter as it is passed as a const to the match function.

Quoted 3 lines

For this reason, change the prototype of bus_find_device() to match the prototype of class_find_device() and adjust its callers to use the const qualifier in accordance with the new prototype of it.

Acked-by on v2 4/28
#9 lore raw

Re: [PATCH v2 04/28] bus_find_device: Unify the match callback with class_find_device

In reply to Suzuki K Poulose
Quoted 47 lines · Suzuki K Poulose

There is an arbitrary difference between the prototypes of bus_find_device() and class_find_device() preventing their callers from passing the same pair of data and match() arguments to both of them, which is the const qualifier used in the prototype of class_find_device(). If that qualifier is also used in the bus_find_device() prototype, it will be possible to pass the same match() callback function to both bus_find_device() and class_find_device(), which will allow some optimizations to be made in order to avoid code duplication going forward. Also with that, constify the "data" parameter as it is passed as a const to the match function.

For this reason, change the prototype of bus_find_device() to match the prototype of class_find_device() and adjust its callers to use the const qualifier in accordance with the new prototype of it.

Cc Alexander Shishkin <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Andreas Noever <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Corey Minyard <[email protected]>
Cc Christian Borntraeger <[email protected]>
Cc David Kershner <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc David Airlie <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Frank Rowand <[email protected]>
Cc Grygorii Strashko <[email protected]>
Cc Harald Freudenberger <[email protected]>
Cc Hartmut Knaack <[email protected]>
Cc Heiko Stuebner <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Cc Len Brown <[email protected]>
Cc Mark Brown <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Michael Jamet <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
Cc Peter Oberparleiter <[email protected]>
Cc Rob Herring <[email protected]>
Cc Sebastian Ott <[email protected]>
Cc Srinivas Kandagatla <[email protected]>
Cc Yehezkel Bernat <[email protected]>
Cc Wolfram Sang <[email protected]>
Quoted 8 lines
author maintainer
#10 lore raw

PATCH v2 5/28 driver_find_device: Unify the match function with class_find_device()

In reply to Suzuki K Poulose

The driver_find_device() accepts a match function pointer to filter the devices for lookup, similar to bus/class_find_device(). However, there is a minor difference in the prototype for the match parameter for driver_find_device() with the now unified version accepted by {bus/class}_find_device(), where it doesn't accept a "const" qualifier for the data argument. This prevents us from reusing the generic match functions for driver_find_device().

For this reason, change the prototype of the driver_find_device() to make the "match" parameter in line with {bus/class}_find_device() and adjust its callers to use the const qualifier. Also, we could now promote the "data" parameter to const as we pass it down as a const parameter to the match functions.

Cc Corey Minyard <[email protected]>
Cc Russell King <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Will Deacon <[email protected]>
Cc Joerg Roedel <[email protected]>
Cc Peter Oberparleiter <[email protected]>
Cc Sebastian Ott <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Nehal Shah <[email protected]>
Cc Shyam Sundar S K <[email protected]>
Cc Lee Jones <[email protected]>
Cc Christian Borntraeger <[email protected]>
---
 drivers/amba/tegra-ahb.c             | 4 ++--
 drivers/base/driver.c                | 4 ++--
 drivers/char/ipmi/ipmi_msghandler.c  | 8 ++++----
 drivers/gpu/drm/tegra/dc.c           | 4 ++--
 drivers/i2c/busses/i2c-amd-mp2-pci.c | 2 +-
 drivers/iommu/arm-smmu-v3.c          | 2 +-
 drivers/iommu/arm-smmu.c             | 2 +-
 drivers/mfd/altera-sysmgr.c          | 4 ++--
 drivers/s390/cio/ccwgroup.c          | 4 ++--
 drivers/s390/cio/chsc_sch.c          | 2 +-
 drivers/s390/cio/device.c            | 2 +-
 include/linux/device.h               | 4 ++--
 12 files changed, 21 insertions(+), 21 deletions(-)
drivers/amba/tegra-ahb.c +2 -2
index 3eaa459..aa64eec 100644
@@ -134,10 +134,10 @@ 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, void *data)
+static int tegra_ahb_match_by_smmu(struct device *dev, const void *data)
 {
 	struct tegra_ahb *ahb = dev_get_drvdata(dev);
-	struct device_node *dn = data;
+	const struct device_node *dn = data;
 
 	return (ahb->dev->of_node == dn) ? 1 : 0;
 }
drivers/base/driver.c +2 -2
index 857c8f1..4e5ca63 100644
@@ -73,8 +73,8 @@ EXPORT_SYMBOL_GPL(driver_for_each_device);
  * return to the caller and not iterate over any more devices.
  */
 struct device *driver_find_device(struct device_driver *drv,
-				  struct device *start, void *data,
-				  int (*match)(struct device *dev, void *data))
+				  struct device *start, const void *data,
+				  int (*match)(struct device *dev, const void *data))
 {
 	struct klist_iter i;
 	struct device *dev;
drivers/char/ipmi/ipmi_msghandler.c +4 -4
index 1dc1074..6707659 100644
@@ -2819,9 +2819,9 @@ static const struct device_type bmc_device_type = {
 	.groups		= bmc_dev_attr_groups,
 };
 
-static int __find_bmc_guid(struct device *dev, void *data)
+static int __find_bmc_guid(struct device *dev, const void *data)
 {
-	guid_t *guid = data;
+	const guid_t *guid = data;
 	struct bmc_device *bmc;
 	int rv;
 
@@ -2857,9 +2857,9 @@ struct prod_dev_id {
 	unsigned char device_id;
 };
 
-static int __find_bmc_prod_dev_id(struct device *dev, void *data)
+static int __find_bmc_prod_dev_id(struct device *dev, const void *data)
 {
-	struct prod_dev_id *cid = data;
+	const struct prod_dev_id *cid = data;
 	struct bmc_device *bmc;
 	int rv;
 
drivers/gpu/drm/tegra/dc.c +2 -2
index 607a6ea1..52109a6 100644
@@ -2375,10 +2375,10 @@ static int tegra_dc_parse_dt(struct tegra_dc *dc)
 	return 0;
 }
 
-static int tegra_dc_match_by_pipe(struct device *dev, void *data)
+static int tegra_dc_match_by_pipe(struct device *dev, const void *data)
 {
 	struct tegra_dc *dc = dev_get_drvdata(dev);
-	unsigned int pipe = (unsigned long)data;
+	unsigned int pipe = (unsigned long)(void *)data;
 
 	return dc->pipe == pipe;
 }
drivers/i2c/busses/i2c-amd-mp2-pci.c +1 -1
index 455e1f3..c7fe3b4 100644
@@ -457,7 +457,7 @@ static struct pci_driver amd_mp2_pci_driver = {
 };
 module_pci_driver(amd_mp2_pci_driver);
 
-static int amd_mp2_device_match(struct device *dev, void *data)
+static int amd_mp2_device_match(struct device *dev, const void *data)
 {
 	return 1;
 }
drivers/iommu/arm-smmu-v3.c +1 -1
index 4d5a694..d787856 100644
@@ -2023,7 +2023,7 @@ 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, void *data)
+static int arm_smmu_match_node(struct device *dev, const void *data)
 {
 	return dev->fwnode == data;
 }
drivers/iommu/arm-smmu.c +1 -1
index 5aeb1db..3af579a 100644
@@ -1419,7 +1419,7 @@ static bool arm_smmu_capable(enum iommu_cap cap)
 	}
 }
 
-static int arm_smmu_match_node(struct device *dev, void *data)
+static int arm_smmu_match_node(struct device *dev, const void *data)
 {
 	return dev->fwnode == data;
 }
drivers/mfd/altera-sysmgr.c +2 -2
index 8976f82..2ee14d8 100644
@@ -92,9 +92,9 @@ static struct regmap_config altr_sysmgr_regmap_cfg = {
  * Matching function used by driver_find_device().
  * Return: True if match is found, otherwise false.
  */
-static int sysmgr_match_phandle(struct device *dev, void *data)
+static int sysmgr_match_phandle(struct device *dev, const void *data)
 {
-	return dev->of_node == (struct device_node *)data;
+	return dev->of_node == (const struct device_node *)data;
 }
 
 /**
drivers/s390/cio/ccwgroup.c +2 -2
index 4ebf6d4..ea176157 100644
@@ -581,7 +581,7 @@ int ccwgroup_driver_register(struct ccwgroup_driver *cdriver)
 }
 EXPORT_SYMBOL(ccwgroup_driver_register);
 
-static int __ccwgroup_match_all(struct device *dev, void *data)
+static int __ccwgroup_match_all(struct device *dev, const void *data)
 {
 	return 1;
 }
@@ -608,7 +608,7 @@ void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver)
 }
 EXPORT_SYMBOL(ccwgroup_driver_unregister);
 
-static int __ccwgroupdev_check_busid(struct device *dev, void *id)
+static int __ccwgroupdev_check_busid(struct device *dev, const void *id)
 {
 	char *bus_id = id;
 
drivers/s390/cio/chsc_sch.c +1 -1
index 8d9f366..8f080d3 100644
@@ -203,7 +203,7 @@ static void chsc_cleanup_sch_driver(void)
 
 static DEFINE_SPINLOCK(chsc_lock);
 
-static int chsc_subchannel_match_next_free(struct device *dev, void *data)
+static int chsc_subchannel_match_next_free(struct device *dev, const void *data)
 {
 	struct subchannel *sch = to_subchannel(dev);
 
drivers/s390/cio/device.c +1 -1
index d32f373..f27536b 100644
@@ -1653,7 +1653,7 @@ EXPORT_SYMBOL_GPL(ccw_device_force_console);
  * get ccw_device matching the busid, but only if owned by cdrv
  */
 static int
-__ccwdev_check_busid(struct device *dev, void *id)
+__ccwdev_check_busid(struct device *dev, const void *id)
 {
 	char *bus_id;
 
include/linux/device.h +2 -2
index cbbdcadc..4d7c881 100644
@@ -336,8 +336,8 @@ extern int __must_check driver_for_each_device(struct device_driver *drv,
 					       int (*fn)(struct device *dev,
 							 void *));
 struct device *driver_find_device(struct device_driver *drv,
-				  struct device *start, void *data,
-				  int (*match)(struct device *dev, void *data));
+				  struct device *start, const void *data,
+				  int (*match)(struct device *dev, const void *data));
 
 void driver_deferred_probe_add(struct device *dev);
 int driver_deferred_probe_check_state(struct device *dev);
Signature · 1 line
2.7.4
author maintainer
#11 lore raw

PATCH v2 6/28 drivers: Add generic helper to match by of_node

In reply to Suzuki K Poulose

Add a helper to match device by the of_node. This will be later used to provide wrappers to the device iterators for {bus/class/driver}_find_device(). Convert other users to reuse this new helper.

Cc Alan Tull <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc David Airlie <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Frank Rowand <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Heiner Kallweit <[email protected]>
Cc Jiri Slaby <[email protected]>
Cc Jonathan Hunter <[email protected]>
Cc Lee Jones <[email protected]>
Cc Liam Girdwood <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Mark Brown <[email protected]>
Cc Mathieu Poirier <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Moritz Fischer <[email protected]>
Cc Peter Rosin <[email protected]>
Cc Rob Herring <[email protected]>
Cc Srinivas Kandagatla <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Thor Thayer <[email protected]>
Cc Wolfram Sang <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc Joe Perches <[email protected]>
---
 drivers/base/core.c           | 6 ++++++
 drivers/fpga/of-fpga-region.c | 7 +------
 include/linux/device.h        | 2 ++
 3 files changed, 9 insertions(+), 6 deletions(-)
drivers/base/core.c +6 -0
index fd7511e..9211908 100644
@@ -3328,3 +3328,9 @@ void device_set_of_node_from_dev(struct device *dev, const struct device *dev2)
 	dev->of_node_reused = true;
 }
 EXPORT_SYMBOL_GPL(device_set_of_node_from_dev);
+
+int device_match_of_node(struct device *dev, const void *np)
+{
+	return dev->of_node == np;
+}
+EXPORT_SYMBOL_GPL(device_match_of_node);
drivers/fpga/of-fpga-region.c +1 -6
index 75f64ab..e405309 100644
@@ -22,11 +22,6 @@ static const struct of_device_id fpga_region_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, fpga_region_of_match);
 
-static int fpga_region_of_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 /**
  * of_fpga_region_find - find FPGA region
  * @np: device node of FPGA Region
@@ -37,7 +32,7 @@ static int fpga_region_of_node_match(struct device *dev, const void *data)
  */
 static struct fpga_region *of_fpga_region_find(struct device_node *np)
 {
-	return fpga_region_class_find(NULL, np, fpga_region_of_node_match);
+	return fpga_region_class_find(NULL, np, device_match_of_node);
 }
 
 /**
include/linux/device.h +2 -0
index 4d7c881..7093085 100644
@@ -163,6 +163,8 @@ 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_of_node(struct device *dev, const void *np);
+
 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
 		     int (*fn)(struct device *dev, void *data));
 struct device *bus_find_device(struct bus_type *bus, struct device *start,
Signature · 1 line
2.7.4
#12 lore raw

Re: [PATCH v2 06/28] drivers: Add generic helper to match by of_node

drivers/base/core.c void device_set_of_node_from_dev(struct device *dev, const struct device *dev2) · line 3336

Quoted 6 lines
drivers/base/core.c +6 -0
+
+int device_match_of_node(struct device *dev, const void *np)
+{
+	return dev->of_node == np;
+}
+EXPORT_SYMBOL_GPL(device_match_of_node);

Is it an option to 'static inline' this simple function in the header, saving the EXPORT?

author maintainer
#13 lore raw

Re: [PATCH v2 06/28] drivers: Add generic helper to match by of_node

Hi

Quoted 10 lines · Wolfram Sang

drivers/base/core.c void device_set_of_node_from_dev(struct device *dev, const struct device *dev2) · line 3336

Quoted 6 lines
drivers/base/core.c +6 -0
+
+int device_match_of_node(struct device *dev, const void *np)
+{
+	return dev->of_node == np;
+}
+EXPORT_SYMBOL_GPL(device_match_of_node);

Is it an option to 'static inline' this simple function in the header, saving the EXPORT?

No. This is supposed to be passed on as a call back function pointer for the APIs. Having it as a static inline, would simply replicate the same function through the driver subsystems, which is one of the issues that series is trying to solve. Also, by having them exported, we can convert the new specialized device lookup functions, *_find_device_by_<property> to be static inlines.

Suzuki

#14 lore raw

Re: [PATCH v2 06/28] drivers: Add generic helper to match by of_node

Quoted 6 lines
Quoted 4 lines

Is it an option to 'static inline' this simple function in the header, saving the EXPORT?

No.

OK, thanks for the explanation!

author maintainer
#15 lore raw

PATCH v2 7/28 drivers: Add generic helper to match by fwnode

In reply to Suzuki K Poulose

Add a helper to match the firmware node handle of a device. This will be used later for generic look up by fwnode helpers for bus/class/driver.

Cc "David S. Miller" <[email protected]>
Cc Doug Ledford <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Heikki Krogerus <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc Joe Perches <[email protected]>
---
 drivers/base/core.c    | 6 ++++++
 include/linux/device.h | 1 +
 2 files changed, 7 insertions(+)
drivers/base/core.c +6 -0
index 9211908..efcdb96 100644
@@ -3334,3 +3334,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);
include/linux/device.h +1 -0
index 7093085..08aa087 100644
@@ -164,6 +164,7 @@ struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter);
 void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
 
 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));
Signature · 1 line
2.7.4
author maintainer
#16 lore raw

PATCH v2 8/28 drivers: Add generic helper to match by device type

In reply to Suzuki K Poulose

Add a helper to match a device by its type. This will be used later for providing wrappers to the device iterators for bus/class/driver.

Cc Alexander Shishkin <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Harald Freudenberger <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc Oliver Neukum <[email protected]>
Cc Sebastian Andrzej Siewior <[email protected]>
Cc Tomas Winkler <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc Joe Perches <[email protected]>
---
 drivers/base/core.c    | 6 ++++++
 include/linux/device.h | 1 +
 2 files changed, 7 insertions(+)
drivers/base/core.c +6 -0
index efcdb96..b827ca1 100644
@@ -3340,3 +3340,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);
include/linux/device.h +1 -0
index 08aa087..f315692 100644
@@ -165,6 +165,7 @@ void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
 
 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));
Signature · 1 line
2.7.4
author maintainer
#17 lore raw

PATCH v2 9/28 drivers: Add generic match helper by ACPI_COMPANION device

In reply to Suzuki K Poulose

Add a generic helper to match a device by the ACPI_COMPANION device. This will be later used for providing wrappers for (bus/class/driver)_find_device().

Cc Len Brown <[email protected]>
Cc Mark Brown <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/base/core.c    | 6 ++++++
 include/linux/device.h | 1 +
 2 files changed, 7 insertions(+)
drivers/base/core.c +6 -0
index b827ca1..597095b 100644
@@ -3346,3 +3346,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);
include/linux/device.h +1 -0
index f315692..a03b50d 100644
@@ -166,6 +166,7 @@ void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
 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));
Signature · 1 line
2.7.4
#18 lore raw

Re: [PATCH v2 09/28] drivers: Add generic match helper by ACPI_COMPANION device

Quoted 5 lines · Suzuki K Poulose

Add a generic helper to match a device by the ACPI_COMPANION device. This will be later used for providing wrappers for (bus/class/driver)_find_device().

Quoted 7 lines
Cc Len Brown <[email protected]>
Cc Mark Brown <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>

Please fold this change into the patch adding users of device_match_acpi_dev().

Quoted 34 lines
---
 drivers/base/core.c    | 6 ++++++
 include/linux/device.h | 1 +
 2 files changed, 7 insertions(+)
drivers/base/core.c +6 -0
index b827ca1..597095b 100644
@@ -3346,3 +3346,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);
include/linux/device.h +1 -1
index f315692..a03b50d 100644
@@ -166,6 +166,7 @@ void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
 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));
--

2.7.4

author maintainer
#19 lore raw

Re: [PATCH v2 09/28] drivers: Add generic match helper by ACPI_COMPANION device

Hi Rafael,

Quoted 14 lines · Rafael J. Wysocki
Quoted 5 lines · Suzuki K Poulose

Add a generic helper to match a device by the ACPI_COMPANION device. This will be later used for providing wrappers for (bus/class/driver)_find_device().

Quoted 7 lines
Cc Len Brown <[email protected]>
Cc Mark Brown <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Quoted 1 line

Please fold this change into the patch adding users of device_match_acpi_dev().

There are variants of this by class/bus/driver and all of them are introduced as separate patches with the respective users. If we do for this, we have to do the same for other matches as well.

i.e, [ device_match_by_attr + class_find_device_by_attr & users + driver_find_device_by_attr & users + bus_find_device_by_attr & users ]

And that becomes a large chunk, which could make the review painful.

If you would still like that approach, I could do that in the next revision.

Cheers
Suzuki

#20 lore raw

Re: [PATCH v2 09/28] drivers: Add generic match helper by ACPI_COMPANION device

Quoted 24 lines · Suzuki K Poulose

Hi Rafael,

Quoted 14 lines · Rafael J. Wysocki
Quoted 5 lines · Suzuki K Poulose

Add a generic helper to match a device by the ACPI_COMPANION device. This will be later used for providing wrappers for (bus/class/driver)_find_device().

Quoted 7 lines
Cc Len Brown <[email protected]>
Cc Mark Brown <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Quoted 1 line

Please fold this change into the patch adding users of device_match_acpi_dev().

There are variants of this by class/bus/driver and all of them are introduced as separate patches with the respective users. If we do for this, we have to do the same for other matches as well.

Quoted 6 lines

i.e, [ device_match_by_attr + class_find_device_by_attr & users + driver_find_device_by_attr & users + bus_find_device_by_attr & users ]

And that becomes a large chunk, which could make the review painful.

If you would still like that approach, I could do that in the next revision.

Yes, please.

author maintainer
#21 lore raw

PATCH v2 10/28 drivers: Add generic helper to match by name

In reply to Suzuki K Poulose

Add a helper to match the device name. Also reuse this generic exported helper for bus_find_device_by_name(). This will also be used to add similar interface for (driver/class)_find_device()

Cc Alessandro Zummo <[email protected]>
Cc Alexander Aring <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Alexandre Belloni <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Dan Murphy <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Harald Freudenberger <[email protected]>
Cc Heikki Krogerus <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc Jacek Anaszewski <[email protected]>
Cc Lee Jones <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Peter Oberparleiter <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Stefan Schmidt <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/base/bus.c     | 24 ------------------------
 drivers/base/core.c    |  6 ++++++
 include/linux/device.h | 18 +++++++++++++++---
 3 files changed, 21 insertions(+), 27 deletions(-)
drivers/base/bus.c +0 -24
index df3cac7..a1d1e82 100644
@@ -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
drivers/base/core.c +6 -0
index 597095b..5724f93 100644
@@ -3352,3 +3352,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_name(struct device *dev, const void *name)
+{
+	return sysfs_streq(dev_name(dev), name);
+}
+EXPORT_SYMBOL_GPL(device_match_name);
include/linux/device.h +15 -3
index a03b50d..b9b82b7 100644
@@ -167,15 +167,27 @@ 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_name(struct device *dev, const void *name);
 
 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
 		     int (*fn)(struct device *dev, 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,
Signature · 1 line
2.7.4
author maintainer
#22 lore raw

PATCH v2 11/28 drivers: Add generic helper to match any device

In reply to Suzuki K Poulose

Add a generic helper to match any/all devices. This will be used for providing {bus/driver/class}_find_next_device()

Cc Bjorn Helgaas <[email protected]>
Cc Elie Morisse <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
Cc Nehal Shah <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Shyam Sundar S K <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/base/core.c    | 6 ++++++
 include/linux/device.h | 1 +
 2 files changed, 7 insertions(+)
drivers/base/core.c +6 -0
index 5724f93..053ee2e 100644
@@ -3358,3 +3358,9 @@ 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_any(struct device *dev, const void *unused)
+{
+	return 1;
+}
+EXPORT_SYMBOL_GPL(device_match_any);
include/linux/device.h +1 -0
index b9b82b7..a449d09 100644
@@ -168,6 +168,7 @@ 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_name(struct device *dev, const void *name);
+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));
Signature · 1 line
2.7.4
author maintainer
#23 lore raw

PATCH v2 12/28 drivers: Introduce class_find_device_by_name() helper

In reply to Suzuki K Poulose

Add a new wrapper for class_find_device() to search for devices by name and convert the existing users to use the new helper.

Cc Alexander Shishkin <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Alessandro Zummo <[email protected]>
Cc Alexander Aring <[email protected]>
Cc Alexandre Belloni <[email protected]>
Cc Dan Murphy <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Heikki Krogerus <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc Jacek Anaszewski <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Stefan Schmidt <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/hwtracing/stm/core.c     |  9 +--------
 drivers/leds/led-class.c         |  9 +--------
 drivers/rtc/interface.c          | 11 +----------
 drivers/s390/crypto/zcrypt_api.c | 11 +----------
 drivers/usb/roles/class.c        |  8 +-------
 drivers/usb/typec/class.c        |  8 +-------
 include/linux/device.h           | 12 ++++++++++++
 net/ieee802154/core.c            |  7 +------
 8 files changed, 19 insertions(+), 56 deletions(-)
drivers/hwtracing/stm/core.c +1 -8
index e55b902..2b6bd42 100644
@@ -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;
 
drivers/leds/led-class.c +1 -8
index 85848c5..317a619 100644
@@ -216,13 +216,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)
 {
@@ -233,7 +226,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);
 	}
drivers/rtc/interface.c +1 -10
index 4124f4d..1bee39c 100644
@@ -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);
 
drivers/s390/crypto/zcrypt_api.c +1 -10
index 1058b4b..38a5a47 100644
@@ -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;
 }
drivers/usb/roles/class.c +1 -7
index f45d8df..07aaa96 100644
@@ -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);
drivers/usb/typec/class.c +1 -7
index 2eb6238..18a0687 100644
@@ -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);
 }
include/linux/device.h +12 -0
index a449d09..bb14c7f 100644
@@ -485,6 +485,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,
net/ieee802154/core.c +1 -6
index 60b7ac5..de259b5 100644
@@ -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;
 
Signature · 1 line
2.7.4
Acked-by on v2 12/28
#24 lore raw

Re: [PATCH v2 12/28] drivers: Introduce class_find_device_by_name() helper

Quoted 4 lines · Suzuki K Poulose

Add a new wrapper for class_find_device() to search for devices by name and convert the existing users to use the new helper.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
maintainer Acked-by on v2 12/28
#25 lore raw

Re: [PATCH v2 12/28] drivers: Introduce class_find_device_by_name() helper

In reply to Suzuki K Poulose
Quoted 14 lines · Suzuki K Poulose

Add a new wrapper for class_find_device() to search for devices by name and convert the existing users to use the new helper.

Cc Alexander Shishkin <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Alessandro Zummo <[email protected]>
Cc Alexander Aring <[email protected]>
Cc Alexandre Belloni <[email protected]>
Cc Dan Murphy <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Heikki Krogerus <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc Jacek Anaszewski <[email protected]>
Quoted 8 lines
Cc Martin Schwidefsky <[email protected]>
Cc Stefan Schmidt <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Quoted 224 lines
---
 drivers/hwtracing/stm/core.c     |  9 +--------
 drivers/leds/led-class.c         |  9 +--------
 drivers/rtc/interface.c          | 11 +----------
 drivers/s390/crypto/zcrypt_api.c | 11 +----------
 drivers/usb/roles/class.c        |  8 +-------
 drivers/usb/typec/class.c        |  8 +-------
 include/linux/device.h           | 12 ++++++++++++
 net/ieee802154/core.c            |  7 +------
 8 files changed, 19 insertions(+), 56 deletions(-)
drivers/hwtracing/stm/core.c +1 -8
index e55b902..2b6bd42 100644
@@ -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;
 
drivers/leds/led-class.c +1 -8
index 85848c5..317a619 100644
@@ -216,13 +216,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)
 {
@@ -233,7 +226,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);
 	}
drivers/rtc/interface.c +1 -10
index 4124f4d..1bee39c 100644
@@ -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);
 
drivers/s390/crypto/zcrypt_api.c +1 -10
index 1058b4b..38a5a47 100644
@@ -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;
 }
drivers/usb/roles/class.c +1 -7
index f45d8df..07aaa96 100644
@@ -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);
drivers/usb/typec/class.c +1 -7
index 2eb6238..18a0687 100644
@@ -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);
 }
include/linux/device.h +12 -0
index a449d09..bb14c7f 100644
@@ -485,6 +485,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,
net/ieee802154/core.c +1 -6
index 60b7ac5..de259b5 100644
@@ -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;
 
Signature · 1 line
2.7.4
Signature · 3 lines
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
author maintainer
#26 lore raw

PATCH v2 13/28 drivers: Introduce class_find_device_by_of_node() helper

In reply to Suzuki K Poulose

Add a wrapper to class_find_device() to search for a device by the of_node pointer, reusing the generic match function. Also convert the existing users to make use of the new helper.

Cc Alan Tull <[email protected]>
Cc Moritz Fischer <[email protected]>
Cc Peter Rosin <[email protected]>
Cc Mark Brown <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Heiner Kallweit <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Liam Girdwood <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Jiri Slaby <[email protected]>
---
 drivers/fpga/fpga-bridge.c       |  8 +-------
 drivers/fpga/fpga-mgr.c          |  8 +-------
 drivers/mux/core.c               |  7 +------
 drivers/net/phy/mdio_bus.c       |  9 +--------
 drivers/regulator/of_regulator.c |  7 +------
 drivers/spi/spi.c                | 11 ++---------
 include/linux/device.h           | 12 ++++++++++++
 7 files changed, 19 insertions(+), 43 deletions(-)
drivers/fpga/fpga-bridge.c +1 -7
index 80bd8f1..4bab902 100644
@@ -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);
 
drivers/fpga/fpga-mgr.c +1 -7
index c386681..e05104f 100644
@@ -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);
 
drivers/mux/core.c +1 -6
index d1271c1..1fb2238 100644
@@ -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;
 }
drivers/net/phy/mdio_bus.c +1 -8
index bd04fe7..ce94087 100644
@@ -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);
drivers/regulator/of_regulator.c +1 -6
index 0ead116..1b40277 100644
@@ -442,16 +442,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;
 }
drivers/spi/spi.c +2 -9
index 3da1121..a256be5 100644
@@ -3554,21 +3554,14 @@ 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;
 
include/linux/device.h +12 -0
index bb14c7f..9228502 100644
@@ -497,6 +497,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,
Signature · 1 line
2.7.4
#27 lore raw

Re: [PATCH v2 13/28] drivers: Introduce class_find_device_by_of_node() helper

Quoted 4 lines · Suzuki K Poulose

Add a wrapper to class_find_device() to search for a device by the of_node pointer, reusing the generic match function. Also convert the existing users to make use of the new helper.

Quoted 16 lines
Cc Alan Tull <[email protected]>
Cc Moritz Fischer <[email protected]>
Cc Peter Rosin <[email protected]>
Cc Mark Brown <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Heiner Kallweit <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Liam Girdwood <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Jiri Slaby <[email protected]>

Whoooa! I reviewed only the drivers/mux/core.c changes when this was done in a series of much smaller patches. This tag makes it seem as if I have reviewed the whole thing, which I had not done when you added this tag out of the blue.

Now, this stuff is trivial and by now I have looked at the other files and it all seems simple enough. So, you can keep the tag, but it is NOT ok to handle tags like you have done here.

Cheers,
Peter

Quoted 10 lines
---
 drivers/fpga/fpga-bridge.c       |  8 +-------
 drivers/fpga/fpga-mgr.c          |  8 +-------
 drivers/mux/core.c               |  7 +------
 drivers/net/phy/mdio_bus.c       |  9 +--------
 drivers/regulator/of_regulator.c |  7 +------
 drivers/spi/spi.c                | 11 ++---------
 include/linux/device.h           | 12 ++++++++++++
 7 files changed, 19 insertions(+), 43 deletions(-)
author maintainer
#28 lore raw

Re: [PATCH v2 13/28] drivers: Introduce class_find_device_by_of_node() helper

Hi Peter,

Quoted 22 lines · Peter Rosin
Quoted 4 lines · Suzuki K Poulose

Add a wrapper to class_find_device() to search for a device by the of_node pointer, reusing the generic match function. Also convert the existing users to make use of the new helper.

Quoted 16 lines
Cc Alan Tull <[email protected]>
Cc Moritz Fischer <[email protected]>
Cc Peter Rosin <[email protected]>
Cc Mark Brown <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Heiner Kallweit <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Liam Girdwood <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Jiri Slaby <[email protected]>
Quoted 4 lines

Whoooa! I reviewed only the drivers/mux/core.c changes when this was done in a series of much smaller patches. This tag makes it seem as if I have reviewed the whole thing, which I had not done when you added this tag out of the blue.

Apologies for the surprise. The patch was simply squashed with the change that introduced the "helper" to better aid the reviewers, based on suggestions on the list. I kept your tags, only because there were no changes, but some additional context on the core driver.

Quoted 4 lines

Now, this stuff is trivial and by now I have looked at the other files and it all seems simple enough. So, you can keep the tag, but it is NOT ok to handle tags like you have done here.

Sure, I will keep that in mind.

Cheers
Suzuki

#29 lore raw

Re: [PATCH v2 13/28] drivers: Introduce class_find_device_by_of_node() helper

Quoted 30 lines · Suzuki K Poulose

Hi Peter,

Quoted 22 lines · Peter Rosin
Quoted 4 lines · Suzuki K Poulose

Add a wrapper to class_find_device() to search for a device by the of_node pointer, reusing the generic match function. Also convert the existing users to make use of the new helper.

Quoted 16 lines
Cc Alan Tull <[email protected]>
Cc Moritz Fischer <[email protected]>
Cc Peter Rosin <[email protected]>
Cc Mark Brown <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Heiner Kallweit <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Liam Girdwood <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Jiri Slaby <[email protected]>
Quoted 4 lines

Whoooa! I reviewed only the drivers/mux/core.c changes when this was done in a series of much smaller patches. This tag makes it seem as if I have reviewed the whole thing, which I had not done when you added this tag out of the blue.

Quoted 4 lines

Apologies for the surprise. The patch was simply squashed with the change that introduced the "helper" to better aid the reviewers, based on suggestions on the list. I kept your tags, only because there were no changes, but some additional context on the core driver.

You could e.g. have written:

	...
	[For the drivers/mux/core.c part]
	Reviewed-by: Peter Rosin <[email protected]>
	...
Quoted 6 lines
Quoted 4 lines

Now, this stuff is trivial and by now I have looked at the other files and it all seems simple enough. So, you can keep the tag, but it is NOT ok to handle tags like you have done here.

Sure, I will keep that in mind.

Great!

Cheers,
Peter

author maintainer
#30 lore raw

Re: [PATCH v2 13/28] drivers: Introduce class_find_device_by_of_node() helper

Quoted 36 lines · Peter Rosin
Quoted 30 lines · Suzuki K Poulose

Hi Peter,

Quoted 22 lines · Peter Rosin
Quoted 4 lines · Suzuki K Poulose

Add a wrapper to class_find_device() to search for a device by the of_node pointer, reusing the generic match function. Also convert the existing users to make use of the new helper.

Quoted 16 lines
Cc Alan Tull <[email protected]>
Cc Moritz Fischer <[email protected]>
Cc Peter Rosin <[email protected]>
Cc Mark Brown <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Heiner Kallweit <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Liam Girdwood <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Jiri Slaby <[email protected]>
Quoted 4 lines

Whoooa! I reviewed only the drivers/mux/core.c changes when this was done in a series of much smaller patches. This tag makes it seem as if I have reviewed the whole thing, which I had not done when you added this tag out of the blue.

Quoted 4 lines

Apologies for the surprise. The patch was simply squashed with the change that introduced the "helper" to better aid the reviewers, based on suggestions on the list. I kept your tags, only because there were no changes, but some additional context on the core driver.

Quoted 6 lines

You could e.g. have written:

	...
	[For the drivers/mux/core.c part]
	Reviewed-by: Peter Rosin <[email protected]>
	...

Ok. This might change again, another level of merging, but no changes to the hunk for mux. So I can use the above.

Cheers
Suzuki

author maintainer
#31 lore raw

PATCH v2 14/28 drivers: Introduce class_find_device_by_fwnode() helper

In reply to Suzuki K Poulose

Add a wrapper to class_find_device() to search for a device by the fwnode pointer, reusing the generic match function. Also convert the existing users to make use of the new helper.

Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Heikki Krogerus <[email protected]>
---
 drivers/usb/roles/class.c |  8 +-------
 drivers/usb/typec/class.c |  8 +-------
 include/linux/device.h    | 13 +++++++++++++
 3 files changed, 15 insertions(+), 14 deletions(-)
drivers/usb/roles/class.c +1 -7
index 07aaa96..5cd87d8 100644
@@ -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 (!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]);
 	}
drivers/usb/typec/class.c +1 -7
index 18a0687..af4fb73 100644
@@ -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]);
 
include/linux/device.h +13 -0
index 9228502..52ac911 100644
@@ -509,6 +509,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,
Signature · 1 line
2.7.4
maintainer Acked-by on v2 14/28
#32 lore raw

Re: [PATCH v2 14/28] drivers: Introduce class_find_device_by_fwnode() helper

Quoted 9 lines · Suzuki K Poulose

Add a wrapper to class_find_device() to search for a device by the fwnode pointer, reusing the generic match function. Also convert the existing users to make use of the new helper.

Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Heikki Krogerus <[email protected]>
Quoted 84 lines
---
 drivers/usb/roles/class.c |  8 +-------
 drivers/usb/typec/class.c |  8 +-------
 include/linux/device.h    | 13 +++++++++++++
 3 files changed, 15 insertions(+), 14 deletions(-)
drivers/usb/roles/class.c +1 -7
index 07aaa96..5cd87d8 100644
@@ -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 (!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]);
 	}
drivers/usb/typec/class.c +1 -7
index 18a0687..af4fb73 100644
@@ -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]);
 
include/linux/device.h +13 -0
index 9228502..52ac911 100644
@@ -509,6 +509,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,
Signature · 1 line
2.7.4

thanks,

Signature · 1 line
heikki
author maintainer
#33 lore raw

PATCH v2 15/28 drivers: Introduce class_find_device_by_devt() helper

In reply to Suzuki K Poulose

Add a wrapper to class_find_device() to search for a device by the device type, reusing the generic match function. Also convert the existing users.

Cc Heiko Carstens <[email protected]>
Cc Harald Freudenberger <[email protected]>
Cc Tomas Winkler <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/base/core.c              |  9 +--------
 drivers/misc/mei/main.c          |  9 +--------
 drivers/s390/crypto/zcrypt_api.c | 11 +----------
 drivers/tty/tty_io.c             |  8 +-------
 include/linux/device.h           | 12 ++++++++++++
 5 files changed, 16 insertions(+), 33 deletions(-)
drivers/base/core.c +1 -8
index 053ee2e..e9746cf 100644
@@ -2839,13 +2839,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
@@ -2858,7 +2851,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);
drivers/misc/mei/main.c +1 -8
index ad02097..572502a 100644
@@ -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);
drivers/s390/crypto/zcrypt_api.c +1 -10
index 38a5a47..150f623 100644
@@ -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;
 }
drivers/tty/tty_io.c +1 -7
index 033ac7e..202f640 100644
@@ -2950,17 +2950,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);
 }
 
 
include/linux/device.h +12 -0
index 52ac911..2effcc2 100644
@@ -522,6 +522,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,
Signature · 1 line
2.7.4
author maintainer
#34 lore raw

PATCH v2 16/28 drivers: Introduce class_find_device_by_acpi_dev() helper

In reply to Suzuki K Poulose

Add a wrapper to class_find_device() to search for a device by the ACPI COMPANION device, reusing the generic match function.

Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 include/linux/device.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
include/linux/device.h +21 -0
index 2effcc2..b1b8c90 100644
@@ -534,6 +534,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,
Signature · 1 line
2.7.4
author maintainer
#35 lore raw

PATCH v2 17/28 drivers: Introduce bus_find_device_by_of_node() helper

In reply to Suzuki K Poulose

Add a wrapper to bus_find_device() to search for a device by the of_node pointer, reusing the generic match function. Also convert the existing users to make use of the new helper.

Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Frank Rowand <[email protected]>
Cc Heiko Stuebner <[email protected]>
Cc Liam Girdwood <[email protected]>
Cc Mathieu Poirier <[email protected]>
Cc Rob Herring <[email protected]>
Cc Srinivas Kandagatla <[email protected]>
Cc Takashi Iwai <[email protected]>
Cc Wolfram Sang <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/gpu/drm/drm_mipi_dsi.c             |  7 +------
 drivers/hwtracing/coresight/of_coresight.c | 11 ++---------
 drivers/i2c/i2c-core-of.c                  |  7 +------
 drivers/nvmem/core.c                       |  7 +------
 drivers/of/of_mdio.c                       |  8 +-------
 drivers/of/platform.c                      |  7 +------
 drivers/spi/spi.c                          |  9 ++-------
 include/linux/device.h                     | 12 ++++++++++++
 sound/soc/rockchip/rk3399_gru_sound.c      |  9 ++-------
 9 files changed, 23 insertions(+), 54 deletions(-)
drivers/gpu/drm/drm_mipi_dsi.c +1 -6
index ad19df0..bd2498b 100644
@@ -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;
 }
drivers/hwtracing/coresight/of_coresight.c +2 -9
index 3fc200e..f417f76 100644
@@ -18,11 +18,6 @@
 #include <asm/smp_plat.h>
 
 
-static int of_dev_node_match(struct device *dev, const void *data)
-{
-	return dev->of_node == data;
-}
-
 static struct device *
 of_coresight_get_endpoint_device(struct device_node *endpoint)
 {
@@ -32,8 +27,7 @@ of_coresight_get_endpoint_device(struct device_node *endpoint)
 	 * If we have a non-configurable replicator, it will be found on the
 	 * platform bus.
 	 */
-	dev = bus_find_device(&platform_bus_type, NULL,
-			      endpoint, of_dev_node_match);
+	dev = bus_find_device_by_of_node(&platform_bus_type, endpoint);
 	if (dev)
 		return dev;
 
@@ -41,8 +35,7 @@ of_coresight_get_endpoint_device(struct device_node *endpoint)
 	 * 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,
-			       endpoint, of_dev_node_match);
+	return bus_find_device_by_of_node(&amba_bustype, endpoint);
 }
 
 static inline bool of_coresight_legacy_ep_is_input(struct device_node *ep)
drivers/i2c/i2c-core-of.c +1 -6
index 2eb59a2..74a4126 100644
@@ -112,11 +112,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)
@@ -134,7 +129,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;
 
drivers/nvmem/core.c +1 -6
index ac5d945..057d1ff 100644
@@ -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;
drivers/of/of_mdio.c +1 -7
index 44f5349..000b957 100644
@@ -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)
drivers/of/platform.c +1 -6
index 008d79e..de11905 100644
@@ -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);
drivers/spi/spi.c +2 -7
index a256be5..cc4d83e 100644
@@ -3538,16 +3538,11 @@ 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);
include/linux/device.h +12 -0
index b1b8c90..35f51d6 100644
@@ -189,6 +189,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,
sound/soc/rockchip/rk3399_gru_sound.c +2 -7
index c04c9ed..2fb7f8e 100644
@@ -405,11 +405,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;
@@ -421,8 +416,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);
Signature · 1 line
2.7.4
Acked-by on v2 17/28
#36 lore raw

Re: [PATCH v2 17/28] drivers: Introduce bus_find_device_by_of_node() helper

Quoted 17 lines · Suzuki K Poulose

Add a wrapper to bus_find_device() to search for a device by the of_node pointer, reusing the generic match function. Also convert the existing users to make use of the new helper.

Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Frank Rowand <[email protected]>
Cc Heiko Stuebner <[email protected]>
Cc Liam Girdwood <[email protected]>
Quoted 8 lines
Cc Mathieu Poirier <[email protected]>
Cc Rob Herring <[email protected]>
Cc Srinivas Kandagatla <[email protected]>
Cc Takashi Iwai <[email protected]>
Cc Wolfram Sang <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer Reviewed-by on v2 17/28
#37 lore raw

Re: [PATCH v2 17/28] drivers: Introduce bus_find_device_by_of_node() helper

In reply to Suzuki K Poulose
Quoted 25 lines · Suzuki K Poulose

Add a wrapper to bus_find_device() to search for a device by the of_node pointer, reusing the generic match function. Also convert the existing users to make use of the new helper.

Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Frank Rowand <[email protected]>
Cc Heiko Stuebner <[email protected]>
Cc Liam Girdwood <[email protected]>
Cc Mathieu Poirier <[email protected]>
Cc Rob Herring <[email protected]>
Cc Srinivas Kandagatla <[email protected]>
Cc Takashi Iwai <[email protected]>
Cc Wolfram Sang <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Quoted 12 lines
---
 drivers/gpu/drm/drm_mipi_dsi.c             |  7 +------
 drivers/hwtracing/coresight/of_coresight.c | 11 ++---------
 drivers/i2c/i2c-core-of.c                  |  7 +------
 drivers/nvmem/core.c                       |  7 +------
 drivers/of/of_mdio.c                       |  8 +-------
 drivers/of/platform.c                      |  7 +------
 drivers/spi/spi.c                          |  9 ++-------
 include/linux/device.h                     | 12 ++++++++++++
 sound/soc/rockchip/rk3399_gru_sound.c      |  9 ++-------
 9 files changed, 23 insertions(+), 54 deletions(-)
author maintainer
#38 lore raw

PATCH v2 18/28 drivers: Introduce bus_find_device_by_fwnode() helper

In reply to Suzuki K Poulose

Add a wrapper to bus_find_device() to search for a device by the fwnode pointer, reusing the generic match function. Also convert the existing users to make use of the new helper.

Cc "David S. Miller" <[email protected]>
Cc Doug Ledford <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/base/devcon.c                              |  8 +-------
 drivers/infiniband/hw/hns/hns_roce_hw_v1.c         |  8 +-------
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c |  8 +-------
 include/linux/device.h                             | 12 ++++++++++++
 4 files changed, 15 insertions(+), 21 deletions(-)
drivers/base/devcon.c +1 -7
index ac026d5..5a888eaa 100644
@@ -107,19 +107,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;
 
drivers/infiniband/hw/hns/hns_roce_hw_v1.c +1 -7
index 3afd3e9..6779b7d 100644
@@ -4498,19 +4498,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;
 }
drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c +1 -7
index bb6586d..ed3829a 100644
@@ -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;
 }
include/linux/device.h +12 -0
index 35f51d6..576d84f 100644
@@ -201,6 +201,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,
Signature · 1 line
2.7.4
author maintainer
#39 lore raw

PATCH v2 19/28 drivers: Introduce bus_find_device_by_devt() helper

In reply to Suzuki K Poulose

Add a wrapper to bus_find_device() to search for a device by the device type, reusing the generic match function. Also convert the existing users to make use of the new helper.

Cc Oliver Neukum <[email protected]>
Cc Sebastian Andrzej Siewior <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/hwtracing/intel_th/core.c | 10 +---------
 drivers/usb/core/devio.c          |  8 +-------
 include/linux/device.h            | 12 ++++++++++++
 3 files changed, 14 insertions(+), 16 deletions(-)
drivers/hwtracing/intel_th/core.c +1 -9
index 5592289..d5c1821 100644
@@ -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;
 
drivers/usb/core/devio.c +1 -7
index 7bd7de7..4e83623 100644
@@ -947,17 +947,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);
include/linux/device.h +12 -0
index 576d84f..3c244ac 100644
@@ -213,6 +213,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,
Signature · 1 line
2.7.4
author maintainer
#40 lore raw

PATCH v2 20/28 drivers: Introduce bus_find_next_device() helper

In reply to Suzuki K Poulose

Add a wrapper for bus_find_device() to find the next devices on the given bus from the "start" device. Also convert the existing users to make use of the new helper.

Cc Bjorn Helgaas <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/pci/probe.c      |  7 +------
 drivers/scsi/scsi_proc.c |  9 ++-------
 include/linux/device.h   | 10 ++++++++++
 3 files changed, 13 insertions(+), 13 deletions(-)
drivers/pci/probe.c +1 -6
index f9ef7ad..3504695 100644
@@ -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;
drivers/scsi/scsi_proc.c +2 -7
index c074631..5b31322 100644
@@ -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;
 }
include/linux/device.h +10 -0
index 3c244ac..1c137ab 100644
@@ -225,6 +225,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);
+}
+
 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,
Signature · 1 line
2.7.4
author maintainer
#41 lore raw

PATCH v2 21/28 drivers: Introduce bus_find_device_by_acpi_dev() helper

In reply to Suzuki K Poulose

Add a wrapper to bus_find_device() to search for a device by the ACPI COMPANION device, reusing the generic match function. Also convert the existing users to make use of the new helper.

Cc Mika Westerberg <[email protected]>
Cc Wolfram Sang <[email protected]>
Cc Mark Brown <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/i2c/i2c-core-acpi.c |  8 +-------
 drivers/spi/spi.c           |  8 +-------
 include/linux/device.h      | 22 ++++++++++++++++++++++
 3 files changed, 24 insertions(+), 14 deletions(-)
drivers/i2c/i2c-core-acpi.c +1 -7
index 8af35f11..7c6435c 100644
@@ -328,11 +328,6 @@ 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;
-}
-
 static struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle)
 {
 	struct device *dev;
@@ -346,8 +341,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;
 }
 
drivers/spi/spi.c +1 -7
index cc4d83e..8737d69 100644
@@ -3627,11 +3627,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;
@@ -3651,8 +3646,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;
 }
 
include/linux/device.h +22 -0
index 1c137ab..6768e2b 100644
@@ -235,6 +235,28 @@ 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;
+
+/**
+ * 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,
Signature · 1 line
2.7.4
maintainer Acked-by on v2 21/28
#42 lore raw

Re: [PATCH v2 21/28] drivers: Introduce bus_find_device_by_acpi_dev() helper

Quoted 3 lines · Suzuki K Poulose

Add a wrapper to bus_find_device() to search for a device by the ACPI COMPANION device, reusing the generic match function. Also convert the existing users to make use of the new helper.

This might have merge issues, I just applied some changes to the ACPI parsing code the other day.

Acked-by on v2 21/28
#44 lore raw

Re: [PATCH v2 21/28] drivers: Introduce bus_find_device_by_acpi_dev() helper

In reply to Suzuki K Poulose
Quoted 11 lines · Suzuki K Poulose

Add a wrapper to bus_find_device() to search for a device by the ACPI COMPANION device, reusing the generic match function. Also convert the existing users to make use of the new helper.

Cc Mika Westerberg <[email protected]>
Cc Wolfram Sang <[email protected]>
Cc Mark Brown <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
author maintainer
#45 lore raw

PATCH v2 22/28 drivers: Introduce driver_find_device_by_name() helper

In reply to Suzuki K Poulose

Add a wrapper to driver_find_device() to search for a device by name, similar to the other iterators, reusing the generic match function. Also convert the existing users to make use of the new helper.

Cc Lee Jones <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc Peter Oberparleiter <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/s390/cio/ccwgroup.c | 10 +---------
 drivers/s390/cio/device.c   | 17 +----------------
 include/linux/device.h      | 12 ++++++++++++
 3 files changed, 14 insertions(+), 25 deletions(-)
drivers/s390/cio/ccwgroup.c +1 -9
index ea176157..d843e36 100644
@@ -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)
-{
-	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;
 }
drivers/s390/cio/device.c +1 -16
index f27536b..df29d7e 100644
@@ -1649,20 +1649,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)
-{
-	char *bus_id;
-
-	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
@@ -1679,8 +1665,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;
 }
include/linux/device.h +12 -0
index 6768e2b..0d3958e 100644
@@ -425,6 +425,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);
 
Signature · 1 line
2.7.4
author maintainer
#46 lore raw

PATCH v2 23/28 drivers: Introduce driver_find_device_by_of_node() helper

In reply to Suzuki K Poulose

Add a wrapper to driver_find_device() to search for a device by the of_node pointer, reusing the generic match function. Also convert the existing users to make use of the new helper.

Cc Lee Jones <[email protected]>
Cc Thor Thayer <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/amba/tegra-ahb.c    | 11 +----------
 drivers/mfd/altera-sysmgr.c | 14 ++------------
 include/linux/device.h      | 13 +++++++++++++
 3 files changed, 16 insertions(+), 22 deletions(-)
drivers/amba/tegra-ahb.c +1 -10
index aa64eec..57d3b2e 100644
@@ -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);
drivers/mfd/altera-sysmgr.c +2 -12
index 2ee14d8..d2a13a5 100644
@@ -88,16 +88,6 @@ static struct regmap_config altr_sysmgr_regmap_cfg = {
 };
 
 /**
- * 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.
  * Return: regmap if found or error if not found.
@@ -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);
include/linux/device.h +13 -0
index 0d3958e..f929671 100644
@@ -437,6 +437,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);
 
Signature · 1 line
2.7.4
#47 lore raw

Re: [PATCH v2 23/28] drivers: Introduce driver_find_device_by_of_node() helper

Quoted 10 lines · Suzuki K Poulose

Add a wrapper to driver_find_device() to search for a device by the of_node pointer, reusing the generic match function. Also convert the existing users to make use of the new helper.

Cc Lee Jones <[email protected]>
Cc Thor Thayer <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Quoted 5 lines
---
 drivers/amba/tegra-ahb.c    | 11 +----------
 drivers/mfd/altera-sysmgr.c | 14 ++------------
 include/linux/device.h      | 13 +++++++++++++
 3 files changed, 16 insertions(+), 22 deletions(-)

Looks good to me. For the MFD part.

For my own reference:

What is the merge plan?

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
author maintainer
#48 lore raw

Re: [PATCH v2 23/28] drivers: Introduce driver_find_device_by_of_node() helper

Hi Lee

Quoted 18 lines · Lee Jones
Quoted 10 lines · Suzuki K Poulose

Add a wrapper to driver_find_device() to search for a device by the of_node pointer, reusing the generic match function. Also convert the existing users to make use of the new helper.

Cc Lee Jones <[email protected]>
Cc Thor Thayer <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Quoted 5 lines
---
  drivers/amba/tegra-ahb.c    | 11 +----------
  drivers/mfd/altera-sysmgr.c | 14 ++------------
  include/linux/device.h      | 13 +++++++++++++
  3 files changed, 16 insertions(+), 22 deletions(-)
Quoted 4 lines

Looks good to me. For the MFD part.

For my own reference:

Thanks ! Btw, v3 has been posted based on 5.3-rc1. You are in Cc for that.

Quoted 3 lines

What is the merge plan?

With v3, it looks more sensible to merge the patch via Greg's tree.

Suzuki

author maintainer
#49 lore raw

PATCH v2 24/28 drivers: Introduce driver_find_device_by_fwnode() helper

In reply to Suzuki K Poulose

Add a wrapper to driver_find_device() to search for a device by the fwnode pointer, reusing the generic match function. Also convert the existing users to make use of the new helper.

Cc Will Deacon <[email protected]>
Cc Robin Murphy <[email protected]>
Cc Joerg Roedel <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/iommu/arm-smmu-v3.c |  9 ++-------
 drivers/iommu/arm-smmu.c    |  9 ++-------
 include/linux/device.h      | 13 +++++++++++++
 3 files changed, 17 insertions(+), 14 deletions(-)
drivers/iommu/arm-smmu-v3.c +2 -7
index d787856..6b956a03 100644
@@ -2023,16 +2023,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;
 }
drivers/iommu/arm-smmu.c +2 -7
index 3af579a..0d63a9e 100644
@@ -1419,16 +1419,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;
 }
include/linux/device.h +13 -0
index f929671..2cf49f7 100644
@@ -450,6 +450,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);
 
Signature · 1 line
2.7.4
author maintainer
#50 lore raw

PATCH v2 25/28 drivers: Introduce driver_find_device_by_devt() helper

In reply to Suzuki K Poulose

Add a wrapper to driver_find_device() to search for a device by the device type, reusing the generic match function.

Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 include/linux/device.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/linux/device.h +12 -0
index 2cf49f7..f7f6a43 100644
@@ -463,6 +463,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);
 
Signature · 1 line
2.7.4
author maintainer
#51 lore raw

PATCH v2 26/28 drivers: Introduce driver_find_next_device() helper

In reply to Suzuki K Poulose

Add a wrapper for driver_find_device() to find the next device for a given driver from the "start" device. Also convert the existing users to make use of the new helper.

Cc Elie Morisse <[email protected]>
Cc Nehal Shah <[email protected]>
Cc Shyam Sundar S K <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/i2c/busses/i2c-amd-mp2-pci.c | 8 +-------
 drivers/s390/cio/ccwgroup.c          | 8 +-------
 include/linux/device.h               | 6 ++++++
 3 files changed, 8 insertions(+), 14 deletions(-)
drivers/i2c/busses/i2c-amd-mp2-pci.c +1 -7
index c7fe3b4..5e4800d 100644
@@ -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;
 
drivers/s390/cio/ccwgroup.c +1 -7
index d843e36..0005ec9 100644
@@ -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);
include/linux/device.h +6 -0
index f7f6a43..77f817d 100644
@@ -475,6 +475,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);
+}
+
 void driver_deferred_probe_add(struct device *dev);
 int driver_deferred_probe_check_state(struct device *dev);
 
Signature · 1 line
2.7.4
author maintainer
#52 lore raw

PATCH v2 27/28 drivers: Introduce driver_find_device_by_acpi_dev() helper

In reply to Suzuki K Poulose

Add a wrapper to driver_find_device() to search for a device by the ACPI COMPANION device, reusing the generic match function.

Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 include/linux/device.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
include/linux/device.h +21 -0
index 77f817d..a2a8ac2 100644
@@ -481,6 +481,27 @@ static inline struct device *driver_find_next_device(struct device_driver *drv,
 	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
+ * 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);
 
Signature · 1 line
2.7.4
author maintainer
#53 lore raw

PATCH v2 28/28 platform: Add platform_find_device_by_driver() helper

In reply to Suzuki K Poulose

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

Cc Eric Anholt <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc "Heiko Stübner" <[email protected]>
Cc Inki Dae <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Sandy Huang <[email protected]>
Cc Seung-Woo Kim <[email protected]>
---
 drivers/base/platform.c                     | 14 ++++++++++++++
 drivers/gpu/drm/exynos/exynos_drm_drv.c     |  9 +++------
 drivers/gpu/drm/rockchip/rockchip_drm_drv.c |  3 +--
 drivers/gpu/drm/vc4/vc4_drv.c               |  3 +--
 include/linux/platform_device.h             |  3 +++
 5 files changed, 22 insertions(+), 10 deletions(-)
drivers/base/platform.c +14 -0
index 4d17298..158ac24 100644
@@ -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;
drivers/gpu/drm/exynos/exynos_drm_drv.c +3 -6
index ba8932a..b357e0d 100644
@@ -244,9 +244,7 @@ static struct component_match *exynos_drm_match_add(struct device *dev)
 		if (!info->driver || !(info->flags & DRM_COMPONENT_DRIVER))
 			continue;
 
-		while ((d = bus_find_device(&platform_bus_type, p,
-					    &info->driver->driver,
-					    (void *)platform_bus_type.match))) {
+		while ((d = platform_find_device_by_driver(p, &info->driver->driver))) {
 			put_device(p);
 
 			if (!(info->flags & DRM_FIMC_DEVICE) ||
@@ -414,9 +412,8 @@ static void exynos_drm_unregister_devices(void)
 		if (!info->driver || !(info->flags & DRM_VIRTUAL_DEVICE))
 			continue;
 
-		while ((dev = bus_find_device(&platform_bus_type, NULL,
-					    &info->driver->driver,
-					    (void *)platform_bus_type.match))) {
+		while ((dev = platform_find_device_by_driver(NULL,
+						&info->driver->driver))) {
 			put_device(dev);
 			platform_device_unregister(to_platform_device(dev));
 		}
drivers/gpu/drm/rockchip/rockchip_drm_drv.c +1 -2
index 53d2c5b..38dc263 100644
@@ -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;
 
drivers/gpu/drm/vc4/vc4_drv.c +1 -2
index 6d9be20..d159eb5 100644
@@ -236,8 +236,7 @@ static void vc4_match_add_drivers(struct device *dev,
 		struct device_driver *drv = &drivers[i]->driver;
 		struct device *p = NULL, *d;
 
-		while ((d = bus_find_device(&platform_bus_type, p, drv,
-					    (void *)platform_bus_type.match))) {
+		while ((d = platform_find_device_by_driver(p, drv))) {
 			put_device(p);
 			component_match_add(dev, match, compare_dev, d);
 			p = d;
include/linux/platform_device.h +3 -0
index beb25f2..c9c9d9e 100644
@@ -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);
Signature · 1 line
2.7.4
#54 lore raw
In reply to Suzuki K Poulose

(dropping the very long cc list just cc'ing LKML and devicetree)

Quoted 8 lines · Suzuki K Poulose

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.

Quoted 7 lines

Additionally the prototype for the "match" functions accepted by the above APIs have a minute difference which prevents us otherwise sharing the match functions. i.e,
int (*match)(struct device *dev, void *data) for {bus/driver}_find_device()
vs
int (*match)(struct device *dev, const void *) for class_find_device()

As you are doing treewide conversions, perhaps using

	bool (*match)(...)

is a more sensible api.

Quoted 8 lines

Changes since v1:
- Drop start parameter for *_find_device_by_devt().
- Fix build warnings for s390
- Add *_find_device_by_acpi_dev() wrappers.
- Group wrappers and the consumers into single patch, reducing the total patches to 28 from 57. (Rafael).
- Better description for acpi cleanup patch.
- Added tags from v1.

Below this is a _very_ long list of cc:'s.

If the list is generated using scripts/get_maintainer.pl perhaps it is more sensible to add --nogit --nogit-fallback to its arguments to cc actual maintainers and avoid people that have submitted cleanup style patches to various files.

Quoted 88 lines
Cc Alan Tull <[email protected]>
Cc Alessandro Zummo <[email protected]>
Cc Alexander Aring <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Alexandre Belloni <[email protected]>
Cc Andreas Noever <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Corey Minyard <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Dan Murphy <[email protected]>
Cc David Airlie <[email protected]>
Cc David Kershner <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Doug Ledford <[email protected]>
Cc Elie Morisse <[email protected]>
Cc Eric Anholt <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Frank Rowand <[email protected]>
Cc Grant Likely <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Grygorii Strashko <[email protected]>
Cc Harald Freudenberger <[email protected]>
Cc Hartmut Knaack <[email protected]>
Cc Heikki Krogerus <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc "Heiko Stübner" <[email protected]>
Cc Heiko Stuebner <[email protected]>
Cc Heiner Kallweit <[email protected]>
Cc Inki Dae <[email protected]>
Cc Jacek Anaszewski <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Jiri Slaby <[email protected]>
Cc Joe Perches <[email protected]>
Cc Joerg Roedel <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Jonathan Hunter <[email protected]>
Cc Lee Jones <[email protected]>
Cc Len Brown <[email protected]
Cc Liam Girdwood <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Mark Brown <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
Cc Mathieu Poirier <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Michael Jamet <[email protected]>
Cc Mika Westerberg <[email protected]>
Cc Moritz Fischer <[email protected]>
Cc Nehal Shah <[email protected]>
Cc Oliver Neukum <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Peter Oberparleiter <[email protected]>
Cc Peter Rosin <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Rafael J. Wysocki" <[email protected]>
Cc Rob Herring <[email protected]>
Cc Robin Murphy <[email protected]>
Cc Russell King <[email protected]>
Cc Sandy Huang <[email protected]>
Cc Sebastian Andrzej Siewior <[email protected]>
Cc Sebastian Ott <[email protected]>
Cc Seung-Woo Kim <[email protected]>
Cc Shyam Sundar S K <[email protected]>
Cc Srinivas Kandagatla <[email protected]>
Cc Stefan Schmidt <[email protected]>
Cc Takashi Iwai <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Thor Thayer <[email protected]>
Cc Tomas Winkler <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc Will Deacon <[email protected]>
Cc Wolfram Sang <[email protected]>
author maintainer
#55 lore raw
Cc Greg, Rafael

Hi Joe,

Quoted 19 lines · Joe Perches

(dropping the very long cc list just cc'ing LKML and devicetree)

Quoted 8 lines · Suzuki K Poulose

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.

Quoted 7 lines

Additionally the prototype for the "match" functions accepted by the above APIs have a minute difference which prevents us otherwise sharing the match functions. i.e,
int (*match)(struct device *dev, void *data) for {bus/driver}_find_device()
vs
int (*match)(struct device *dev, const void *) for class_find_device()

Quoted 5 lines

As you are doing treewide conversions, perhaps using

	bool (*match)(...)

is a more sensible api.

I agree that it is more suitable api. However, that would need much more conversions for the existing "class_find_device()" , which are not touched by the series and would make this series even more bigger. With that said, I am fine with implementing the suggestion if Greg/Rafael thinks that is fine.

Quoted 10 lines
Quoted 8 lines

Changes since v1:
- Drop start parameter for *_find_device_by_devt().
- Fix build warnings for s390
- Add *_find_device_by_acpi_dev() wrappers.
- Group wrappers and the consumers into single patch, reducing the total patches to 28 from 57. (Rafael).
- Better description for acpi cleanup patch.
- Added tags from v1.

Below this is a _very_ long list of cc:'s.

Unfortunately, yes.

Quoted 2 lines

If the list is generated using scripts/get_maintainer.pl perhaps it is more sensible to add --nogit --nogit-fallback

Yes, and trimmed manually a bit to remove the "commit-signers". I have tried to keep only the maintainers/reviewers/supporters. Thanks for the option, I will give that a try.

Quoted 3 lines

to its arguments to cc actual maintainers and avoid people that have submitted cleanup style patches to various files.

Cheers
Suzuki

maintainer
#56 lore raw
In reply to Suzuki K Poulose
Quoted 15 lines · Suzuki K Poulose

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.

Additionally the prototype for the "match" functions accepted by the above APIs have a minute difference which prevents us otherwise sharing the match functions. i.e,
int (*match)(struct device *dev, void *data) for {bus/driver}_find_device()
vs
int (*match)(struct device *dev, const void *) for class_find_device()

Quoted 5 lines

If we promote the former to accept a "const void*" parameter, we could share one single match function for all the helpers. This series achieves the following:

a) [Patches 03-05] Unify the prototype for "match" functions accepted by the device lookup APIs.

I've applied the first 6 patches of this series to my tree now. Let's see how that goes, and this should give you a more solid base to redo the rest of the series off of.

thanks,

greg k-h
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

author maintainer
#57 lore raw

Greg,

Quoted 19 lines · Greg KH
Quoted 18 lines · Suzuki K Poulose

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.

Additionally the prototype for the "match" functions accepted by the above APIs have a minute difference which prevents us otherwise sharing the match functions. i.e,
int (*match)(struct device *dev, void *data) for {bus/driver}_find_device()
vs
int (*match)(struct device *dev, const void *) for class_find_device()

If we promote the former to accept a "const void*" parameter, we could share one single match function for all the helpers. This series achieves the following:

Quoted 6 lines
Quoted 2 lines

a) [Patches 03-05] Unify the prototype for "match" functions accepted by the device lookup APIs.

I've applied the first 6 patches of this series to my tree now. Let's see how that goes, and this should give you a more solid base to redo the rest of the series off of.

Thanks for that. I will rebase my next version on top your tree sometime soon.

Cheers
Suzuki