linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Jon Loeliger <jdl@freescale.com>
Cc: linuxppc-dev@ozlabs.org
Subject: dtc: Assume properties preced subnodes in the flattened tree
Date: Tue, 4 Sep 2007 10:43:03 +1000	[thread overview]
Message-ID: <20070904004303.GC20549@localhost.localdomain> (raw)

With kernel commit eff2ebd207af9f501af0ef667a7d14befcb36c1b, we
clarified that in the flattened tree format, a particular nodes
properties are required to precede its subdnodes.

At present however, both dtc and libfdt will process trees which don't
meet this condition.  This patch simplifies the code for
fdt_get_property() based on assuming that constraint.  dtc continues
to be able to handle such an invalid tree - on the grounds that it's
useful for dtc to be able to correct such a broken tree - but this
patch adds a warning when this condition is not met while reading a
flattened tree.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>

Index: dtc/libfdt/fdt_ro.c
===================================================================
--- dtc.orig/libfdt/fdt_ro.c	2007-08-31 15:59:38.000000000 +1000
+++ dtc/libfdt/fdt_ro.c	2007-08-31 16:23:09.000000000 +1000
@@ -197,7 +197,6 @@
 					    int nodeoffset,
 					    const char *name, int *lenp)
 {
-	int level = 0;
 	uint32_t tag;
 	const struct fdt_property *prop;
 	int namestroff;
@@ -225,17 +224,11 @@
 			goto fail;
 
 		case FDT_BEGIN_NODE:
-			level++;
-			break;
-
 		case FDT_END_NODE:
-			level--;
+		case FDT_NOP:
 			break;
 
 		case FDT_PROP:
-			if (level != 0)
-				continue;
-
 			err = -FDT_ERR_BADSTRUCTURE;
 			prop = fdt_offset_ptr_typed(fdt, offset, prop);
 			if (! prop)
@@ -256,14 +249,11 @@
 			}
 			break;
 
-		case FDT_NOP:
-			break;
-
 		default:
 			err = -FDT_ERR_BADSTRUCTURE;
 			goto fail;
 		}
-	} while (level >= 0);
+	} while ((tag != FDT_BEGIN_NODE) && (tag != FDT_END_NODE));
 
 	err = -FDT_ERR_NOTFOUND;
  fail:
Index: dtc/flattree.c
===================================================================
--- dtc.orig/flattree.c	2007-08-31 16:34:34.000000000 +1000
+++ dtc/flattree.c	2007-08-31 16:39:11.000000000 +1000
@@ -779,6 +779,9 @@
 		val = flat_read_word(dtbuf);
 		switch (val) {
 		case OF_DT_PROP:
+			if (node->children)
+				fprintf(stderr, "Warning: Flat tree input has "
+					"subnodes preceding a property.\n");
 			prop = flat_read_property(dtbuf, strbuf, flags);
 			add_property(node, prop);
 			break;

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

             reply	other threads:[~2007-09-04  0:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-04  0:43 David Gibson [this message]
2007-09-07 13:41 ` dtc: Assume properties preced subnodes in the flattened tree Jon Loeliger

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=20070904004303.GC20549@localhost.localdomain \
    --to=david@gibson.dropbear.id.au \
    --cc=jdl@freescale.com \
    --cc=linuxppc-dev@ozlabs.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).