* [PATCH v2 00/28] drivers: Consolidate device lookup helpers @ 2019-06-14 17:53 Suzuki K Poulose 2019-06-14 17:54 ` [PATCH v2 10/28] drivers: Add generic helper to match by name Suzuki K Poulose ` (2 more replies) 0 siblings, 3 replies; 6+ messages in thread From: Suzuki K Poulose @ 2019-06-14 17:53 UTC (permalink / raw) To: linux-kernel Cc: Andrew Lunn, Shyam Sundar S K, rafael, Will Deacon, Ulf Hansson, dri-devel, Pavel Machek, Stefan Schmidt, Wolfram Sang, linux-acpi, Doug Ledford, Jiri Slaby, Tomas Winkler, Dan Murphy, gregkh, linux-usb, Seung-Woo Kim, linux-spi, Joe Perches, linux-wpan, Alexandre Belloni, David Airlie, Rafael J . Wysocki , Thierry Reding, Srinivas Kandagatla 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/?i=1559577023-558-1-git-send-email-suzuki.poulose@arm.com V1 [2] https://marc.info/?i=1559747630-28065-1-git-send-email-suzuki.poulose@arm.com 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 <atull@kernel.org> Cc: Alessandro Zummo <a.zummo@towertech.it> Cc: Alexander Aring <alex.aring@gmail.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com> Cc: Andreas Noever <andreas.noever@gmail.com> Cc: Andrew Lunn <andrew@lunn.ch> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Bjorn Helgaas <bhelgaas@google.com> Cc: Corey Minyard <minyard@acm.org> Cc: Daniel Vetter <daniel@ffwll.ch> Cc: Dan Murphy <dmurphy@ti.com> Cc: David Airlie <airlied@linux.ie> Cc: David Kershner <david.kershner@unisys.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: Doug Ledford <dledford@redhat.com> Cc: dri-devel@lists.freedesktop.org Cc: Elie Morisse <syniurge@gmail.com> Cc: Eric Anholt <eric@anholt.net> Cc: Felipe Balbi <balbi@kernel.org> Cc: Florian Fainelli <f.fainelli@gmail.com> Cc: Frank Rowand <frowand.list@gmail.com> Cc: Grant Likely <grant.likely@arm.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Grygorii Strashko <grygorii.strashko@ti.com> Cc: Harald Freudenberger <freude@linux.ibm.com> Cc: Hartmut Knaack <knaack.h@gmx.de> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: "Heiko Stübner" <heiko@sntech.de> Cc: Heiko Stuebner <heiko@sntech.de> Cc: Heiner Kallweit <hkallweit1@gmail.com> Cc: Inki Dae <inki.dae@samsung.com> Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com> Cc: "James E.J. Bottomley" <jejb@linux.ibm.com> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: Jiri Slaby <jslaby@suse.com> Cc: Joe Perches <joe@perches.com> Cc: Joerg Roedel <joro@8bytes.org> Cc: Jonathan Cameron <jic23@kernel.org> Cc: Jonathan Hunter <jonathanh@nvidia.com> Cc: Lee Jones <lee.jones@linaro.org> Cc: Len Brown <lenb@kernel.org Cc: Liam Girdwood <lgirdwood@gmail.com> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> Cc: Mark Brown <broonie@kernel.org> Cc: "Martin K. Petersen" <martin.petersen@oracle.com> Cc: Mathieu Poirier <mathieu.poirier@linaro.org> Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com> Cc: Maxime Ripard <maxime.ripard@bootlin.com> Cc: Michael Jamet <michael.jamet@intel.com> Cc: Mika Westerberg <mika.westerberg@linux.intel.com> Cc: Moritz Fischer <mdf@kernel.org> Cc: Nehal Shah <nehal-bakulchandra.shah@amd.com> Cc: Oliver Neukum <oneukum@suse.com> Cc: Pavel Machek <pavel@ucw.cz> Cc: Peter Oberparleiter <oberpar@linux.ibm.com> Cc: Peter Rosin <peda@axentia.se> Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com> Cc: "Rafael J. Wysocki" <rafael@kernel.org> Cc: Rafael J. Wysocki" <rjw@rjwysocki.net> Cc: Rob Herring <robh+dt@kernel.org> Cc: Robin Murphy <robin.murphy@arm.com> Cc: Russell King <linux@armlinux.org.uk> Cc: Sandy Huang <hjc@rock-chips.com> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Cc: Sebastian Ott <sebott@linux.ibm.com> Cc: Seung-Woo Kim <sw0312.kim@samsung.com> Cc: Shyam Sundar S K <shyam-sundar.s-k@amd.com> Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Cc: Stefan Schmidt <stefan@datenfreihafen.org> Cc: Takashi Iwai <tiwai@suse.com> Cc: Thierry Reding <thierry.reding@gmail.com> Cc: Thor Thayer <thor.thayer@linux.intel.com> Cc: Tomas Winkler <tomas.winkler@intel.com> Cc: Ulf Hansson <ulf.hansson@linaro.org> Cc: Will Deacon <will.deacon@arm.com> Cc: Wolfram Sang <wsa@the-dreams.de> Cc: devicetree@vger.kernel.org Cc: linux-acpi@vger.kernel.org Cc: linux-fpga@vger.kernel.org Cc: linux-i2c@vger.kernel.org Cc: linux-leds@vger.kernel.org Cc: linux-rockchip@lists.infradead.org Cc: linux-rtc@vger.kernel.org Cc: linux-spi@vger.kernel.org Cc: linux-usb@vger.kernel.org Cc: linux-wpan@vger.kernel.org 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(-) -- 2.7.4 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 10/28] drivers: Add generic helper to match by name 2019-06-14 17:53 [PATCH v2 00/28] drivers: Consolidate device lookup helpers Suzuki K Poulose @ 2019-06-14 17:54 ` Suzuki K Poulose 2019-06-14 17:54 ` [PATCH v2 12/28] drivers: Introduce class_find_device_by_name() helper Suzuki K Poulose 2019-06-24 3:23 ` [PATCH v2 00/28] drivers: Consolidate device lookup helpers Greg KH 2 siblings, 0 replies; 6+ messages in thread From: Suzuki K Poulose @ 2019-06-14 17:54 UTC (permalink / raw) To: linux-kernel Cc: gregkh, rafael, suzuki.poulose, Alessandro Zummo, Alexander Aring, Alexander Shishkin, Alexandre Belloni, Arnd Bergmann, Dan Murphy, Harald Freudenberger, Heikki Krogerus, Heiko Carstens, Jacek Anaszewski, Lee Jones, linux-leds, linux-rtc, linux-usb, linux-wpan, Martin Schwidefsky, Maxime Coquelin, Pavel Machek 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 <a.zummo@towertech.it> Cc: Alexander Aring <alex.aring@gmail.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Dan Murphy <dmurphy@ti.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Harald Freudenberger <freude@linux.ibm.com> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com> Cc: Lee Jones <lee.jones@linaro.org> Cc: linux-leds@vger.kernel.org Cc: linux-rtc@vger.kernel.org Cc: linux-usb@vger.kernel.org Cc: linux-wpan@vger.kernel.org Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com> Cc: Pavel Machek <pavel@ucw.cz> Cc: Peter Oberparleiter <oberpar@linux.ibm.com> Cc: "Rafael J. Wysocki" <rafael@kernel.org> Cc: Stefan Schmidt <stefan@datenfreihafen.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com> --- drivers/base/bus.c | 24 ------------------------ drivers/base/core.c | 6 ++++++ include/linux/device.h | 18 +++++++++++++++--- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index df3cac7..a1d1e82 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -342,30 +342,6 @@ struct device *bus_find_device(struct bus_type *bus, } EXPORT_SYMBOL_GPL(bus_find_device); -static int match_name(struct device *dev, const void *data) -{ - const char *name = data; - - return sysfs_streq(name, dev_name(dev)); -} - -/** - * bus_find_device_by_name - device iterator for locating a particular device of a specific name - * @bus: bus type - * @start: Device to begin with - * @name: name of the device to match - * - * This is similar to the bus_find_device() function above, but it handles - * searching by a name automatically, no need to write another strcmp matching - * function. - */ -struct device *bus_find_device_by_name(struct bus_type *bus, - struct device *start, const char *name) -{ - return bus_find_device(bus, start, (void *)name, match_name); -} -EXPORT_SYMBOL_GPL(bus_find_device_by_name); - /** * subsys_find_device_by_id - find a device with a specific enumeration number * @subsys: subsystem diff --git a/drivers/base/core.c b/drivers/base/core.c index 597095b..5724f93 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -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); diff --git a/include/linux/device.h b/include/linux/device.h index a03b50d..b9b82b7 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -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, -- 2.7.4 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 12/28] drivers: Introduce class_find_device_by_name() helper 2019-06-14 17:53 [PATCH v2 00/28] drivers: Consolidate device lookup helpers Suzuki K Poulose 2019-06-14 17:54 ` [PATCH v2 10/28] drivers: Add generic helper to match by name Suzuki K Poulose @ 2019-06-14 17:54 ` Suzuki K Poulose 2019-06-21 11:02 ` Pavel Machek 2019-06-24 10:08 ` Alexandre Belloni 2019-06-24 3:23 ` [PATCH v2 00/28] drivers: Consolidate device lookup helpers Greg KH 2 siblings, 2 replies; 6+ messages in thread From: Suzuki K Poulose @ 2019-06-14 17:54 UTC (permalink / raw) To: linux-kernel Cc: gregkh, rafael, suzuki.poulose, Alexander Shishkin, Maxime Coquelin, Alessandro Zummo, Alexander Aring, Alexandre Belloni, Dan Murphy, Heikki Krogerus, Heiko Carstens, Jacek Anaszewski, linux-leds, linux-rtc, linux-usb, linux-wpan, Martin Schwidefsky, Stefan Schmidt 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 <alexander.shishkin@linux.intel.com> Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com> Cc: Alessandro Zummo <a.zummo@towertech.it> Cc: Alexander Aring <alex.aring@gmail.com> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com> Cc: Dan Murphy <dmurphy@ti.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com> Cc: linux-leds@vger.kernel.org Cc: linux-rtc@vger.kernel.org Cc: linux-usb@vger.kernel.org Cc: linux-wpan@vger.kernel.org Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Stefan Schmidt <stefan@datenfreihafen.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: "Rafael J. Wysocki" <rafael@kernel.org> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com> --- drivers/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(-) diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c index e55b902..2b6bd42 100644 --- a/drivers/hwtracing/stm/core.c +++ b/drivers/hwtracing/stm/core.c @@ -89,13 +89,6 @@ static struct class stm_class = { .dev_groups = stm_groups, }; -static int stm_dev_match(struct device *dev, const void *data) -{ - const char *name = data; - - return sysfs_streq(name, dev_name(dev)); -} - /** * stm_find_device() - find stm device by name * @buf: character buffer containing the name @@ -116,7 +109,7 @@ struct stm_device *stm_find_device(const char *buf) if (!stm_core_up) return NULL; - dev = class_find_device(&stm_class, NULL, buf, stm_dev_match); + dev = class_find_device_by_name(&stm_class, buf); if (!dev) return NULL; diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index 85848c5..317a619 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -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); } diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index 4124f4d..1bee39c 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c @@ -663,21 +663,12 @@ void rtc_update_irq(struct rtc_device *rtc, } EXPORT_SYMBOL_GPL(rtc_update_irq); -static int __rtc_match(struct device *dev, const void *data) -{ - const char *name = data; - - if (strcmp(dev_name(dev), name) == 0) - return 1; - return 0; -} - struct rtc_device *rtc_class_open(const char *name) { struct device *dev; struct rtc_device *rtc = NULL; - dev = class_find_device(rtc_class, NULL, name, __rtc_match); + dev = class_find_device_by_name(rtc_class, name); if (dev) rtc = to_rtc_device(dev); diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c index 1058b4b..38a5a47 100644 --- a/drivers/s390/crypto/zcrypt_api.c +++ b/drivers/s390/crypto/zcrypt_api.c @@ -133,12 +133,6 @@ struct zcdn_device { static int zcdn_create(const char *name); static int zcdn_destroy(const char *name); -/* helper function, matches the name for find_zcdndev_by_name() */ -static int __match_zcdn_name(struct device *dev, const void *data) -{ - return strcmp(dev_name(dev), (const char *)data) == 0; -} - /* helper function, matches the devt value for find_zcdndev_by_devt() */ static int __match_zcdn_devt(struct device *dev, const void *data) { @@ -152,10 +146,7 @@ static int __match_zcdn_devt(struct device *dev, const void *data) */ static inline struct zcdn_device *find_zcdndev_by_name(const char *name) { - struct device *dev = - class_find_device(zcrypt_class, NULL, - (void *) name, - __match_zcdn_name); + struct device *dev = class_find_device_by_name(zcrypt_class, name); return dev ? to_zcdn_dev(dev) : NULL; } diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c index f45d8df..07aaa96 100644 --- a/drivers/usb/roles/class.c +++ b/drivers/usb/roles/class.c @@ -90,11 +90,6 @@ static int switch_fwnode_match(struct device *dev, const void *fwnode) return dev_fwnode(dev) == fwnode; } -static int switch_name_match(struct device *dev, const void *name) -{ - return !strcmp((const char *)name, dev_name(dev)); -} - static void *usb_role_switch_match(struct device_connection *con, int ep, void *data) { @@ -107,8 +102,7 @@ static void *usb_role_switch_match(struct device_connection *con, int ep, dev = class_find_device(role_class, NULL, con->fwnode, switch_fwnode_match); } else { - dev = class_find_device(role_class, NULL, con->endpoint[ep], - switch_name_match); + dev = class_find_device_by_name(role_class, con->endpoint[ep]); } return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER); diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 2eb6238..18a0687 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -210,11 +210,6 @@ static int typec_port_fwnode_match(struct device *dev, const void *fwnode) return dev_fwnode(dev) == fwnode; } -static int typec_port_name_match(struct device *dev, const void *name) -{ - return !strcmp((const char *)name, dev_name(dev)); -} - static void *typec_port_match(struct device_connection *con, int ep, void *data) { struct device *dev; @@ -227,8 +222,7 @@ static void *typec_port_match(struct device_connection *con, int ep, void *data) return class_find_device(typec_class, NULL, con->fwnode, typec_port_fwnode_match); - dev = class_find_device(typec_class, NULL, con->endpoint[ep], - typec_port_name_match); + dev = class_find_device_by_name(typec_class, con->endpoint[ep]); return dev ? dev : ERR_PTR(-EPROBE_DEFER); } diff --git a/include/linux/device.h b/include/linux/device.h index a449d09..bb14c7f 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -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, diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c index 60b7ac5..de259b5 100644 --- a/net/ieee802154/core.c +++ b/net/ieee802154/core.c @@ -23,11 +23,6 @@ LIST_HEAD(cfg802154_rdev_list); int cfg802154_rdev_list_generation; -static int wpan_phy_match(struct device *dev, const void *data) -{ - return !strcmp(dev_name(dev), (const char *)data); -} - struct wpan_phy *wpan_phy_find(const char *str) { struct device *dev; @@ -35,7 +30,7 @@ struct wpan_phy *wpan_phy_find(const char *str) if (WARN_ON(!str)) return NULL; - dev = class_find_device(&wpan_phy_class, NULL, str, wpan_phy_match); + dev = class_find_device_by_name(&wpan_phy_class, str); if (!dev) return NULL; -- 2.7.4 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 12/28] drivers: Introduce class_find_device_by_name() helper 2019-06-14 17:54 ` [PATCH v2 12/28] drivers: Introduce class_find_device_by_name() helper Suzuki K Poulose @ 2019-06-21 11:02 ` Pavel Machek 2019-06-24 10:08 ` Alexandre Belloni 1 sibling, 0 replies; 6+ messages in thread From: Pavel Machek @ 2019-06-21 11:02 UTC (permalink / raw) To: Suzuki K Poulose Cc: linux-kernel, gregkh, rafael, Alexander Shishkin, Maxime Coquelin, Alessandro Zummo, Alexander Aring, Alexandre Belloni, Dan Murphy, Heikki Krogerus, Heiko Carstens, Jacek Anaszewski, linux-leds, linux-rtc, linux-usb, linux-wpan, Martin Schwidefsky, Stefan Schmidt [-- Attachment #1: Type: text/plain, Size: 431 bytes --] On Fri 2019-06-14 18:54:07, Suzuki K Poulose wrote: > Add a new wrapper for class_find_device() to search for devices > by name and convert the existing users to use the new helper. > > Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com> Acked-by: Pavel Machek <pavel@ucw.cz> -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 181 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 12/28] drivers: Introduce class_find_device_by_name() helper 2019-06-14 17:54 ` [PATCH v2 12/28] drivers: Introduce class_find_device_by_name() helper Suzuki K Poulose 2019-06-21 11:02 ` Pavel Machek @ 2019-06-24 10:08 ` Alexandre Belloni 1 sibling, 0 replies; 6+ messages in thread From: Alexandre Belloni @ 2019-06-24 10:08 UTC (permalink / raw) To: Suzuki K Poulose Cc: linux-kernel, gregkh, rafael, Alexander Shishkin, Maxime Coquelin, Alessandro Zummo, Alexander Aring, Dan Murphy, Heikki Krogerus, Heiko Carstens, Jacek Anaszewski, linux-leds, linux-rtc, linux-usb, linux-wpan, Martin Schwidefsky, Stefan Schmidt On 14/06/2019 18:54:07+0100, Suzuki K Poulose wrote: > 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 <alexander.shishkin@linux.intel.com> > Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com> > Cc: Alessandro Zummo <a.zummo@towertech.it> > Cc: Alexander Aring <alex.aring@gmail.com> > Cc: Alexandre Belloni <alexandre.belloni@bootlin.com> > Cc: Dan Murphy <dmurphy@ti.com> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> > Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com> > Cc: Heiko Carstens <heiko.carstens@de.ibm.com> > Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com> > Cc: linux-leds@vger.kernel.org > Cc: linux-rtc@vger.kernel.org > Cc: linux-usb@vger.kernel.org > Cc: linux-wpan@vger.kernel.org > Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> > Cc: Stefan Schmidt <stefan@datenfreihafen.org> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> > Cc: "Rafael J. Wysocki" <rafael@kernel.org> > Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com> Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com> > --- > 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(-) > > diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c > index e55b902..2b6bd42 100644 > --- a/drivers/hwtracing/stm/core.c > +++ b/drivers/hwtracing/stm/core.c > @@ -89,13 +89,6 @@ static struct class stm_class = { > .dev_groups = stm_groups, > }; > > -static int stm_dev_match(struct device *dev, const void *data) > -{ > - const char *name = data; > - > - return sysfs_streq(name, dev_name(dev)); > -} > - > /** > * stm_find_device() - find stm device by name > * @buf: character buffer containing the name > @@ -116,7 +109,7 @@ struct stm_device *stm_find_device(const char *buf) > if (!stm_core_up) > return NULL; > > - dev = class_find_device(&stm_class, NULL, buf, stm_dev_match); > + dev = class_find_device_by_name(&stm_class, buf); > if (!dev) > return NULL; > > diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c > index 85848c5..317a619 100644 > --- a/drivers/leds/led-class.c > +++ b/drivers/leds/led-class.c > @@ -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); > } > diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c > index 4124f4d..1bee39c 100644 > --- a/drivers/rtc/interface.c > +++ b/drivers/rtc/interface.c > @@ -663,21 +663,12 @@ void rtc_update_irq(struct rtc_device *rtc, > } > EXPORT_SYMBOL_GPL(rtc_update_irq); > > -static int __rtc_match(struct device *dev, const void *data) > -{ > - const char *name = data; > - > - if (strcmp(dev_name(dev), name) == 0) > - return 1; > - return 0; > -} > - > struct rtc_device *rtc_class_open(const char *name) > { > struct device *dev; > struct rtc_device *rtc = NULL; > > - dev = class_find_device(rtc_class, NULL, name, __rtc_match); > + dev = class_find_device_by_name(rtc_class, name); > if (dev) > rtc = to_rtc_device(dev); > > diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c > index 1058b4b..38a5a47 100644 > --- a/drivers/s390/crypto/zcrypt_api.c > +++ b/drivers/s390/crypto/zcrypt_api.c > @@ -133,12 +133,6 @@ struct zcdn_device { > static int zcdn_create(const char *name); > static int zcdn_destroy(const char *name); > > -/* helper function, matches the name for find_zcdndev_by_name() */ > -static int __match_zcdn_name(struct device *dev, const void *data) > -{ > - return strcmp(dev_name(dev), (const char *)data) == 0; > -} > - > /* helper function, matches the devt value for find_zcdndev_by_devt() */ > static int __match_zcdn_devt(struct device *dev, const void *data) > { > @@ -152,10 +146,7 @@ static int __match_zcdn_devt(struct device *dev, const void *data) > */ > static inline struct zcdn_device *find_zcdndev_by_name(const char *name) > { > - struct device *dev = > - class_find_device(zcrypt_class, NULL, > - (void *) name, > - __match_zcdn_name); > + struct device *dev = class_find_device_by_name(zcrypt_class, name); > > return dev ? to_zcdn_dev(dev) : NULL; > } > diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c > index f45d8df..07aaa96 100644 > --- a/drivers/usb/roles/class.c > +++ b/drivers/usb/roles/class.c > @@ -90,11 +90,6 @@ static int switch_fwnode_match(struct device *dev, const void *fwnode) > return dev_fwnode(dev) == fwnode; > } > > -static int switch_name_match(struct device *dev, const void *name) > -{ > - return !strcmp((const char *)name, dev_name(dev)); > -} > - > static void *usb_role_switch_match(struct device_connection *con, int ep, > void *data) > { > @@ -107,8 +102,7 @@ static void *usb_role_switch_match(struct device_connection *con, int ep, > dev = class_find_device(role_class, NULL, con->fwnode, > switch_fwnode_match); > } else { > - dev = class_find_device(role_class, NULL, con->endpoint[ep], > - switch_name_match); > + dev = class_find_device_by_name(role_class, con->endpoint[ep]); > } > > return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER); > diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c > index 2eb6238..18a0687 100644 > --- a/drivers/usb/typec/class.c > +++ b/drivers/usb/typec/class.c > @@ -210,11 +210,6 @@ static int typec_port_fwnode_match(struct device *dev, const void *fwnode) > return dev_fwnode(dev) == fwnode; > } > > -static int typec_port_name_match(struct device *dev, const void *name) > -{ > - return !strcmp((const char *)name, dev_name(dev)); > -} > - > static void *typec_port_match(struct device_connection *con, int ep, void *data) > { > struct device *dev; > @@ -227,8 +222,7 @@ static void *typec_port_match(struct device_connection *con, int ep, void *data) > return class_find_device(typec_class, NULL, con->fwnode, > typec_port_fwnode_match); > > - dev = class_find_device(typec_class, NULL, con->endpoint[ep], > - typec_port_name_match); > + dev = class_find_device_by_name(typec_class, con->endpoint[ep]); > > return dev ? dev : ERR_PTR(-EPROBE_DEFER); > } > diff --git a/include/linux/device.h b/include/linux/device.h > index a449d09..bb14c7f 100644 > --- a/include/linux/device.h > +++ b/include/linux/device.h > @@ -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, > diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c > index 60b7ac5..de259b5 100644 > --- a/net/ieee802154/core.c > +++ b/net/ieee802154/core.c > @@ -23,11 +23,6 @@ > LIST_HEAD(cfg802154_rdev_list); > int cfg802154_rdev_list_generation; > > -static int wpan_phy_match(struct device *dev, const void *data) > -{ > - return !strcmp(dev_name(dev), (const char *)data); > -} > - > struct wpan_phy *wpan_phy_find(const char *str) > { > struct device *dev; > @@ -35,7 +30,7 @@ struct wpan_phy *wpan_phy_find(const char *str) > if (WARN_ON(!str)) > return NULL; > > - dev = class_find_device(&wpan_phy_class, NULL, str, wpan_phy_match); > + dev = class_find_device_by_name(&wpan_phy_class, str); > if (!dev) > return NULL; > > -- > 2.7.4 > -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 00/28] drivers: Consolidate device lookup helpers 2019-06-14 17:53 [PATCH v2 00/28] drivers: Consolidate device lookup helpers Suzuki K Poulose 2019-06-14 17:54 ` [PATCH v2 10/28] drivers: Add generic helper to match by name Suzuki K Poulose 2019-06-14 17:54 ` [PATCH v2 12/28] drivers: Introduce class_find_device_by_name() helper Suzuki K Poulose @ 2019-06-24 3:23 ` Greg KH 2 siblings, 0 replies; 6+ messages in thread From: Greg KH @ 2019-06-24 3:23 UTC (permalink / raw) To: Suzuki K Poulose Cc: Andrew Lunn, Shyam Sundar S K, rafael, Will Deacon, Ulf Hansson, dri-devel, Pavel Machek, Stefan Schmidt, Wolfram Sang, linux-acpi, Doug Ledford, Jiri Slaby, Tomas Winkler, Dan Murphy, linux-usb, Seung-Woo Kim, linux-kernel, linux-spi, Joe Perches, linux-wpan, Alexandre Belloni, David Airlie, Rafael J . Wysocki , Thierry Reding, Srinivas Kandagatla On Fri, Jun 14, 2019 at 06:53:55PM +0100, Suzuki K Poulose wrote: > We have device iterators to find a particular device matching a criteria > for a given bus/class/driver. i.e, {bus,class,driver}_find_device() APIs. > The matching criteria is a function pointer for the APIs. Often the lookup > is based on a generic property of a device (e.g, name, fwnode, of node pointer > or device type) rather than a driver specific information. However, each driver > writes up its own "match" function, spilling the similar match functions all > over the driver subsystems. > > 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. 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 dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-06-24 10:08 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2019-06-14 17:53 [PATCH v2 00/28] drivers: Consolidate device lookup helpers Suzuki K Poulose 2019-06-14 17:54 ` [PATCH v2 10/28] drivers: Add generic helper to match by name Suzuki K Poulose 2019-06-14 17:54 ` [PATCH v2 12/28] drivers: Introduce class_find_device_by_name() helper Suzuki K Poulose 2019-06-21 11:02 ` Pavel Machek 2019-06-24 10:08 ` Alexandre Belloni 2019-06-24 3:23 ` [PATCH v2 00/28] drivers: Consolidate device lookup helpers Greg KH
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).