]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
of: unittest: Use for_each_child_of_node_scoped()
authorJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 25 Feb 2024 14:27:13 +0000 (14:27 +0000)
committerRob Herring <robh@kernel.org>
Wed, 13 Mar 2024 22:59:00 +0000 (16:59 -0600)
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>
drivers/of/unittest.c

index 4c67de37bf2636c09583e0aac32bea93dc27fb96..0913d916e790501a40b4f1dae5fbad7fd1582aba 100644 (file)
@@ -233,27 +233,22 @@ static void __init of_unittest_dynamic(void)
 
 static int __init of_unittest_check_node_linkage(struct device_node *np)
 {
-       struct device_node *child;
        int count = 0, rc;
 
-       for_each_child_of_node(np, child) {
+       for_each_child_of_node_scoped(np, child) {
                if (child->parent != np) {
                        pr_err("Child node %pOFn links to wrong parent %pOFn\n",
                                 child, np);
-                       rc = -EINVAL;
-                       goto put_child;
+                       return -EINVAL;
                }
 
                rc = of_unittest_check_node_linkage(child);
                if (rc < 0)
-                       goto put_child;
+                       return rc;
                count += rc;
        }
 
        return count + 1;
-put_child:
-       of_node_put(child);
-       return rc;
 }
 
 static void __init of_unittest_check_tree_linkage(void)