[PATCH 2/5] of: fix of_graph_get_next_endpoint()

Sascha Hauer s.hauer at pengutronix.de
Wed Sep 25 07:01:12 PDT 2024


of_get_child_by_name() behaves differently than the corresponding Linux
function. The barebox version matches the full name of the node whereas
the Linux version skips the part after the '@' in the node.

of_graph_get_next_endpoint() explicitly needs the Linux behaviour.

As of_get_child_by_name() is heavily used in barebox and some call sites
might depend on the different behaviour, do not alter
of_get_child_by_name(), but instead introduce a new function that has
the Linux behaviour and use that in of_graph_get_next_endpoint().

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/of/base.c | 26 ++++++++++++++++++++++++--
 include/of.h      |  8 ++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 6fd69e7d7d..fbbc3316fc 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2139,7 +2139,7 @@ EXPORT_SYMBOL(of_get_compatible_child);
  *	@node:	parent node
  *	@name:	child name to look for.
  *
- *      This function looks for child node for given matching name
+ *      This function looks for child node for given matching full name
  *
  *	Returns a node pointer if found or NULL.
  */
@@ -2156,6 +2156,28 @@ struct device_node *of_get_child_by_name(const struct device_node *node,
 }
 EXPORT_SYMBOL(of_get_child_by_name);
 
+/**
+ *	of_get_child_by_name_stem - Find the child node by name for a given parent
+ *	@node:	parent node
+ *	@name:	child name to look for.
+ *
+ *      This function looks for child node for given matching name excluding the
+ *      unit address
+ *
+ *	Returns a node pointer if found or NULL.
+ */
+struct device_node *of_get_child_by_name_stem(const struct device_node *node,
+				const char *name)
+{
+	struct device_node *child;
+
+	for_each_child_of_node(node, child)
+		if (of_node_name_eq(child, name))
+			break;
+	return child;
+}
+EXPORT_SYMBOL(of_get_child_by_name_stem);
+
 /**
  * of_property_read_string_helper() - Utility helper for parsing string properties
  * @np:		device node from which the property value is to be read.
@@ -3296,7 +3318,7 @@ struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
 		if (node)
 			parent = node;
 
-		port = of_get_child_by_name(parent, "port");
+		port = of_get_child_by_name_stem(parent, "port");
 		if (!port) {
 			pr_err("%s(): no port node found in %pOF\n",
 			       __func__, parent);
diff --git a/include/of.h b/include/of.h
index 55f2c0cbde..05e92d41b9 100644
--- a/include/of.h
+++ b/include/of.h
@@ -218,6 +218,8 @@ extern struct device_node *of_get_compatible_child(const struct device_node *par
 					const char *compatible);
 extern struct device_node *of_get_child_by_name(const struct device_node *node,
 					const char *name);
+extern struct device_node *of_get_child_by_name_stem(const struct device_node *node,
+					const char *name);
 extern char *of_get_reproducible_name(struct device_node *node);
 extern struct device_node *of_get_node_by_reproducible_name(struct device_node *dstroot,
 							    struct device_node *srcnp);
@@ -560,6 +562,12 @@ static inline struct device_node *of_get_child_by_name(
 	return NULL;
 }
 
+static inline struct device_node *of_get_child_by_name_stem(
+			const struct device_node *node, const char *name)
+{
+	return NULL;
+}
+
 static inline char *of_get_reproducible_name(struct device_node *node)
 {
 	return NULL;

-- 
2.39.5




More information about the barebox mailing list