aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorQi Hou <qi.hou@windriver.com>2017-02-05 23:55:19 -0500
committerRob Herring <robh@kernel.org>2017-02-09 10:11:30 -0500
commit0549bde0fcb11a95773e7dc4121738b9e653abf4 (patch)
tree1363dcf0fe079815db273593ded5b08c7282847a /drivers
parent4b741bc35962ccf93b798a233512850c48c2646e (diff)
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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/of/base.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index d4bea3c797d6..ce8206f9f97a 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -842,8 +842,11 @@ struct device_node *of_find_node_opts_by_path(const char *path, const char **opt
842 if (!np) 842 if (!np)
843 np = of_node_get(of_root); 843 np = of_node_get(of_root);
844 while (np && *path == '/') { 844 while (np && *path == '/') {
845 struct device_node *tmp = np;
846
845 path++; /* Increment past '/' delimiter */ 847 path++; /* Increment past '/' delimiter */
846 np = __of_find_node_by_path(np, path); 848 np = __of_find_node_by_path(np, path);
849 of_node_put(tmp);
847 path = strchrnul(path, '/'); 850 path = strchrnul(path, '/');
848 if (separator && separator < path) 851 if (separator && separator < path)
849 break; 852 break;