From: Krzysztof Kozlowski Date: Fri, 9 Jan 2026 16:57:45 +0000 (+0100) Subject: of: Add for_each_compatible_node_scoped() helper X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=620097c6c070fb01259b5fcab915065ce746e5a1;p=thirdparty%2Fkernel%2Flinux.git 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 Reviewed-by: Jonathan Cameron Signed-off-by: Krzysztof Kozlowski Link: https://patch.msgid.link/20260109-of-for-each-compatible-scoped-v3-1-c22fa2c0749a@oss.qualcomm.com Signed-off-by: Rob Herring (Arm) --- diff --git a/.clang-format b/.clang-format index 2ceca764122f8..1f2429c474335 100644 --- a/.clang-format +++ b/.clang-format @@ -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' diff --git a/include/linux/of.h b/include/linux/of.h index 9bbdcf25a2b44..be6ec4916adf5 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)) diff --git a/scripts/dtc/dt-extract-compatibles b/scripts/dtc/dt-extract-compatibles index 6570efabaa649..87999d7073905 100755 --- a/scripts/dtc/dt-extract-compatibles +++ b/scripts/dtc/dt-extract-compatibles @@ -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