libfdt: Use void * to refer to device tree blobs

At present, the blob containing a device tree is passed to the various
fdt_*() functions as a (struct fdt_header *) i.e. a pointer to the
header structure at the beginning of the blob.

This patch changes all the functions so that they instead take a (void
*) pointing to the blob.  Under some circumstances can avoid the need
for the caller to cast a blob pointer into a (struct fdt_header *)
before passing it to the fdt_*() functions.

Using a (void *) also reduce the temptation for users of the library
to directly dereference toe (struct fdt_header *) to access header
fields.  Instead they must use the fdt_get_header() or
fdt_set_header() macros, or the fdt_magic(), fdt_totalsize()
etc. wrappers around them which are safer, since they will always
handle endian conversion.

With this change, the whole-tree moving, or manipulating functions:
fdt_move(), fdt_open_into() and fdt_pack() no longer need to return a
pointer to the "new" tree.  The given (void *) buffer pointer they
take can instead be used directly by the caller as the new tree.
Those functions are thus changed to instead return an error code
(which in turn reduces the number of functions using the ugly encoding
of error values into pointers).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2006-12-15 15:12:47 +11:00
parent 568b569e89
commit 73d60926a0
26 changed files with 182 additions and 182 deletions

View file

@ -37,7 +37,7 @@
return PTR_ERROR(err); \
}
static int offset_streq(const struct fdt_header *fdt, int offset,
static int offset_streq(const void *fdt, int offset,
const char *s, int len)
{
const char *p = fdt_offset_ptr(fdt, offset, len+1);
@ -55,12 +55,12 @@ static int offset_streq(const struct fdt_header *fdt, int offset,
return 1;
}
char *fdt_string(const struct fdt_header *fdt, int stroffset)
char *fdt_string(const void *fdt, int stroffset)
{
return (char *)fdt + fdt_off_dt_strings(fdt) + stroffset;
}
int fdt_subnode_offset_namelen(const struct fdt_header *fdt, int parentoffset,
int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
const char *name, int namelen)
{
int level = 0;
@ -106,13 +106,13 @@ int fdt_subnode_offset_namelen(const struct fdt_header *fdt, int parentoffset,
return OFFSET_ERROR(FDT_ERR_NOTFOUND);
}
int fdt_subnode_offset(const struct fdt_header *fdt, int parentoffset,
int fdt_subnode_offset(const void *fdt, int parentoffset,
const char *name)
{
return fdt_subnode_offset_namelen(fdt, parentoffset, name, strlen(name));
}
int fdt_path_offset(const struct fdt_header *fdt, const char *path)
int fdt_path_offset(const void *fdt, const char *path)
{
const char *end = path + strlen(path);
const char *p = path;
@ -144,7 +144,7 @@ int fdt_path_offset(const struct fdt_header *fdt, const char *path)
return offset;
}
struct fdt_property *fdt_get_property(const struct fdt_header *fdt,
struct fdt_property *fdt_get_property(const void *fdt,
int nodeoffset,
const char *name, int *lenp)
{
@ -215,7 +215,7 @@ struct fdt_property *fdt_get_property(const struct fdt_header *fdt,
return PTR_ERROR(FDT_ERR_NOTFOUND);
}
void *fdt_getprop(const struct fdt_header *fdt, int nodeoffset,
void *fdt_getprop(const void *fdt, int nodeoffset,
const char *name, int *lenp)
{
const struct fdt_property *prop;