Skip to content

Commit 0549bde

Browse files
Qi Hourobherring
authored andcommitted
of: fix of_node leak caused in of_find_node_opts_by_path
During stepping down the tree, parent node is gotten first and its refcount is increased with of_node_get() in __of_get_next_child(). Since it just being used as tmp node, its refcount must be decreased with of_node_put() after traversing its child nodes. Or, its refcount will never be descreased to ZERO, then it will never be freed, as well as other related memory blocks. To fix this, decrease refcount of parent with of_node_put() after __of_find_node_by_path(). Signed-off-by: Qi Hou <qi.hou@windriver.com> Acked-by: Peter Rosin <peda@axentia.se> Signed-off-by: Rob Herring <robh@kernel.org>
1 parent 4b741bc commit 0549bde

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/of/base.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,8 +842,11 @@ struct device_node *of_find_node_opts_by_path(const char *path, const char **opt
842842
if (!np)
843843
np = of_node_get(of_root);
844844
while (np && *path == '/') {
845+
struct device_node *tmp = np;
846+
845847
path++; /* Increment past '/' delimiter */
846848
np = __of_find_node_by_path(np, path);
849+
of_node_put(tmp);
847850
path = strchrnul(path, '/');
848851
if (separator && separator < path)
849852
break;

0 commit comments

Comments
 (0)