devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rob Herring <robh@kernel.org>
To: devicetree@vger.kernel.org, Michael Ellerman <mpe@ellerman.id.au>,
	linuxppc-dev@lists.ozlabs.org
Cc: linux-kernel@vger.kernel.org,
	Frank Rowand <frowand.list@gmail.com>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	David Laight <David.Laight@aculab.com>
Subject: [PATCH v2 5/5] of/fdt: only store the device node basename in full_name
Date: Mon, 21 Aug 2017 10:16:51 -0500	[thread overview]
Message-ID: <20170821151651.25096-6-robh@kernel.org> (raw)
In-Reply-To: <20170821151651.25096-1-robh@kernel.org>

With dependencies on a statically allocated full path name converted to
use %pOF format specifier, we can store just the basename of node, and
the unflattening of the FDT can be simplified.

This commit will affect the remaining users of full_name. After
analyzing these users, the remaining cases should only change some print
messages. The main users of full_name are providing a name for struct
resource. The resource names shouldn't be important other than providing
/proc/iomem names.

We no longer distinguish between pre and post 0x10 dtb formats as either
a full path or basename will work. However, less than 0x10 formats have
been broken since the conversion to use libfdt (and no one has cared).
The conversion of the unflattening code to be non-recursive also broke
pre 0x10 formats as the populate_node function would return 0 in that
case.

Signed-off-by: Rob Herring <robh@kernel.org>
---
v2:
- rebase to linux-next

 drivers/of/fdt.c | 69 +++++++++-----------------------------------------------
 1 file changed, 11 insertions(+), 58 deletions(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index ce30c9a588a4..27c535af0be8 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -266,74 +266,32 @@ static void populate_properties(const void *blob,
 		*pprev = NULL;
 }
 
-static unsigned int populate_node(const void *blob,
-				  int offset,
-				  void **mem,
-				  struct device_node *dad,
-				  unsigned int fpsize,
-				  struct device_node **pnp,
-				  bool dryrun)
+static bool populate_node(const void *blob,
+			  int offset,
+			  void **mem,
+			  struct device_node *dad,
+			  struct device_node **pnp,
+			  bool dryrun)
 {
 	struct device_node *np;
 	const char *pathp;
 	unsigned int l, allocl;
-	int new_format = 0;
 
 	pathp = fdt_get_name(blob, offset, &l);
 	if (!pathp) {
 		*pnp = NULL;
-		return 0;
+		return false;
 	}
 
 	allocl = ++l;
 
-	/* version 0x10 has a more compact unit name here instead of the full
-	 * path. we accumulate the full path size using "fpsize", we'll rebuild
-	 * it later. We detect this because the first character of the name is
-	 * not '/'.
-	 */
-	if ((*pathp) != '/') {
-		new_format = 1;
-		if (fpsize == 0) {
-			/* root node: special case. fpsize accounts for path
-			 * plus terminating zero. root node only has '/', so
-			 * fpsize should be 2, but we want to avoid the first
-			 * level nodes to have two '/' so we use fpsize 1 here
-			 */
-			fpsize = 1;
-			allocl = 2;
-			l = 1;
-			pathp = "";
-		} else {
-			/* account for '/' and path size minus terminal 0
-			 * already in 'l'
-			 */
-			fpsize += l;
-			allocl = fpsize;
-		}
-	}
-
 	np = unflatten_dt_alloc(mem, sizeof(struct device_node) + allocl,
 				__alignof__(struct device_node));
 	if (!dryrun) {
 		char *fn;
 		of_node_init(np);
 		np->full_name = fn = ((char *)np) + sizeof(*np);
-		if (new_format) {
-			/* rebuild full path for new format */
-			if (dad && dad->parent) {
-				strcpy(fn, dad->full_name);
-#ifdef DEBUG
-				if ((strlen(fn) + l + 1) != allocl) {
-					pr_debug("%s: p: %d, l: %d, a: %d\n",
-						pathp, (int)strlen(fn),
-						l, allocl);
-				}
-#endif
-				fn += strlen(fn);
-			}
-			*(fn++) = '/';
-		}
+
 		memcpy(fn, pathp, l);
 
 		if (dad != NULL) {
@@ -355,7 +313,7 @@ static unsigned int populate_node(const void *blob,
 	}
 
 	*pnp = np;
-	return fpsize;
+	return true;
 }
 
 static void reverse_nodes(struct device_node *parent)
@@ -399,7 +357,6 @@ static int unflatten_dt_nodes(const void *blob,
 	struct device_node *root;
 	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];
 	void *base = mem;
 	bool dryrun = !base;
@@ -418,7 +375,6 @@ static int unflatten_dt_nodes(const void *blob,
 		depth = initial_depth = 1;
 
 	root = dad;
-	fpsizes[depth] = dad ? strlen(of_node_full_name(dad)) : 0;
 	nps[depth] = dad;
 
 	for (offset = 0;
@@ -427,11 +383,8 @@ static int unflatten_dt_nodes(const void *blob,
 		if (WARN_ON_ONCE(depth >= FDT_MAX_DEPTH))
 			continue;
 
-		fpsizes[depth+1] = populate_node(blob, offset, &mem,
-						 nps[depth],
-						 fpsizes[depth],
-						 &nps[depth+1], dryrun);
-		if (!fpsizes[depth+1])
+		if (!populate_node(blob, offset, &mem, nps[depth],
+				   &nps[depth+1], dryrun))
 			return mem - base;
 
 		if (!dryrun && nodepp && !*nodepp)
-- 
2.11.0

  parent reply	other threads:[~2017-08-21 15:16 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-21 15:16 [PATCH v2 0/5] Removing full paths from DT full_name Rob Herring
2017-08-21 15:16 ` [PATCH v2 1/5] powerpc: Convert to using %pOF instead of full_name Rob Herring
     [not found]   ` <20170821151651.25096-2-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2017-08-24 12:37     ` [v2,1/5] " Michael Ellerman
2017-08-21 15:16 ` [PATCH v2 2/5] powerpc: pseries: vio: match parent nodes with of_find_node_by_path Rob Herring
     [not found]   ` <20170821151651.25096-3-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2017-08-22  5:12     ` Michael Ellerman
     [not found]       ` <87fuckb2z2.fsf-W0DJWXSxmBNbyGPkN3NxC2scP1bn1w/D@public.gmane.org>
2017-08-24 18:08         ` Rob Herring
     [not found]           ` <CAL_Jsq+sUgVcfNkpAHG7TmkO03+-0_GuZVW2tpxq6Xm2qDzUog-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-08-25  0:10             ` Michael Ellerman
2017-08-21 15:16 ` [PATCH v2 3/5] powerpc: pseries: remove dlpar_attach_node dependency on full path Rob Herring
2017-08-24 12:37   ` [v2, " Michael Ellerman
2017-08-21 15:16 ` [PATCH v2 4/5] powerpc: pseries: only store the device node basename in full_name Rob Herring
2017-10-03  9:26   ` Michael Ellerman
2017-10-03 18:44     ` Rob Herring
     [not found]       ` <CAL_JsqLiTFM=THW0+WXXUY3S-T4QamV8vS5pWZBPm0oOybQLgg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-10-04 12:37         ` Michael Ellerman
2017-08-21 15:16 ` Rob Herring [this message]
     [not found]   ` <20170821151651.25096-6-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2017-10-17 21:32     ` [PATCH v2 5/5] of/fdt: " Alan Tull
2017-10-17 21:46       ` Rob Herring
     [not found]         ` <CABGGisxU2OPZz-rrWYZYgCQ0iGM9w5vL9Ob9BTHALFN8JyxeJQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-10-17 23:51           ` Frank Rowand
     [not found]             ` <59E69786.2030406-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-10-18 15:12               ` Alan Tull
2017-10-18 15:44                 ` Rob Herring
2017-10-18 15:53                   ` Pantelis Antoniou
2017-10-18 18:30                     ` Rob Herring
2017-10-18 21:46                       ` Frank Rowand
     [not found]                         ` <59E7CBAF.9080501-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-10-19  8:41                           ` Pantelis Antoniou
     [not found]                       ` <CAL_JsqKJ74y3qHVqbRph5C8=0Ggb+n=JT3TZybu2+mENyZ1VZA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-10-19  8:51                         ` Pantelis Antoniou
2017-10-19 20:06                           ` Moritz Fischer
2017-10-19 21:46                             ` Frank Rowand
     [not found]                               ` <59E91D4D.8000200-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-10-20  8:06                                 ` Pantelis Antoniou
2017-10-20 14:59                                   ` Rob Herring
2017-10-18 18:39                     ` Alan Tull
     [not found]                       ` <CANk1AXS1f_z4jWmBhioccBdNgiA6eQPK4YAG=zLH0EUST9XF8g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-10-18 21:40                         ` Frank Rowand
2017-11-28 13:13     ` Geert Uytterhoeven
     [not found]       ` <CAMuHMdU-qQWmDi=V-G=r=poQf-F9hqL2SmoKi+SZyUwEj5vBGw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-11-28 13:26         ` Rob Herring

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=20170821151651.25096-6-robh@kernel.org \
    --to=robh@kernel.org \
    --cc=David.Laight@aculab.com \
    --cc=benh@kernel.crashing.org \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.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).