libfdt: Fix fdt_strerror() bugs

This fixes several small bugs related to fdt_strerror().
	- an entry is added to the error table for FDT_ERR_BADLAYOUT.
	- Incorrect usage of fdt_strerror() in check_property() and
check_getprop() is corrected (they were passing a positive error code,
when fdt_strerror() expects a negative code).
	- Add code to properly retreive an error code from
fdt_get_property() in check_property().  With that a check that the
length returned by fdt_get_property() matches that stored in the
retreived property.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2007-02-23 14:40:10 +11:00
parent 5b344f9c5a
commit 5434fcc7e0
2 changed files with 11 additions and 4 deletions

View File

@ -43,13 +43,14 @@ static struct errtabent errtable[] = {
ERRTABENT(FDT_ERR_BADMAGIC), ERRTABENT(FDT_ERR_BADMAGIC),
ERRTABENT(FDT_ERR_BADVERSION), ERRTABENT(FDT_ERR_BADVERSION),
ERRTABENT(FDT_ERR_BADSTRUCTURE), ERRTABENT(FDT_ERR_BADSTRUCTURE),
ERRTABENT(FDT_ERR_BADLAYOUT),
}; };
#define ERRTABSIZE (sizeof(errtable) / sizeof(errtable[0])) #define ERRTABSIZE (sizeof(errtable) / sizeof(errtable[0]))
const char *fdt_strerror(int errval) const char *fdt_strerror(int errval)
{ {
if (errval > 0) if (errval > 0)
return "<valid offset>"; return "<valid offset/length>";
else if (errval == 0) else if (errval == 0)
return "<no error>"; return "<no error>";
else if (errval > -ERRTABSIZE) { else if (errval > -ERRTABSIZE) {

View File

@ -72,14 +72,16 @@ void check_property(void *fdt, int nodeoffset, const char *name,
int len, const void *val) int len, const void *val)
{ {
const struct fdt_property *prop; const struct fdt_property *prop;
int retlen;
uint32_t tag, nameoff, proplen; uint32_t tag, nameoff, proplen;
const char *propname; const char *propname;
verbose_printf("Checking property \"%s\"...", name); verbose_printf("Checking property \"%s\"...", name);
prop = fdt_get_property(fdt, nodeoffset, name, NULL); prop = fdt_get_property(fdt, nodeoffset, name, &retlen);
verbose_printf("pointer %p\n", prop); verbose_printf("pointer %p\n", prop);
if (! prop) if (! prop)
FAIL("NULL retreiving \"%s\" pointer", name); FAIL("Error retreiving \"%s\" pointer: %s", name,
fdt_strerror(retlen));
tag = fdt32_to_cpu(prop->tag); tag = fdt32_to_cpu(prop->tag);
nameoff = fdt32_to_cpu(prop->nameoff); nameoff = fdt32_to_cpu(prop->nameoff);
@ -92,6 +94,10 @@ void check_property(void *fdt, int nodeoffset, const char *name,
if (!propname || !streq(propname, name)) if (!propname || !streq(propname, name))
FAIL("Property name mismatch \"%s\" instead of \"%s\"", FAIL("Property name mismatch \"%s\" instead of \"%s\"",
propname, name); propname, name);
if (proplen != retlen)
FAIL("Length retrieved for \"%s\" by fdt_get_property()"
" differs from stored length (%d != %d)",
name, retlen, proplen);
if (proplen != len) if (proplen != len)
FAIL("Size mismatch on property \"%s\": %d insead of %d", FAIL("Size mismatch on property \"%s\": %d insead of %d",
name, proplen, len); name, proplen, len);
@ -108,7 +114,7 @@ void *check_getprop(void *fdt, int nodeoffset, const char *name,
propval = fdt_getprop(fdt, nodeoffset, name, &proplen); propval = fdt_getprop(fdt, nodeoffset, name, &proplen);
if (! propval) if (! propval)
FAIL("fdt_getprop(\"%s\"): %s", name, fdt_strerror(-proplen)); FAIL("fdt_getprop(\"%s\"): %s", name, fdt_strerror(proplen));
if (proplen != len) if (proplen != len)
FAIL("Size mismatch on property \"%s\": %d insead of %d", FAIL("Size mismatch on property \"%s\": %d insead of %d",