diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2008-05-20 17:19:11 +1000 |
---|---|---|
committer | Gerald Van Baren <vanbaren@cideas.com> | 2008-06-09 21:13:39 -0400 |
commit | 2f08bfa9526bae4f461e043530cfb903fec0d273 (patch) | |
tree | e9e926f4151f5b264f3d3184535277f0edb1c457 /libfdt/fdt_sw.c | |
parent | fec6d9ee7c10443f65ce1788ef818919167bbf2e (diff) | |
download | u-boot-midas-2f08bfa9526bae4f461e043530cfb903fec0d273.tar.gz u-boot-midas-2f08bfa9526bae4f461e043530cfb903fec0d273.tar.bz2 u-boot-midas-2f08bfa9526bae4f461e043530cfb903fec0d273.zip |
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>
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 dda2de34b2..df0987606e 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)); |