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>
This commit is contained in:
Krzysztof Kozlowski 2026-01-09 17:57:45 +01:00 committed by Rob Herring (Arm)
parent c75afcb4a8
commit 620097c6c0
3 changed files with 9 additions and 0 deletions

View file

@ -259,6 +259,7 @@ ForEachMacros:
- 'for_each_collection'
- 'for_each_comp_order'
- 'for_each_compatible_node'
- 'for_each_compatible_node_scoped'
- 'for_each_component_dais'
- 'for_each_component_dais_safe'
- 'for_each_conduit'

View file

@ -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))

View file

@ -72,6 +72,7 @@ def parse_compatibles(file, compat_ignore_list):
compat_list += parse_of_functions(data, "_is_compatible")
compat_list += parse_of_functions(data, "of_find_compatible_node")
compat_list += parse_of_functions(data, "for_each_compatible_node")
compat_list += parse_of_functions(data, "for_each_compatible_node_scoped")
compat_list += parse_of_functions(data, "of_get_compatible_child")
return compat_list