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 <[email protected]>
diff --git a/tests/del_node.c b/tests/del_node.c
index 87be4b5..56f7cf5 100644
--- a/tests/del_node.c
+++ b/tests/del_node.c
@@ -42,19 +42,21 @@
oldsize = fdt_totalsize(fdt);
subnode1_offset = fdt_path_offset(fdt, "/subnode1");
- if ((err = fdt_offset_error(subnode1_offset)))
- FAIL("Couldn't find \"/subnode1\": %s", fdt_strerror(err));
+ if (subnode1_offset < 0)
+ FAIL("Couldn't find \"/subnode1\": %s",
+ fdt_strerror(subnode1_offset));
check_getprop_typed(fdt, subnode1_offset, "prop-int", TEST_VALUE_1);
subnode2_offset = fdt_path_offset(fdt, "/subnode2");
- if ((err = fdt_offset_error(subnode2_offset)))
- FAIL("Couldn't find \"/subnode2\": %s", fdt_strerror(err));
+ if (subnode2_offset < 0)
+ FAIL("Couldn't find \"/subnode2\": %s",
+ fdt_strerror(subnode2_offset));
check_getprop_typed(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
subsubnode2_offset = fdt_path_offset(fdt, "/subnode2/subsubnode");
- if ((err = fdt_offset_error(subsubnode2_offset)))
+ if (subsubnode2_offset < 0)
FAIL("Couldn't find \"/subnode2/subsubnode\": %s",
- fdt_strerror(err));
+ fdt_strerror(subsubnode2_offset));
check_getprop_typed(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
err = fdt_del_node(fdt, subnode1_offset);
@@ -62,19 +64,21 @@
FAIL("fdt_del_node(subnode1): %s", fdt_strerror(err));
subnode1_offset = fdt_path_offset(fdt, "/subnode1");
- if ((err = fdt_offset_error(subnode1_offset)) != FDT_ERR_NOTFOUND)
+ if (subnode1_offset != -FDT_ERR_NOTFOUND)
FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
- fdt_strerror(err), fdt_strerror(FDT_ERR_NOTFOUND));
+ fdt_strerror(subnode1_offset),
+ fdt_strerror(-FDT_ERR_NOTFOUND));
subnode2_offset = fdt_path_offset(fdt, "/subnode2");
- if ((err = fdt_offset_error(subnode2_offset)))
- FAIL("Couldn't find \"/subnode2\": %s", fdt_strerror(err));
+ if (subnode2_offset < 0)
+ FAIL("Couldn't find \"/subnode2\": %s",
+ fdt_strerror(subnode2_offset));
check_getprop_typed(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
subsubnode2_offset = fdt_path_offset(fdt, "/subnode2/subsubnode");
- if ((err = fdt_offset_error(subsubnode2_offset)))
+ if (subsubnode2_offset < 0)
FAIL("Couldn't find \"/subnode2/subsubnode\": %s",
- fdt_strerror(err));
+ fdt_strerror(subsubnode2_offset));
check_getprop_typed(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
err = fdt_del_node(fdt, subnode2_offset);
@@ -82,19 +86,22 @@
FAIL("fdt_del_node(subnode2): %s", fdt_strerror(err));
subnode1_offset = fdt_path_offset(fdt, "/subnode1");
- if ((err = fdt_offset_error(subnode1_offset)) != FDT_ERR_NOTFOUND)
+ if (subnode1_offset != -FDT_ERR_NOTFOUND)
FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
- fdt_strerror(err), fdt_strerror(FDT_ERR_NOTFOUND));
+ fdt_strerror(subnode1_offset),
+ fdt_strerror(-FDT_ERR_NOTFOUND));
subnode2_offset = fdt_path_offset(fdt, "/subnode2");
- if ((err = fdt_offset_error(subnode2_offset)) != FDT_ERR_NOTFOUND)
+ if (subnode2_offset != -FDT_ERR_NOTFOUND)
FAIL("fdt_path_offset(subnode2) returned \"%s\" instead of \"%s\"",
- fdt_strerror(err), fdt_strerror(FDT_ERR_NOTFOUND));
+ fdt_strerror(subnode2_offset),
+ fdt_strerror(-FDT_ERR_NOTFOUND));
subsubnode2_offset = fdt_path_offset(fdt, "/subnode2/subsubnode");
- if ((err = fdt_offset_error(subsubnode2_offset)) != FDT_ERR_NOTFOUND)
+ if (subsubnode2_offset != -FDT_ERR_NOTFOUND)
FAIL("fdt_path_offset(subsubnode2) returned \"%s\" instead of \"%s\"",
- fdt_strerror(err), fdt_strerror(FDT_ERR_NOTFOUND));
+ fdt_strerror(subsubnode2_offset),
+ fdt_strerror(-FDT_ERR_NOTFOUND));
delsize = fdt_totalsize(fdt);