From d1c6314887c4d6712f7bd9ba7428b6517e7732e0 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Tue, 9 Mar 2010 17:39:14 +1100 Subject: libfdt: Implement property iteration functions For ages, we've been talking about adding functions to libfdt to allow iteration through properties. So, finally, here are some. I got bogged down on this for a long time because I didn't want to expose offsets directly to properties to the callers. But without that, attempting to make reasonable iteration functions just became horrible. So eventually, I settled on an interface which does now expose property offsets. fdt_first_property_offset() and fdt_next_property_offset() are used to step through the offsets of the properties starting from a particularly node offset. The details of the property at each offset can then be retrieved with either fdt_get_property_by_offset() or fdt_getprop_by_offset() which have interfaces similar to fdt_get_property() and fdt_getprop() respectively. No explicit testcases are included, but we do use the new functions to reimplement the existing fdt_get_property() function. Signed-off-by: David Gibson This was extracted from the DTC commit: 73dca9ae0b9abe6924ba640164ecce9f8df69c5a Mon Sep 17 00:00:00 2001 Signed-off-by: Gerald Van Baren --- lib/libfdt/fdt.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib/libfdt/fdt.c') diff --git a/lib/libfdt/fdt.c b/lib/libfdt/fdt.c index b09ea6f04d..4157b21efd 100644 --- a/lib/libfdt/fdt.c +++ b/lib/libfdt/fdt.c @@ -153,6 +153,15 @@ int _fdt_check_node_offset(const void *fdt, int offset) return offset; } +int _fdt_check_prop_offset(const void *fdt, int offset) +{ + if ((offset < 0) || (offset % FDT_TAGSIZE) + || (fdt_next_tag(fdt, offset, &offset) != FDT_PROP)) + return -FDT_ERR_BADOFFSET; + + return offset; +} + int fdt_next_node(const void *fdt, int offset, int *depth) { int nextoffset = 0; -- cgit v1.2.1