Skip to contentSkip to conversation

Bugfix for CHECK_HAVE_WARN_PHANDLE()

dtc Applied David Gibson 2 participants 2 messages Jan 31, 2007

lore
Share & tools
lore
#0 lore raw

At present, the tree checking code in dtc will die with an assertion failure if given a tree which has the invalid value 0 or -1 in a property which should contain a phandle. This patch fixes the check to die more gracefully with an error message indicating the invalid phandle value.

livetree.c +8 -3
Index: dtc/livetree.c
===================================================================
@@ -427,9 +427,14 @@ static int check_structure(struct node *
 		struct node *ref; \
 		CHECK_HAVE_WARN_ONECELL((xnode), (propname)); \
 		if (prop) {\
-			ref = get_node_by_phandle((root), propval_cell(prop)); \
-			if (! ref) \
-				DO_ERR("\"%s\" property in %s refers to non-existant phandle %x\n", (propname), (xnode)->fullpath, propval_cell(prop)); \
+			cell_t phandle = propval_cell(prop); \
+			if ((phandle == 0) || (phandle == -1)) { \
+				DO_ERR("\"%s\" property in %s contains an invalid phandle %x\n", (propname), (xnode)->fullpath, phandle); \
+			} else { \
+				ref = get_node_by_phandle((root), propval_cell(prop)); \
+				if (! ref) \
+					DO_ERR("\"%s\" property in %s refers to non-existant phandle %x\n", (propname), (xnode)->fullpath, propval_cell(prop)); \
+			} \
 		} \
 	} while (0)
 
Signature · 4 lines
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
Applied
#1 lore raw

So, like, the other day David Gibson mumbled:

Quoted 7 lines

At present, the tree checking code in dtc will die with an assertion failure if given a tree which has the invalid value 0 or -1 in a property which should contain a phandle. This patch fixes the check to die more gracefully with an error message indicating the invalid phandle value.

Applied.

Thanks,
jdl