[PATCH 10/13] drivers: Introduce variants of class_find_device()

From: Suzuki K Poulose
Date: Wed Jun 05 2019 - 11:18:55 EST


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@xxxxxxxxxxxx>
Cc: Alexander Aring <alex.aring@xxxxxxxxx>
Cc: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>
Cc: Alexandre Belloni <alexandre.belloni@xxxxxxxxxxx>
Cc: Andrew Lunn <andrew@xxxxxxx>
Cc: Arnd Bergmann <arnd@xxxxxxxx>
Cc: Dan Murphy <dmurphy@xxxxxx>
Cc: "David S. Miller" <davem@xxxxxxxxxxxxx>
Cc: Florian Fainelli <f.fainelli@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
Cc: Harald Freudenberger <freude@xxxxxxxxxxxxx>
Cc: Heikki Krogerus <heikki.krogerus@xxxxxxxxxxxxxxx>
Cc: Heiko Carstens <heiko.carstens@xxxxxxxxxx>
Cc: Heiner Kallweit <hkallweit1@xxxxxxxxx>
Cc: Jacek Anaszewski <jacek.anaszewski@xxxxxxxxx>
Cc: Jiri Slaby <jslaby@xxxxxxxx>
Cc: Liam Girdwood <lgirdwood@xxxxxxxxx>
Cc: linux-leds@xxxxxxxxxxxxxxx
Cc: linux-rtc@xxxxxxxxxxxxxxx
Cc: linux-usb@xxxxxxxxxxxxxxx
Cc: linux-wpan@xxxxxxxxxxxxxxx
Cc: Mark Brown <broonie@xxxxxxxxxx>
Cc: Maxime Coquelin <mcoquelin.stm32@xxxxxxxxx>
Cc: Pavel Machek <pavel@xxxxxx>
Cc: Peter Rosin <peda@xxxxxxxxxx>
Cc: Stefan Schmidt <stefan@xxxxxxxxxxxxxxxxxx>
Cc: Tomas Winkler <tomas.winkler@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@xxxxxxxxx>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@xxxxxxx>
---
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