summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKrzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>2026-01-09 17:57:45 +0100
committerRob Herring (Arm) <robh@kernel.org>2026-02-03 20:58:12 -0600
commit620097c6c070fb01259b5fcab915065ce746e5a1 (patch)
tree28c3becd19693d11dda745e2809f301b5552ea9d /include
parentc75afcb4a8e708747534d8b88a1bcd912cdf9223 (diff)
of: Add for_each_compatible_node_scoped() helper
Just like looping through children and available children, add a scoped helper for for_each_compatible_node() so error paths can drop of_node_put() leading to simpler code. Suggested-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com> Link: https://patch.msgid.link/20260109-of-for-each-compatible-scoped-v3-1-c22fa2c0749a@oss.qualcomm.com Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/of.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/include/linux/of.h b/include/linux/of.h
index 9bbdcf25a2b4..be6ec4916adf 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -1485,6 +1485,13 @@ static inline int of_property_read_s32(const struct device_node *np,
#define for_each_compatible_node(dn, type, compatible) \
for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
dn = of_find_compatible_node(dn, type, compatible))
+
+#define for_each_compatible_node_scoped(dn, type, compatible) \
+ for (struct device_node *dn __free(device_node) = \
+ of_find_compatible_node(NULL, type, compatible); \
+ dn; \
+ dn = of_find_compatible_node(dn, type, compatible))
+
#define for_each_matching_node(dn, matches) \
for (dn = of_find_matching_node(NULL, matches); dn; \
dn = of_find_matching_node(dn, matches))