mirror of
https://github.com/dgibson/dtc.git
synced 2025-12-09 05:05:20 -05:00
libfdt: Abolish encoding of error codes into pointers
This patch abolishes the non-standard and confusing encoding of errors into pointer return values. The only functions still returning such a potentially encoded pointer are fdt_get_property() and fdt_getprop(). Those functions also return a length via an (int *). With this patch those functions instead now return NULL on any error, and return the code indicating the type of error in the length paramater. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
73d60926a0
commit
a7ee95ded6
10 changed files with 79 additions and 88 deletions
58
fdt_rw.c
58
fdt_rw.c
|
|
@ -117,31 +117,29 @@ static int _find_add_string(void *fdt, const char *s)
|
|||
return (new - strtab);
|
||||
}
|
||||
|
||||
static struct fdt_property *_resize_property(void *fdt, int nodeoffset,
|
||||
const char *name, int len)
|
||||
static int _resize_property(void *fdt, int nodeoffset, const char *name, int len,
|
||||
struct fdt_property **prop)
|
||||
{
|
||||
struct fdt_property *prop;
|
||||
int oldlen;
|
||||
int err;
|
||||
|
||||
prop = fdt_get_property(fdt, nodeoffset, name, &oldlen);
|
||||
if ((err = fdt_ptr_error(prop)))
|
||||
return PTR_ERROR(err);
|
||||
*prop = fdt_get_property(fdt, nodeoffset, name, &oldlen);
|
||||
if (! (*prop))
|
||||
return -oldlen;
|
||||
|
||||
if ((err = _blob_splice_struct(fdt, prop->data,
|
||||
if ((err = _blob_splice_struct(fdt, (*prop)->data,
|
||||
ALIGN(oldlen, FDT_TAGSIZE),
|
||||
ALIGN(len, FDT_TAGSIZE))))
|
||||
return PTR_ERROR(err);
|
||||
return err;
|
||||
|
||||
prop->len = cpu_to_fdt32(len);
|
||||
return prop;
|
||||
(*prop)->len = cpu_to_fdt32(len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct fdt_property *_add_property(void *fdt, int nodeoffset,
|
||||
const char *name, int len)
|
||||
static int _add_property(void *fdt, int nodeoffset, const char *name, int len,
|
||||
struct fdt_property **prop)
|
||||
{
|
||||
uint32_t tag;
|
||||
struct fdt_property *prop;
|
||||
int proplen;
|
||||
int nextoffset;
|
||||
int namestroff;
|
||||
|
|
@ -149,23 +147,23 @@ static struct fdt_property *_add_property(void *fdt, int nodeoffset,
|
|||
|
||||
tag = _fdt_next_tag(fdt, nodeoffset, &nextoffset);
|
||||
if (tag != FDT_BEGIN_NODE)
|
||||
return PTR_ERROR(FDT_ERR_BADOFFSET);
|
||||
return FDT_ERR_BADOFFSET;
|
||||
|
||||
namestroff = _find_add_string(fdt, name);
|
||||
if (namestroff < 0)
|
||||
return PTR_ERROR(-namestroff);
|
||||
return -namestroff;
|
||||
|
||||
prop = _fdt_offset_ptr(fdt, nextoffset);
|
||||
proplen = sizeof(*prop) + ALIGN(len, FDT_TAGSIZE);
|
||||
*prop = _fdt_offset_ptr(fdt, nextoffset);
|
||||
proplen = sizeof(**prop) + ALIGN(len, FDT_TAGSIZE);
|
||||
|
||||
err = _blob_splice_struct(fdt, prop, 0, proplen);
|
||||
err = _blob_splice_struct(fdt, *prop, 0, proplen);
|
||||
if (err)
|
||||
return PTR_ERROR(err);
|
||||
return err;
|
||||
|
||||
prop->tag = cpu_to_fdt32(FDT_PROP);
|
||||
prop->nameoff = cpu_to_fdt32(namestroff);
|
||||
prop->len = cpu_to_fdt32(len);
|
||||
return prop;
|
||||
(*prop)->tag = cpu_to_fdt32(FDT_PROP);
|
||||
(*prop)->nameoff = cpu_to_fdt32(namestroff);
|
||||
(*prop)->len = cpu_to_fdt32(len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fdt_setprop(void *fdt, int nodeoffset, const char *name,
|
||||
|
|
@ -177,12 +175,9 @@ int fdt_setprop(void *fdt, int nodeoffset, const char *name,
|
|||
if ((err = rw_check_header(fdt)))
|
||||
return err;
|
||||
|
||||
prop = _resize_property(fdt, nodeoffset, name, len);
|
||||
err = fdt_ptr_error(prop);
|
||||
if (err == FDT_ERR_NOTFOUND) {
|
||||
prop = _add_property(fdt, nodeoffset, name, len);
|
||||
err = fdt_ptr_error(prop);
|
||||
}
|
||||
err = _resize_property(fdt, nodeoffset, name, len, &prop);
|
||||
if (err == FDT_ERR_NOTFOUND)
|
||||
err = _add_property(fdt, nodeoffset, name, len, &prop);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
|
@ -194,13 +189,12 @@ int fdt_delprop(void *fdt, int nodeoffset, const char *name)
|
|||
{
|
||||
struct fdt_property *prop;
|
||||
int len, proplen;
|
||||
int err;
|
||||
|
||||
RW_OFFSET_CHECK_HEADER(fdt);
|
||||
|
||||
prop = fdt_get_property(fdt, nodeoffset, name, &len);
|
||||
if ((err = fdt_ptr_error(prop)))
|
||||
return err;
|
||||
if (! prop)
|
||||
return -len;
|
||||
|
||||
proplen = sizeof(*prop) + ALIGN(len, FDT_TAGSIZE);
|
||||
return _blob_splice_struct(fdt, prop, proplen, 0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue