From: Gavin Shan <gwshan-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
To: Gavin Shan <gwshan-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
andrew.donnellan-8fk3Idey6ehBDgjK7y7TUQ@public.gmane.org,
Rhyland Klein <rklein-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
Subject: Re: [PATCH] drivers/of: Fix depth for sub-tree blob in unflatten_dt_nodes()
Date: Thu, 9 Jun 2016 14:48:59 +1000 [thread overview]
Message-ID: <20160609044859.GA2037@gwshan> (raw)
In-Reply-To: <1465368654-24170-1-git-send-email-gwshan-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
On Wed, Jun 08, 2016 at 04:50:54PM +1000, Gavin Shan wrote:
>The function is unflattening device sub-tree blob if @dad passed to
>the function is valid. Currently, this functionality is used by PPC
>PowerNV PCI hotplug driver only. There are possibly multiple nodes
>in the first level of depth, fdt_next_node() bails immediately when
>@depth becomes negative before the second device node can be probed
>successfully. It leads to the device nodes except the first one won't
>be unflattened successfully.
>
>This fixes the issue by setting the initial depth (@inital_depth) to
>1 when this function is called to unflatten device sub-tree blob. No
>logic changes when this function is used to unflatten non-sub-tree
>blob.
>
>Cc: Rhyland Klein <rklein-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
>Fixes: 78c44d910 ("drivers/of: Fix depth when unflattening devicetree")
>Signed-off-by: Gavin Shan <gwshan-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
>---
> drivers/of/fdt.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
>index 14f2f8c..9d70316 100644
>--- a/drivers/of/fdt.c
>+++ b/drivers/of/fdt.c
>@@ -395,7 +395,7 @@ static int unflatten_dt_nodes(const void *blob,
> struct device_node **nodepp)
> {
> struct device_node *root;
>- int offset = 0, depth = 0;
>+ int offset = 0, depth = 0, initial_depth = 0;
> #define FDT_MAX_DEPTH 64
> unsigned int fpsizes[FDT_MAX_DEPTH];
> struct device_node *nps[FDT_MAX_DEPTH];
>@@ -408,8 +408,19 @@ static int unflatten_dt_nodes(const void *blob,
> root = dad;
> fpsizes[depth] = dad ? strlen(of_node_full_name(dad)) : 0;
> nps[depth] = dad;
>+
>+ /*
>+ * We're unflattening device sub-tree if @dad is valid. There are
>+ * possibly multiple nodes in the first level of depth. We need
>+ * set @depth to 1 to make fdt_next_node() happy as it bails
>+ * immediately when negative @depth is found. Otherwise, the device
>+ * nodes except the first one won't be unflattened successfully.
>+ */
>+ if (dad)
>+ depth = initial_depth = 1;
>+
The change to @depth should happen before @fpsizes[depth] and @nps[depth]
are initialized. Otherwise, the parent device node and its full name length
are lost. It's why this didn't work for Andrew's hotplug case, but it did
work for me (with luck). I will post v2 to correct it.
Thanks,
Gavin
> for (offset = 0;
>- offset >= 0 && depth >= 0;
>+ offset >= 0 && depth >= initial_depth;
> offset = fdt_next_node(blob, offset, &depth)) {
> if (WARN_ON_ONCE(depth >= FDT_MAX_DEPTH))
> continue;
>--
>2.1.0
>
--
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
prev parent reply other threads:[~2016-06-09 4:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-08 6:50 [PATCH] drivers/of: Fix depth for sub-tree blob in unflatten_dt_nodes() Gavin Shan
[not found] ` <1465368654-24170-1-git-send-email-gwshan-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-06-08 8:02 ` Andrew Donnellan
[not found] ` <5757D129.4070505-8fk3Idey6ehBDgjK7y7TUQ@public.gmane.org>
2016-06-08 8:04 ` Andrew Donnellan
[not found] ` <5757D191.3040805-8fk3Idey6ehBDgjK7y7TUQ@public.gmane.org>
2016-06-08 10:18 ` Gavin Shan
2016-06-08 15:53 ` Rhyland Klein
[not found] ` <828431f1-5b74-8aef-c229-7b7469e685ba-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-06-09 4:51 ` Gavin Shan
2016-06-08 16:46 ` Rob Herring
[not found] ` <CAL_Jsq+D86LbGTiDbokSGNMownTMDteji_NmJNxz4AqTYMpJhw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-06-09 0:40 ` Gavin Shan
2016-06-09 4:48 ` Gavin Shan [this message]
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=20160609044859.GA2037@gwshan \
--to=gwshan-23vcf4htsmix0ybbhkvfkdbpr1lh4cv8@public.gmane.org \
--cc=andrew.donnellan-8fk3Idey6ehBDgjK7y7TUQ@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=rklein-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
--cc=robherring2-Re5JQEeQqe8AvxtiuMwx3w@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).