From: Geert Uytterhoeven <geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
To: Grant Likely
<grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: Gaurav Minocha
<gaurav.minocha.os-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Geert Uytterhoeven
<geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
Subject: [PATCH] of: Add missing of_node_put() in of_find_node_by_path()
Date: Wed, 14 Jan 2015 16:45:56 +0100 [thread overview]
Message-ID: <1421250356-16690-1-git-send-email-geert+renesas@glider.be> (raw)
When traversing all nodes and moving to a new path component, the old
one must be released by calling of_node_put(). Else the refcounts of the
parent node(s) will not be decremented.
Signed-off-by: Geert Uytterhoeven <geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
---
Background.
While investigating a reference count imbalance issue with
CONFIG_OF_DYNAMIC=y, I wrote the debug code below to validate the
reference counts of the nodes I was interested in.
During the first call of check_refcnts(), it gathers all reference
counts. During a subsequent call, it verifies that they are still the
same.
Surprisingly, lots of reference counts were wrong, and kept incrementing
every time check_refcnts() was called.
I was just wondering whether it would be useful to have a reference
count test in OF_UNITTEST, but now I see the "select OF_DYNAMIC" will go
away?
Feel free to (ab)use the code below and derive a unittest from it...
static struct to_check {
const char *path;
int refcnt;
} to_check[] = {
{ "/" },
{ "/cpus/cpu@0" },
{ "/cpus/cpu@1" },
/* ... other paths I was interested in ... */
};
static void check_refcnts(void)
{
static bool called;
unsigned int i;
const char *path;
struct device_node *np;
int refcnt;
unsigned int errors = 0;
pr_info("----- %s reference counts -----\n",
called ? "Checking" : "Saving");
for (i = 0; i < ARRAY_SIZE(to_check); i++) {
path = to_check[i].path;
np = of_find_node_by_path(path);
if (!np)
continue;
refcnt = atomic_read(&np->kobj.kref.refcount);
if (!called) {
pr_info("%s %d\n", path, refcnt);
to_check[i].refcnt = refcnt;
} else if (refcnt == to_check[i].refcnt) {
pr_info("%s %d (OK)\n", path, refcnt);
} else {
pr_info("%s %d (should be %d)\n", path, refcnt,
to_check[i].refcnt);
errors++;
}
of_node_put(np);
}
if (called)
pr_info("----- Checking done (%u errors) -----\n", errors);
else
pr_info("----- Saving done -----\n");
called = true;
}
---
drivers/of/base.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 36536b6a8834acd2..f3e346e19c69d1f2 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -791,8 +791,10 @@ 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 *parent = np;
path++; /* Increment past '/' delimiter */
- np = __of_find_node_by_path(np, path);
+ np = __of_find_node_by_path(parent, path);
+ of_node_put(parent);
path = strchrnul(path, '/');
}
raw_spin_unlock_irqrestore(&devtree_lock, flags);
--
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next reply other threads:[~2015-01-14 15:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-14 15:45 Geert Uytterhoeven [this message]
[not found] ` <1421250356-16690-1-git-send-email-geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
2015-01-22 16:14 ` [PATCH] of: Add missing of_node_put() in of_find_node_by_path() Grant Likely
2015-01-22 16:18 ` Grant Likely
[not found] ` <CACxGe6sDFQQfiN0+d5HV7JPE-0bosqdaKqrS-7o-obCy1NP_qg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-01-22 20:35 ` Geert Uytterhoeven
[not found] ` <20150122161446.101EBC40A80-WNowdnHR2B42iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2015-01-22 20:35 ` Geert Uytterhoeven
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=1421250356-16690-1-git-send-email-geert+renesas@glider.be \
--to=geert+renesas-gxvu3+zwzmszqb+pc5nmwq@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=gaurav.minocha.os-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
/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;
as well as URLs for NNTP newsgroup(s).