* [PATCH 08/13] drivers: Add generic helper to match by name
[not found] <1559747630-28065-1-git-send-email-suzuki.poulose@arm.com>
@ 2019-06-05 15:13 ` Suzuki K Poulose
2019-06-05 15:13 ` [PATCH 10/13] drivers: Introduce variants of class_find_device() Suzuki K Poulose
1 sibling, 0 replies; 4+ messages in thread
From: Suzuki K Poulose @ 2019-06-05 15:13 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, Peter Oberparleiter,
Stefan Schmidt, Rafael J. Wysocki
Add a helper to match the device name
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/core.c | 6 ++++++
include/linux/device.h | 1 +
2 files changed, 7 insertions(+)
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..74dd9c6 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -167,6 +167,7 @@ int device_match_of_node(struct device *dev, const void *np);
int device_match_fwnode(struct device *dev, const void *fwnode);
int device_match_devt(struct device *dev, const void *pdevt);
int device_match_acpi_dev(struct device *dev, const void *adev);
+int device_match_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));
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 10/13] drivers: Introduce variants of class_find_device()
[not found] <1559747630-28065-1-git-send-email-suzuki.poulose@arm.com>
2019-06-05 15:13 ` [PATCH 08/13] drivers: Add generic helper to match by name Suzuki K Poulose
@ 2019-06-05 15:13 ` Suzuki K Poulose
2019-06-05 16:14 ` Greg KH
1 sibling, 1 reply; 4+ messages in thread
From: Suzuki K Poulose @ 2019-06-05 15:13 UTC (permalink / raw)
To: linux-kernel
Cc: gregkh, rafael, suzuki.poulose, Alessandro Zummo,
Alexander Aring, Alexander Shishkin, Alexandre Belloni,
Andrew Lunn, Arnd Bergmann, Dan Murphy, David S. Miller,
Florian Fainelli, Harald Freudenberger, Heikki Krogerus,
Heiko Carstens, Heiner Kallweit, Jacek Anaszewski, Jiri Slaby,
Liam Girdwood, linux-leds, linux-rtc, linux-usb, linux-wpan,
Mark Brown, Maxime Coquelin, Pavel Machek, Peter Rosin,
Stefan Schmidt, Tomas Winkler, Rafael J. Wysocki
Now that we have generic helpers to match various generic
device attributes, provide wrappers to the class_find_device()
to lookup devices by individual properties. The new wrappers
except the lookup by devt, drops the "start" device pointer as
none of the existing users need it and the attributes are usually
unique. The idea is to stop the proliferation of custom match
functions to do generic attribute matching.
So now we have :
class_find_device_by_name
class_find_device_by_of_node
class_find_device_by_fwnode
class_find_device_by_devt
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Dan Murphy <dmurphy@ti.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Harald Freudenberger <freude@linux.ibm.com>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Heiner Kallweit <hkallweit1@gmail.com>
Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Liam Girdwood <lgirdwood@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: Mark Brown <broonie@kernel.org>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Peter Rosin <peda@axentia.se>
Cc: Stefan Schmidt <stefan@datenfreihafen.org>
Cc: Tomas Winkler <tomas.winkler@intel.com>
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>
---
include/linux/device.h | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/include/linux/device.h b/include/linux/device.h
index 8c8727b..4396edc 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -474,6 +474,57 @@ 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);
+}
+
+/**
+ * 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);
+}
+
+/**
+ * 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);
+}
+
+/**
+ * class_find_device_by_devt : device iterator for locating a particular device
+ * matching the device type.
+ * @class: class type
+ * @start: device to start search from
+ * @devt: device type of the device to match.
+ */
+static inline struct device *class_find_device_by_devt(struct class *class,
+ struct device *start,
+ dev_t devt)
+{
+ return class_find_device(class, start, &devt, device_match_devt);
+}
+
struct class_attribute {
struct attribute attr;
ssize_t (*show)(struct class *class, struct class_attribute *attr,
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread