Skip to content

Commit 620097c

Browse files
krzkrobherring
authored andcommitted
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>
1 parent c75afcb commit 620097c

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ ForEachMacros:
259259
- 'for_each_collection'
260260
- 'for_each_comp_order'
261261
- 'for_each_compatible_node'
262+
- 'for_each_compatible_node_scoped'
262263
- 'for_each_component_dais'
263264
- 'for_each_component_dais_safe'
264265
- 'for_each_conduit'

include/linux/of.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,13 @@ static inline int of_property_read_s32(const struct device_node *np,
14851485
#define for_each_compatible_node(dn, type, compatible) \
14861486
for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
14871487
dn = of_find_compatible_node(dn, type, compatible))
1488+
1489+
#define for_each_compatible_node_scoped(dn, type, compatible) \
1490+
for (struct device_node *dn __free(device_node) = \
1491+
of_find_compatible_node(NULL, type, compatible); \
1492+
dn; \
1493+
dn = of_find_compatible_node(dn, type, compatible))
1494+
14881495
#define for_each_matching_node(dn, matches) \
14891496
for (dn = of_find_matching_node(NULL, matches); dn; \
14901497
dn = of_find_matching_node(dn, matches))

scripts/dtc/dt-extract-compatibles

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def parse_compatibles(file, compat_ignore_list):
7272
compat_list += parse_of_functions(data, "_is_compatible")
7373
compat_list += parse_of_functions(data, "of_find_compatible_node")
7474
compat_list += parse_of_functions(data, "for_each_compatible_node")
75+
compat_list += parse_of_functions(data, "for_each_compatible_node_scoped")
7576
compat_list += parse_of_functions(data, "of_get_compatible_child")
7677

7778
return compat_list

0 commit comments

Comments
 (0)