summaryrefslogtreecommitdiff
path: root/libfdt/fdt.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2008-05-20 17:19:11 +1000
committerGerald Van Baren <vanbaren@cideas.com>2008-06-09 21:13:39 -0400
commit2f08bfa9526bae4f461e043530cfb903fec0d273 (patch)
treee9e926f4151f5b264f3d3184535277f0edb1c457 /libfdt/fdt.c
parentfec6d9ee7c10443f65ce1788ef818919167bbf2e (diff)
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.c')
-rw-r--r--libfdt/fdt.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/libfdt/fdt.c b/libfdt/fdt.c
index cfa1989d8..cb08ba0a9 100644
--- a/libfdt/fdt.c
+++ b/libfdt/fdt.c
@@ -133,16 +133,23 @@ uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset)
return tag;
}
+int _fdt_check_node_offset(const void *fdt, int offset)
+{
+ if ((offset < 0) || (offset % FDT_TAGSIZE)
+ || (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE))
+ return -FDT_ERR_BADOFFSET;
+
+ return offset;
+}
+
int fdt_next_node(const void *fdt, int offset, int *depth)
{
int nextoffset = 0;
uint32_t tag;
- if (offset >= 0) {
- tag = fdt_next_tag(fdt, offset, &nextoffset);
- if (tag != FDT_BEGIN_NODE)
- return -FDT_ERR_BADOFFSET;
- }
+ if (offset >= 0)
+ if ((nextoffset = _fdt_check_node_offset(fdt, offset)) < 0)
+ return nextoffset;
do {
offset = nextoffset;