[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1559747630-28065-12-git-send-email-suzuki.poulose@arm.com>
Date: Wed, 5 Jun 2019 16:13:48 +0100
From: Suzuki K Poulose <suzuki.poulose@....com>
To: linux-kernel@...r.kernel.org
Cc: gregkh@...uxfoundation.org, rafael@...nel.org,
suzuki.poulose@....com,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Andrew Lunn <andrew@...n.ch>, Daniel Vetter <daniel@...ll.ch>,
David Airlie <airlied@...ux.ie>,
"David S. Miller" <davem@...emloft.net>,
devicetree@...r.kernel.org, Doug Ledford <dledford@...hat.com>,
dri-devel@...ts.freedesktop.org,
Florian Fainelli <f.fainelli@...il.com>,
Frank Rowand <frowand.list@...il.com>,
Heiko Stuebner <heiko@...ech.de>,
Jason Gunthorpe <jgg@...pe.ca>,
Liam Girdwood <lgirdwood@...il.com>, linux-i2c@...r.kernel.org,
linux-rockchip@...ts.infradead.org, linux-spi@...r.kernel.org,
linux-usb@...r.kernel.org,
Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
Mark Brown <broonie@...nel.org>,
Mathieu Poirier <mathieu.poirier@...aro.org>,
Maxime Ripard <maxime.ripard@...tlin.com>,
Oliver Neukum <oneukum@...e.com>,
Rob Herring <robh+dt@...nel.org>,
Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
Srinivas Kandagatla <srinivas.kandagatla@...aro.org>,
Takashi Iwai <tiwai@...e.com>, Wolfram Sang <wsa@...-dreams.de>
Subject: [PATCH 11/13] drivers: Introduce variants for bus_find_device()
Similar to the class_find_device_by_*() introduce the variants
for bus_find_device() to automatically search for device by
generic device properties.
Here is the list of new helpers :
bus_find_device_by_of_node
bus_find_device_by_fwnode
bus_find_device_by_devt
bus_find_next_device
While at it convert the bus_find_device_by_name to static inline
reusing the generic helper to match the name.
Cc: Alexander Shishkin <alexander.shishkin@...ux.intel.com>
Cc: Andrew Lunn <andrew@...n.ch>
Cc: Daniel Vetter <daniel@...ll.ch>
Cc: David Airlie <airlied@...ux.ie>
Cc: "David S. Miller" <davem@...emloft.net>
Cc: devicetree@...r.kernel.org
Cc: Doug Ledford <dledford@...hat.com>
Cc: dri-devel@...ts.freedesktop.org
Cc: Florian Fainelli <f.fainelli@...il.com>
Cc: Frank Rowand <frowand.list@...il.com>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Heiko Stuebner <heiko@...ech.de>
Cc: Jason Gunthorpe <jgg@...pe.ca>
Cc: Liam Girdwood <lgirdwood@...il.com>
Cc: linux-i2c@...r.kernel.org
Cc: linux-rockchip@...ts.infradead.org
Cc: linux-spi@...r.kernel.org
Cc: linux-usb@...r.kernel.org
Cc: Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>
Cc: Mark Brown <broonie@...nel.org>
Cc: Mathieu Poirier <mathieu.poirier@...aro.org>
Cc: Maxime Ripard <maxime.ripard@...tlin.com>
Cc: Oliver Neukum <oneukum@...e.com>
Cc: "Rafael J. Wysocki" <rafael@...nel.org>
Cc: Rob Herring <robh+dt@...nel.org>
Cc: Sebastian Andrzej Siewior <bigeasy@...utronix.de>
Cc: Srinivas Kandagatla <srinivas.kandagatla@...aro.org>
Cc: Takashi Iwai <tiwai@...e.com>
Cc: Wolfram Sang <wsa@...-dreams.de>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@....com>
---
drivers/base/bus.c | 24 -------------------
include/linux/device.h | 64 +++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 61 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/include/linux/device.h b/include/linux/device.h
index 4396edc..10de79d 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -175,9 +175,67 @@ int bus_for_each_dev(struct bus_type *bus, struct device *start, 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);
+}
+
+/**
+ * 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);
+}
+
+/**
+ * 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);
+}
+
+/**
+ * bus_find_device_by_devt : device iterator for locating a particular device
+ * matching the device type.
+ * @bus: bus type
+ * @start: device to start the search from
+ * @devt: device type of the device to match.
+ */
+static inline struct device *
+bus_find_device_by_devt(struct bus_type *bus, struct device *start, dev_t devt)
+{
+ return bus_find_device(bus, start, &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,
--
2.7.4
Powered by blists - more mailing lists