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>
static int offset_streq(const void *fdt, int offset,
@ -60,11 +60,11 @@ int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
@@ -60,11 +60,11 @@ int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
uint32_t tag;
int offset, nextoffset;
OFFSET_CHECK_HEADER(fdt);
CHECK_HEADER(fdt);
tag = _fdt_next_tag(fdt, parentoffset, &nextoffset);
if (tag != FDT_BEGIN_NODE)
return OFFSET_ERROR(FDT_ERR_BADOFFSET);
return -FDT_ERR_BADOFFSET;
do {
offset = nextoffset;
@ -72,7 +72,7 @@ int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
@@ -72,7 +72,7 @@ int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
switch (tag) {
case FDT_END:
return OFFSET_ERROR(FDT_ERR_TRUNCATED);
return -FDT_ERR_TRUNCATED;
case FDT_BEGIN_NODE:
level++;
@ -92,11 +92,11 @@ int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
@@ -92,11 +92,11 @@ int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
break;
default:
return OFFSET_ERROR(FDT_ERR_BADSTRUCTURE);
return -FDT_ERR_BADSTRUCTURE;
}
} while (level >= 0);
return OFFSET_ERROR(FDT_ERR_NOTFOUND);
return -FDT_ERR_NOTFOUND;
}
int fdt_subnode_offset(const void *fdt, int parentoffset,
@ -62,9 +62,9 @@ static int _blob_splice(void *fdt, void *p, int oldlen, int newlen)
@@ -62,9 +62,9 @@ static int _blob_splice(void *fdt, void *p, int oldlen, int newlen)
void *end = fdt + _blob_data_size(fdt);
if (((p + oldlen) < p) || ((p + oldlen) > end))
return FDT_ERR_BADOFFSET;
return -FDT_ERR_BADOFFSET;
if ((end - oldlen + newlen) > (fdt + fdt_totalsize(fdt)))
return FDT_ERR_NOSPACE;
return -FDT_ERR_NOSPACE;
memmove(p + newlen, p + oldlen, end - p - oldlen);
@ -125,7 +125,7 @@ static int _resize_property(void *fdt, int nodeoffset, const char *name, int len
@@ -125,7 +125,7 @@ static int _resize_property(void *fdt, int nodeoffset, const char *name, int len
if ((err = _blob_splice_struct(fdt, (*prop)->data,
ALIGN(oldlen, FDT_TAGSIZE),
@ -147,11 +147,11 @@ static int _add_property(void *fdt, int nodeoffset, const char *name, int len,
@@ -147,11 +147,11 @@ static int _add_property(void *fdt, int nodeoffset, const char *name, int len,
tag = _fdt_next_tag(fdt, nodeoffset, &nextoffset);
@ -210,13 +210,13 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
@@ -210,13 +210,13 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
/* Try to place the new node after the parent's properties */
_fdt_next_tag(fdt, parentoffset, &nextoffset); /* skip the BEGIN_NODE */
@ -230,7 +230,7 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
@@ -230,7 +230,7 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,