[PATCH 1/3] of: Add an iterator to walk up parent nodes
From: Rob Herring (Arm)
Date: Thu May 30 2024 - 21:03:52 EST
Similar to other node iterators, add one for walking up parent
nodes. The iterator starts on the current node, not the immediate
parent as that seems to be the common case and starting with the parent
node can be implemented like this:
for_each_parent_of_node_scoped(parent, of_get_parent(node))
Signed-off-by: Rob Herring (Arm) <robh@xxxxxxxxxx>
---
include/linux/of.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/include/linux/of.h b/include/linux/of.h
index a0bedd038a05..c322802dfc2b 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -1482,6 +1482,11 @@ static inline int of_property_read_s32(const struct device_node *np,
child != NULL; \
child = of_get_next_available_child(parent, child))
+#define for_each_parent_of_node_scoped(parent, node) \
+ for (struct device_node *parent __free(device_node) = \
+ of_node_get(node) ; \
+ parent; parent = of_get_next_parent(parent))
+
#define for_each_of_cpu_node(cpu) \
for (cpu = of_get_next_cpu_node(NULL); cpu != NULL; \
cpu = of_get_next_cpu_node(cpu))
--
2.43.0