libfdt: More consistent handling of returned error codes.
At present, libfdt functions returning a structure offset return a
zero-or-positive offset on success, and return a negative error code
on failure. Functions which only return an error code return a
positive version of the error code, or 0 on success.
This patch improves consistency by always returning negative error
codes on failure, for both types of function. With this change, we do
away with the special fdt_offset_error() macro for checking whether a
returned offset value is an error and extracting the encoded error
value within. Instead an explicit (ret_value < 0) is now the
preferred way of checking return values for both offset-returning and
error-code-returning functions.
The fdt_strerror() function in the test code is updated
correspondingly to make more sense with the new conventions.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
diff --git a/fdt.c b/fdt.c
index bc3ec22..45568b1 100644
--- a/fdt.c
+++ b/fdt.c
@@ -28,15 +28,15 @@
if (fdt_magic(fdt) == FDT_MAGIC) {
/* Complete tree */
if (fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION)
- return FDT_ERR_BADVERSION;
+ return -FDT_ERR_BADVERSION;
if (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION)
- return FDT_ERR_BADVERSION;
+ return -FDT_ERR_BADVERSION;
} else if (fdt_magic(fdt) == SW_MAGIC) {
/* Unfinished sequential-write blob */
if (fdt_size_dt_struct(fdt) == 0)
- return FDT_ERR_BADSTATE;
+ return -FDT_ERR_BADSTATE;
} else {
- return FDT_ERR_BADMAGIC;
+ return -FDT_ERR_BADMAGIC;
}
return 0;
@@ -117,8 +117,8 @@
return err;
if (fdt_totalsize(fdt) > bufsize)
- return FDT_ERR_NOSPACE;
+ return -FDT_ERR_NOSPACE;
memmove(buf, fdt, fdt_totalsize(fdt));
- return FDT_ERR_OK;
+ return 0;
}