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>
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 @@
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 @@
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 @@
[(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 @@
{
if (errval > 0)
return "<valid offset>";
- else if (errval < -ERRTABSIZE)
- return "<unknown error>";
- else
- return errtable[-errval].str;
+ else if (errval == 0)
+ return "<no error>";
+ else if (errval > -ERRTABSIZE) {
+ const char *s = errtable[-errval].str;
+
+ if (s)
+ return s;
+ }
+
+ return "<unknown error>";
}
void check_property(void *fdt, int nodeoffset, const char *name,