Browse Source

libfdt: Clean up error codes

First, this patch removes several underused error codes:
FDT_ERR_BADPOINTER and FDT_ERR_BADHEADER were not used at all and are
simply removed.  FDT_ERR_SIZE_MISMATCH was very similar in spirit to
FDT_ERR_NOSPACE, and used only in circumstances where there can be no
confusion between the two, so is removed and folded into
FDT_ERR_NOSPACE.  FDT_ERR_INTERAL was used on only one place, on a
"can't happen" check.  It seems of little value so the check and error
code are removed also.

Second, the error codes have been re-numbered and grouped roughly by
severity.  That is codes which can reasonably occur in normal
operation separated from those which indicate bad parameters (and
therefore a bug in the caller) or a bad or corrupted device tree blob.

Third the test function fdt_strerror() is cleaned up a little based on
these changes.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
main
David Gibson 18 years ago
parent
commit
3aea828501
  1. 3
      fdt_ro.c
  2. 2
      fdt_wip.c
  3. 37
      libfdt.h
  4. 32
      tests/testutils.c

3
fdt_ro.c

@ -161,9 +161,6 @@ struct fdt_property *fdt_get_property(const void *fdt, @@ -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) {

2
fdt_wip.c

@ -34,7 +34,7 @@ int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name, @@ -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;

37
libfdt.h

@ -25,25 +25,24 @@ @@ -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

#define FDT_ERR_MAX 14
/* Error codes: informative error codes */
#define FDT_ERR_NOTFOUND 1
#define FDT_ERR_EXISTS 2
#define FDT_ERR_NOSPACE 3

/* 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))

32
tests/testutils.c

@ -77,20 +77,18 @@ struct errtabent { @@ -77,20 +77,18 @@ struct errtabent {
[(val)] = { .str = #val, }

static struct errtabent errtable[] = {
ERRTABENT(FDT_ERR_OK),
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_EXISTS),
ERRTABENT(FDT_ERR_NOSPACE),

ERRTABENT(FDT_ERR_BADOFFSET),
ERRTABENT(FDT_ERR_BADPATH),
ERRTABENT(FDT_ERR_BADSTATE),
ERRTABENT(FDT_ERR_SIZE_MISMATCH),
ERRTABENT(FDT_ERR_INTERNAL),

ERRTABENT(FDT_ERR_TRUNCATED),
ERRTABENT(FDT_ERR_BADMAGIC),
ERRTABENT(FDT_ERR_BADVERSION),
ERRTABENT(FDT_ERR_BADSTRUCTURE),
};

#define ERRTABSIZE (sizeof(errtable) / sizeof(errtable[0]))
@ -99,10 +97,16 @@ const char *fdt_strerror(int errval) @@ -99,10 +97,16 @@ const char *fdt_strerror(int errval)
{
if (errval > 0)
return "<valid offset>";
else if (errval < -ERRTABSIZE)
else if (errval == 0)
return "<no error>";
else if (errval > -ERRTABSIZE) {
const char *s = errtable[-errval].str;

if (s)
return s;
}

return "<unknown error>";
else
return errtable[-errval].str;
}

void check_property(void *fdt, int nodeoffset, const char *name,

Loading…
Cancel
Save