diff mbox series

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

Message ID 1559747630-28065-11-git-send-email-suzuki.poulose@arm.com (mailing list archive)
State Superseded
Headers show
Series None | expand

Commit Message

Suzuki K Poulose June 5, 2019, 3:13 p.m. UTC
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(+)

Comments

Greg Kroah-Hartman June 5, 2019, 4:14 p.m. UTC | #1
On Wed, Jun 05, 2019 at 04:13:47PM +0100, Suzuki K Poulose wrote:
> +/**
> + * 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);
> +}

Still has the start parameter, despite the changelog saying it would not
:(
Suzuki K Poulose June 5, 2019, 6:13 p.m. UTC | #2
Hi Greg,

On 06/05/2019 05:14 PM, Greg KH wrote:
> On Wed, Jun 05, 2019 at 04:13:47PM +0100, Suzuki K Poulose wrote:
>> +/**
>> + * 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);
>> +}
> 
> Still has the start parameter, despite the changelog saying it would not
> :(
> 

Well, I kept the start parameter just for the _devt variants, as
mentioned in the changelog:

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

Somehow I thought the dev_t may be duplicate for devices, which is why
I didn't change that alone. But that was silly of me to ignore the minor
number part. I will respin it fixing that.

Suzuki
diff mbox series

Patch

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,