diff options
Diffstat (limited to 'libfdt/fdt_sw.c')
-rw-r--r-- | libfdt/fdt_sw.c | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/libfdt/fdt_sw.c b/libfdt/fdt_sw.c index dda2de3..df09876 100644 --- a/libfdt/fdt_sw.c +++ b/libfdt/fdt_sw.c @@ -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)); |