Skip to content

Commit

Permalink
of: fix of_node leak caused in of_find_node_opts_by_path
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Qi Hou authored and robherring committed Feb 9, 2017
1 parent 4b741bc commit 0549bde
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/of/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,11 @@ struct device_node *of_find_node_opts_by_path(const char *path, const char **opt
if (!np)
np = of_node_get(of_root);
while (np && *path == '/') {
struct device_node *tmp = np;

path++; /* Increment past '/' delimiter */
np = __of_find_node_by_path(np, path);
of_node_put(tmp);
path = strchrnul(path, '/');
if (separator && separator < path)
break;
Expand Down

0 comments on commit 0549bde

Please sign in to comment.