diff --git a/fdt_ro.c b/fdt_ro.c index 7db7f12..9112c6a 100644 --- a/fdt_ro.c +++ b/fdt_ro.c @@ -161,9 +161,6 @@ struct fdt_property *fdt_get_property(const void *fdt, do { offset = nextoffset; - err = -FDT_ERR_INTERNAL; - if (offset % FDT_TAGSIZE) - goto fail; tag = _fdt_next_tag(fdt, offset, &nextoffset); switch (tag) { diff --git a/fdt_wip.c b/fdt_wip.c index 943fb68..0db7d25 100644 --- a/fdt_wip.c +++ b/fdt_wip.c @@ -34,7 +34,7 @@ int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name, return proplen; if (proplen != len) - return -FDT_ERR_SIZE_MISMATCH; + return -FDT_ERR_NOSPACE; memcpy(propval, val, len); return 0; diff --git a/libfdt.h b/libfdt.h index cf6ad19..8ba2daf 100644 --- a/libfdt.h +++ b/libfdt.h @@ -25,25 +25,24 @@ #define FDT_FIRST_SUPPORTED_VERSION 0x10 #define FDT_LAST_SUPPORTED_VERSION 0x11 -/* Errors */ -#define FDT_ERR_OK 0 -#define FDT_ERR_BADMAGIC 1 -#define FDT_ERR_BADVERSION 2 -#define FDT_ERR_BADPOINTER 3 -#define FDT_ERR_BADHEADER 4 -#define FDT_ERR_BADSTRUCTURE 5 -#define FDT_ERR_BADOFFSET 6 -#define FDT_ERR_NOTFOUND 7 -#define FDT_ERR_BADPATH 8 -#define FDT_ERR_TRUNCATED 9 -#define FDT_ERR_NOSPACE 10 -#define FDT_ERR_BADSTATE 11 -#define FDT_ERR_SIZE_MISMATCH 12 -#define FDT_ERR_INTERNAL 13 -#define FDT_ERR_BADLAYOUT 14 -#define FDT_ERR_EXISTS 15 +/* Error codes: informative error codes */ +#define FDT_ERR_NOTFOUND 1 +#define FDT_ERR_EXISTS 2 +#define FDT_ERR_NOSPACE 3 -#define FDT_ERR_MAX 14 +/* Error codes: codes for bad parameters */ +#define FDT_ERR_BADOFFSET 4 +#define FDT_ERR_BADPATH 5 +#define FDT_ERR_BADSTATE 6 + +/* Error codes: codes for bad device tree blobs */ +#define FDT_ERR_TRUNCATED 7 +#define FDT_ERR_BADMAGIC 8 +#define FDT_ERR_BADVERSION 9 +#define FDT_ERR_BADSTRUCTURE 10 +#define FDT_ERR_BADLAYOUT 11 + +#define FDT_ERR_MAX 11 #define fdt_get_header(fdt, field) \ (fdt32_to_cpu(((struct fdt_header *)(fdt))->field)) diff --git a/tests/testutils.c b/tests/testutils.c index aafcbb0..f411067 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -77,20 +77,18 @@ struct errtabent { [(val)] = { .str = #val, } static struct errtabent errtable[] = { - ERRTABENT(FDT_ERR_OK), + ERRTABENT(FDT_ERR_NOTFOUND), + ERRTABENT(FDT_ERR_EXISTS), + ERRTABENT(FDT_ERR_NOSPACE), + + ERRTABENT(FDT_ERR_BADOFFSET), + ERRTABENT(FDT_ERR_BADPATH), + ERRTABENT(FDT_ERR_BADSTATE), + + ERRTABENT(FDT_ERR_TRUNCATED), ERRTABENT(FDT_ERR_BADMAGIC), ERRTABENT(FDT_ERR_BADVERSION), - ERRTABENT(FDT_ERR_BADPOINTER), - ERRTABENT(FDT_ERR_BADHEADER), ERRTABENT(FDT_ERR_BADSTRUCTURE), - ERRTABENT(FDT_ERR_BADOFFSET), - ERRTABENT(FDT_ERR_NOTFOUND), - ERRTABENT(FDT_ERR_BADPATH), - ERRTABENT(FDT_ERR_TRUNCATED), - ERRTABENT(FDT_ERR_NOSPACE), - ERRTABENT(FDT_ERR_BADSTATE), - ERRTABENT(FDT_ERR_SIZE_MISMATCH), - ERRTABENT(FDT_ERR_INTERNAL), }; #define ERRTABSIZE (sizeof(errtable) / sizeof(errtable[0])) @@ -99,10 +97,16 @@ const char *fdt_strerror(int errval) { if (errval > 0) return ""; - else if (errval < -ERRTABSIZE) - return ""; - else - return errtable[-errval].str; + else if (errval == 0) + return ""; + else if (errval > -ERRTABSIZE) { + const char *s = errtable[-errval].str; + + if (s) + return s; + } + + return ""; } void check_property(void *fdt, int nodeoffset, const char *name,