From 2f08bfa9526bae4f461e043530cfb903fec0d273 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Tue, 20 May 2008 17:19:11 +1000 Subject: 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 --- libfdt/fdt_ro.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'libfdt/fdt_ro.c') diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c index 11d80d2..69af7bb 100644 --- a/libfdt/fdt_ro.c +++ b/libfdt/fdt_ro.c @@ -161,16 +161,12 @@ int fdt_path_offset(const void *fdt, const char *path) const char *fdt_get_name(const void *fdt, int nodeoffset, int *len) { - const struct fdt_node_header *nh; + const struct fdt_node_header *nh = _fdt_offset_ptr(fdt, nodeoffset); int err; - if ((err = fdt_check_header(fdt)) != 0) - goto fail; - - err = -FDT_ERR_BADOFFSET; - nh = fdt_offset_ptr(fdt, nodeoffset, sizeof(*nh)); - if (!nh || (fdt32_to_cpu(nh->tag) != FDT_BEGIN_NODE)) - goto fail; + if (((err = fdt_check_header(fdt)) != 0) + || ((err = _fdt_check_node_offset(fdt, nodeoffset)) < 0)) + goto fail; if (len) *len = strlen(nh->name); @@ -193,17 +189,11 @@ const struct fdt_property *fdt_get_property(const void *fdt, int offset, nextoffset; int err; - if ((err = fdt_check_header(fdt)) != 0) - goto fail; - - err = -FDT_ERR_BADOFFSET; - if (nodeoffset % FDT_TAGSIZE) - goto fail; - - tag = fdt_next_tag(fdt, nodeoffset, &nextoffset); - if (tag != FDT_BEGIN_NODE) - goto fail; + if (((err = fdt_check_header(fdt)) != 0) + || ((err = _fdt_check_node_offset(fdt, nodeoffset)) < 0)) + goto fail; + nextoffset = err; do { offset = nextoffset; -- cgit v1.1