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>
This commit is contained in:
David Gibson 2006-12-15 15:12:51 +11:00
parent a7ee95ded6
commit 9a9fdf5991
17 changed files with 153 additions and 154 deletions

View file

@ -50,7 +50,7 @@ int main(int argc, char *argv[])
intp = fdt_getprop(fdt, 0, "prop-int", &lenerr);
if (intp)
FAIL("prop-int still present after nopping");
if ((err = fdt_ptrlen_error(intp, lenerr)) != FDT_ERR_NOTFOUND)
if (lenerr != -FDT_ERR_NOTFOUND)
FAIL("Unexpected error on second getprop: %s", fdt_strerror(err));
strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1,
@ -63,7 +63,7 @@ int main(int argc, char *argv[])
strp = fdt_getprop(fdt, 0, "prop-str", &lenerr);
if (strp)
FAIL("prop-str still present after nopping");
if ((err = fdt_ptrlen_error(strp, lenerr)) != FDT_ERR_NOTFOUND)
if (lenerr != -FDT_ERR_NOTFOUND)
FAIL("Unexpected error on second getprop: %s", fdt_strerror(err));
PASS();