[Crosstoolchain-logs] [device-tree-compiler] 70/357: libfdt: Clean up error codes

Hector Oron zumbi at moszumanska.debian.org
Thu Dec 8 17:05:51 UTC 2016


This is an automated email from the git hooks/post-receive script.

zumbi pushed a commit to branch upstream/1.3.x
in repository device-tree-compiler.

commit 3aea82850164d49678a684bda11203da8d7e25ce
Author: David Gibson <dgibson at sneetch.(none)>
Date:   Fri Dec 15 15:12:52 2006 +1100

    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 at gibson.dropbear.id.au>
---
 fdt_ro.c          |  3 ---
 fdt_wip.c         |  2 +-
 libfdt.h          | 37 ++++++++++++++++++-------------------
 tests/testutils.c | 34 +++++++++++++++++++---------------
 4 files changed, 38 insertions(+), 38 deletions(-)

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
-
-#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))
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_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)
 {
 	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,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/crosstoolchain/device-tree-compiler.git



More information about the Crosstoolchain-logs mailing list