Commit 2056b282 authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Rob Herring

of: unittest: Use for_each_child_of_node_scoped()

A simple example of the utility of this autocleanup approach to
handling of_node_put().

In this particular case some of the nodes needed for the test are
not available and the _available_ version would cause them to be
skipped resulting in a test failure.
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: default avatarRob Herring <robh@kernel.org>
Link: https://lore.kernel.org/r/20240225142714.286440-4-jic23@kernel.orgSigned-off-by: default avatarRob Herring <robh@kernel.org>
parent 34af4554
...@@ -233,27 +233,22 @@ static void __init of_unittest_dynamic(void) ...@@ -233,27 +233,22 @@ static void __init of_unittest_dynamic(void)
static int __init of_unittest_check_node_linkage(struct device_node *np) static int __init of_unittest_check_node_linkage(struct device_node *np)
{ {
struct device_node *child;
int count = 0, rc; int count = 0, rc;
for_each_child_of_node(np, child) { for_each_child_of_node_scoped(np, child) {
if (child->parent != np) { if (child->parent != np) {
pr_err("Child node %pOFn links to wrong parent %pOFn\n", pr_err("Child node %pOFn links to wrong parent %pOFn\n",
child, np); child, np);
rc = -EINVAL; return -EINVAL;
goto put_child;
} }
rc = of_unittest_check_node_linkage(child); rc = of_unittest_check_node_linkage(child);
if (rc < 0) if (rc < 0)
goto put_child; return rc;
count += rc; count += rc;
} }
return count + 1; return count + 1;
put_child:
of_node_put(child);
return rc;
} }
static void __init of_unittest_check_tree_linkage(void) static void __init of_unittest_check_tree_linkage(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment