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

@ -40,10 +40,9 @@ int main(int argc, char *argv[])
prop = fdt_getprop(fdt, 0, "truncated", &len);
if (prop)
FAIL("fdt_getprop() succeeded on truncated property");
err = fdt_ptrlen_error(prop, len);
if (err != FDT_ERR_BADSTRUCTURE)
if (len != -FDT_ERR_BADSTRUCTURE)
FAIL("fdt_getprop() failed with \"%s\" instead of \"%s\"",
fdt_strerror(err), fdt_strerror(FDT_ERR_BADSTRUCTURE));
fdt_strerror(err), fdt_strerror(-FDT_ERR_BADSTRUCTURE));
PASS();
}