Browse Source

libfdt: Fixup usage of fdt_offset_ptr() in fdt_rw.c

Several places in fdt_rw.c incorrectly use fdt_offset_ptr(), using it
as if it returned an encoded error code on errors, instead of
returning NULL on error as it actually does.

In fact, however, in these instances the extra checks in
fdt_offset_ptr() are useless anyway, so we introduce a new (internal
use) _fdt_offset_ptr() and use that without checking.
(cherry picked from 3dffb1808dea6aee6158c92e17faa6ced9b183f2 commit)
main
David Gibson 18 years ago committed by David Gibson
parent
commit
568b569e89
  1. 2
      fdt.c
  2. 19
      fdt_rw.c
  3. 5
      libfdt_internal.h

2
fdt.c

@ -51,7 +51,7 @@ void *fdt_offset_ptr(const struct fdt_header *fdt, int offset, int len) @@ -51,7 +51,7 @@ void *fdt_offset_ptr(const struct fdt_header *fdt, int offset, int len)
|| ((offset + len) > fdt_size_dt_struct(fdt)))
return NULL;

p = (void *)fdt + fdt_off_dt_struct(fdt) + offset;
p = _fdt_offset_ptr(fdt, offset);

if (p + len < p)
return NULL;

19
fdt_rw.c

@ -157,10 +157,7 @@ static struct fdt_property *_add_property(struct fdt_header *fdt, int nodeoffset @@ -157,10 +157,7 @@ static struct fdt_property *_add_property(struct fdt_header *fdt, int nodeoffset
if (namestroff < 0)
return PTR_ERROR(-namestroff);

prop = fdt_offset_ptr(fdt, nextoffset, 0);
if ((err = fdt_ptr_error(prop)))
return PTR_ERROR(err);

prop = _fdt_offset_ptr(fdt, nextoffset);
proplen = sizeof(*prop) + ALIGN(len, FDT_TAGSIZE);

err = _blob_splice_struct(fdt, prop, 0, proplen);
@ -236,11 +233,9 @@ int fdt_add_subnode_namelen(struct fdt_header *fdt, int parentoffset, @@ -236,11 +233,9 @@ int fdt_add_subnode_namelen(struct fdt_header *fdt, int parentoffset,
tag = _fdt_next_tag(fdt, offset, &nextoffset);
} while (tag == FDT_PROP);

nh = fdt_offset_ptr(fdt, offset, 0);
if ((err = fdt_ptr_error(nh)))
return OFFSET_ERROR(err);

nh = _fdt_offset_ptr(fdt, offset);
nodelen = sizeof(*nh) + ALIGN(namelen+1, FDT_TAGSIZE) + FDT_TAGSIZE;

err = _blob_splice_struct(fdt, nh, 0, nodelen);
if (err)
return OFFSET_ERROR(err);
@ -261,7 +256,6 @@ int fdt_add_subnode(struct fdt_header *fdt, int parentoffset, const char *name) @@ -261,7 +256,6 @@ int fdt_add_subnode(struct fdt_header *fdt, int parentoffset, const char *name)

int fdt_del_node(struct fdt_header *fdt, int nodeoffset)
{
struct fdt_node_header *nh;
int endoffset;
int err;

@ -269,11 +263,8 @@ int fdt_del_node(struct fdt_header *fdt, int nodeoffset) @@ -269,11 +263,8 @@ int fdt_del_node(struct fdt_header *fdt, int nodeoffset)
if ((err = fdt_offset_error(endoffset)))
return err;

nh = fdt_offset_ptr(fdt, nodeoffset, 0);
if ((err = fdt_ptr_error(nh)))
return err;

return _blob_splice_struct(fdt, nh, endoffset - nodeoffset, 0);
return _blob_splice_struct(fdt, _fdt_offset_ptr(fdt, nodeoffset),
endoffset - nodeoffset, 0);
}

struct fdt_header *fdt_open_into(struct fdt_header *fdt, void *buf, int bufsize)

5
libfdt_internal.h

@ -31,6 +31,11 @@ uint32_t _fdt_next_tag(const struct fdt_header *fdt, int startoffset, int *nexto @@ -31,6 +31,11 @@ uint32_t _fdt_next_tag(const struct fdt_header *fdt, int startoffset, int *nexto
const char *_fdt_find_string(const char *strtab, int tabsize, const char *s);
int _fdt_node_end_offset(struct fdt_header *fdt, int nodeoffset);

static inline void *_fdt_offset_ptr(const struct fdt_header *fdt, int offset)
{
return (void *)fdt + fdt_off_dt_struct(fdt) + offset;
}

#define OFFSET_ERROR(code) -(code)
#define PTR_ERROR(code) (void *)(-(long)(code))


Loading…
Cancel
Save