mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-13 16:27:39 -04:00
libfdt: Several cleanups to parameter checking
This patch makes a couple of small cleanups to parameter checking of libfdt functions. - In several functions which take a node offset, we use an idiom involving fdt_next_tag() first to check that we have indeed been given a node offset. This patch adds a helper function _fdt_check_node_offset() to encapsulate this usage of fdt_next_tag(). - In fdt_rw.c in several places we have the expanded version of the RW_CHECK_HEADER() macro for no particular reason. This patch replaces those instances with an invocation of the macro; that's what it's for. - In fdt_sw.c we rename the check_header_sw() function to sw_check_header() to match the analgous function in fdt_rw.c, and we provide an SW_CHECK_HEADER() wrapper macro as RW_CHECK_HEADER() functions in fdt_rw.c Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
e4a64a8cd0
commit
aa1baab3cc
5 changed files with 44 additions and 55 deletions
|
@ -55,13 +55,21 @@
|
|||
|
||||
#include "libfdt_internal.h"
|
||||
|
||||
static int check_header_sw(void *fdt)
|
||||
static int sw_check_header(void *fdt)
|
||||
{
|
||||
if (fdt_magic(fdt) != SW_MAGIC)
|
||||
return -FDT_ERR_BADMAGIC;
|
||||
/* FIXME: should check more details about the header state */
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define SW_CHECK_HEADER(fdt) \
|
||||
{ \
|
||||
int err; \
|
||||
if ((err = sw_check_header(fdt)) != 0) \
|
||||
return err; \
|
||||
}
|
||||
|
||||
static void *grab_space(void *fdt, int len)
|
||||
{
|
||||
int offset = fdt_size_dt_struct(fdt);
|
||||
|
@ -102,11 +110,10 @@ int fdt_create(void *buf, int bufsize)
|
|||
int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size)
|
||||
{
|
||||
struct fdt_reserve_entry *re;
|
||||
int err = check_header_sw(fdt);
|
||||
int offset;
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
SW_CHECK_HEADER(fdt);
|
||||
|
||||
if (fdt_size_dt_struct(fdt))
|
||||
return -FDT_ERR_BADSTATE;
|
||||
|
||||
|
@ -131,11 +138,9 @@ int fdt_finish_reservemap(void *fdt)
|
|||
int fdt_begin_node(void *fdt, const char *name)
|
||||
{
|
||||
struct fdt_node_header *nh;
|
||||
int err = check_header_sw(fdt);
|
||||
int namelen = strlen(name) + 1;
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
SW_CHECK_HEADER(fdt);
|
||||
|
||||
nh = grab_space(fdt, sizeof(*nh) + ALIGN(namelen, FDT_TAGSIZE));
|
||||
if (! nh)
|
||||
|
@ -149,10 +154,8 @@ int fdt_begin_node(void *fdt, const char *name)
|
|||
int fdt_end_node(void *fdt)
|
||||
{
|
||||
uint32_t *en;
|
||||
int err = check_header_sw(fdt);
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
SW_CHECK_HEADER(fdt);
|
||||
|
||||
en = grab_space(fdt, FDT_TAGSIZE);
|
||||
if (! en)
|
||||
|
@ -188,11 +191,9 @@ static int find_add_string(void *fdt, const char *s)
|
|||
int fdt_property(void *fdt, const char *name, const void *val, int len)
|
||||
{
|
||||
struct fdt_property *prop;
|
||||
int err = check_header_sw(fdt);
|
||||
int nameoff;
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
SW_CHECK_HEADER(fdt);
|
||||
|
||||
nameoff = find_add_string(fdt, name);
|
||||
if (nameoff == 0)
|
||||
|
@ -211,15 +212,13 @@ int fdt_property(void *fdt, const char *name, const void *val, int len)
|
|||
|
||||
int fdt_finish(void *fdt)
|
||||
{
|
||||
int err = check_header_sw(fdt);
|
||||
char *p = (char *)fdt;
|
||||
uint32_t *end;
|
||||
int oldstroffset, newstroffset;
|
||||
uint32_t tag;
|
||||
int offset, nextoffset;
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
SW_CHECK_HEADER(fdt);
|
||||
|
||||
/* Add terminator */
|
||||
end = grab_space(fdt, sizeof(*end));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue