* [PATCH 1/3] of: fix of_node leak caused in of_find_node_opts_by_path
@ 2017-02-06 4:55 Qi Hou
2017-02-09 15:11 ` Rob Herring
0 siblings, 1 reply; 3+ messages in thread
From: Qi Hou @ 2017-02-06 4:55 UTC (permalink / raw)
To: peda, stable, robh, linux-i2c
Cc: leif.lindholm, pantelis.antoniou, grant.likely, bruce.ashfield,
paul.gortmaker, xiao.zhang
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>
---
drivers/of/base.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index d4bea3c..ce8206f 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
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;
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/3] of: fix of_node leak caused in of_find_node_opts_by_path
2017-02-06 4:55 [PATCH 1/3] of: fix of_node leak caused in of_find_node_opts_by_path Qi Hou
@ 2017-02-09 15:11 ` Rob Herring
2017-02-10 1:15 ` qhou
0 siblings, 1 reply; 3+ messages in thread
From: Rob Herring @ 2017-02-09 15:11 UTC (permalink / raw)
To: Qi Hou
Cc: Peter Rosin, stable, linux-i2c@vger.kernel.org, Leif Lindholm,
Pantelis Antoniou, Grant Likely, Bruce Ashfield, Paul Gortmaker,
ZhangXiao
On Sun, Feb 5, 2017 at 10:55 PM, Qi Hou <qi.hou@windriver.com> wrote:
> 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>
> ---
> drivers/of/base.c | 3 +++
> 1 file changed, 3 insertions(+)
It doesn't look like there is any inter-dependency with this patch and
the other 2, so I'll apply this one.
Rob
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/3] of: fix of_node leak caused in of_find_node_opts_by_path
2017-02-09 15:11 ` Rob Herring
@ 2017-02-10 1:15 ` qhou
0 siblings, 0 replies; 3+ messages in thread
From: qhou @ 2017-02-10 1:15 UTC (permalink / raw)
To: Rob Herring
Cc: Peter Rosin, stable, linux-i2c@vger.kernel.org, Leif Lindholm,
Pantelis Antoniou, Grant Likely, Bruce Ashfield, Paul Gortmaker,
ZhangXiao
On 2017年02月09日 23:11, Rob Herring wrote:
> On Sun, Feb 5, 2017 at 10:55 PM, Qi Hou <qi.hou@windriver.com> wrote:
>> 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>
>> ---
>> drivers/of/base.c | 3 +++
>> 1 file changed, 3 insertions(+)
> It doesn't look like there is any inter-dependency with this patch and
> the other 2, so I'll apply this one.
No, there is no inter-dependency in these three patches.
Just since they are all related with of_node_put and reported by
kmemleak and debugged
by the similar means, I sent them together.
-- Best regards,
Qi Hou
>
> Rob
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-02-10 1:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-06 4:55 [PATCH 1/3] of: fix of_node leak caused in of_find_node_opts_by_path Qi Hou
2017-02-09 15:11 ` Rob Herring
2017-02-10 1:15 ` qhou
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox