Skip to content

Commit 2056b28

Browse files
jic23robherring
authored andcommitted
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: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Rob Herring <robh@kernel.org> Link: https://lore.kernel.org/r/20240225142714.286440-4-jic23@kernel.org Signed-off-by: Rob Herring <robh@kernel.org>
1 parent 34af455 commit 2056b28

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

drivers/of/unittest.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,27 +233,22 @@ static void __init of_unittest_dynamic(void)
233233

234234
static int __init of_unittest_check_node_linkage(struct device_node *np)
235235
{
236-
struct device_node *child;
237236
int count = 0, rc;
238237

239-
for_each_child_of_node(np, child) {
238+
for_each_child_of_node_scoped(np, child) {
240239
if (child->parent != np) {
241240
pr_err("Child node %pOFn links to wrong parent %pOFn\n",
242241
child, np);
243-
rc = -EINVAL;
244-
goto put_child;
242+
return -EINVAL;
245243
}
246244

247245
rc = of_unittest_check_node_linkage(child);
248246
if (rc < 0)
249-
goto put_child;
247+
return rc;
250248
count += rc;
251249
}
252250

253251
return count + 1;
254-
put_child:
255-
of_node_put(child);
256-
return rc;
257252
}
258253

259254
static void __init of_unittest_check_tree_linkage(void)

0 commit comments

Comments
 (0)