[RFC,04/57] drivers: Add generic match helper to match the device of_node
diff mbox series

Message ID 1559577023-558-5-git-send-email-suzuki.poulose@arm.com
State New
Headers show
Series
  • [RFC,01/57] drivers: s390/cio: Use driver_for_each_device
Related show

Commit Message

Suzuki K Poulose June 3, 2019, 3:49 p.m. UTC
Instead of spilling the match function to check the of_node for
a given value, lets add a common helper. Also add a wrapper to
find device by of_node pointer for bus.

Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/base/core.c    |  6 ++++++
 include/linux/device.h | 17 +++++++++++++++++
 2 files changed, 23 insertions(+)

Patch
diff mbox series

diff --git a/drivers/base/core.c b/drivers/base/core.c
index fd7511e..d20699c 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3328,3 +3328,9 @@  void device_set_of_node_from_dev(struct device *dev, const struct device *dev2)
 	dev->of_node_reused = true;
 }
 EXPORT_SYMBOL_GPL(device_set_of_node_from_dev);
+
+int device_match_of_node(struct device *dev, void *np)
+{
+	return dev->of_node == np;
+}
+EXPORT_SYMBOL_GPL(device_match_of_node);
diff --git a/include/linux/device.h b/include/linux/device.h
index e85264f..fe16be4 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -163,6 +163,8 @@  void subsys_dev_iter_init(struct subsys_dev_iter *iter,
 struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter);
 void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
 
+int device_match_of_node(struct device *dev, void *np);
+
 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,
@@ -171,6 +173,21 @@  struct device *bus_find_device(struct bus_type *bus, struct device *start,
 struct device *bus_find_device_by_name(struct bus_type *bus,
 				       struct device *start,
 				       const char *name);
+
+/**
+ * bus_find_device_by_of_node : device iterator for locating a particular device
+ * matching the of_node.
+ * @bus: bus type
+ * @start: Device to begin with
+ * @np: of_node of the device to match.
+ */
+static inline struct device *bus_find_device_by_of_node(struct bus_type *bus,
+							struct device *start,
+							struct device_node *np)
+{
+	return bus_find_device(bus, start, np, device_match_of_node);
+}
+
 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,