Skip to content

Commit 855ff28

Browse files
JuliaLawallrobherring
authored andcommitted
of/unittest: add missing of_node_put
for_each_child_of_node performs an of_node_get on each iteration, so a break out of the loop requires an of_node_put. A simplified version of the semantic patch that fixes this problem is as follows (http://coccinelle.lip6.fr): // <smpl> @@ expression root,e; local idexpression child; @@ for_each_child_of_node(root, child) { ... when != of_node_put(child) when != e = child ( return child; | + of_node_put(child); ? return ...; ) ... } // </smpl> Combine the puts into code at the end of the function, for conciseness. Signed-off-by: Julia Lawall <[email protected]> Signed-off-by: Rob Herring <[email protected]>
1 parent e300745 commit 855ff28

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/of/unittest.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,20 @@ static int __init of_unittest_check_node_linkage(struct device_node *np)
205205
if (child->parent != np) {
206206
pr_err("Child node %s links to wrong parent %s\n",
207207
child->name, np->name);
208-
return -EINVAL;
208+
rc = -EINVAL;
209+
goto put_child;
209210
}
210211

211212
rc = of_unittest_check_node_linkage(child);
212213
if (rc < 0)
213-
return rc;
214+
goto put_child;
214215
count += rc;
215216
}
216217

217218
return count + 1;
219+
put_child:
220+
of_node_put(child);
221+
return rc;
218222
}
219223

220224
static void __init of_unittest_check_tree_linkage(void)

0 commit comments

Comments
 (0)