From: Qi Hou <qi.hou@windriver.com>
To: peda@axentia.se, stable@vger.kernel.org, robh@kernel.org,
linux-i2c@vger.kernel.org
Cc: leif.lindholm@linaro.org, pantelis.antoniou@konsulko.com,
grant.likely@linaro.org, bruce.ashfield@windriver.com,
paul.gortmaker@windriver.com, xiao.zhang@windriver.com
Subject: [PATCH 1/3] of: fix of_node leak caused in of_find_node_opts_by_path
Date: Mon, 6 Feb 2017 12:55:19 +0800 [thread overview]
Message-ID: <1486356919-97176-1-git-send-email-qi.hou@windriver.com> (raw)
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
next reply other threads:[~2017-02-06 4:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-06 4:55 Qi Hou [this message]
2017-02-09 15:11 ` [PATCH 1/3] of: fix of_node leak caused in of_find_node_opts_by_path Rob Herring
2017-02-10 1:15 ` qhou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1486356919-97176-1-git-send-email-qi.hou@windriver.com \
--to=qi.hou@windriver.com \
--cc=bruce.ashfield@windriver.com \
--cc=grant.likely@linaro.org \
--cc=leif.lindholm@linaro.org \
--cc=linux-i2c@vger.kernel.org \
--cc=pantelis.antoniou@konsulko.com \
--cc=paul.gortmaker@windriver.com \
--cc=peda@axentia.se \
--cc=robh@kernel.org \
--cc=stable@vger.kernel.org \
--cc=xiao.zhang@windriver.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox