summaryrefslogtreecommitdiff
path: root/include/libfdt.h
diff options
context:
space:
mode:
authorMaxime Ripard <maxime.ripard@free-electrons.com>2016-07-05 10:26:38 +0200
committerTom Rini <trini@konsulko.com>2016-08-20 11:35:00 -0400
commit67e610d9f0e9262cfa742f8a78c089b3cab9659a (patch)
treeb359e4f921e80fc8509044d52c12ea388adacb36 /include/libfdt.h
parent805ac6aacf8f9c3e912ebc8d9273e78d738c109d (diff)
downloadu-boot-67e610d9f0e9262cfa742f8a78c089b3cab9659a.tar.gz
libfdt: Add iterator over properties
Implement a macro based on fdt_first_property_offset and fdt_next_property_offset that provides a convenience to iterate over all the properties of a given node. Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> Acked-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include/libfdt.h')
-rw-r--r--include/libfdt.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/include/libfdt.h b/include/libfdt.h
index 74b1d149c2..fbbe58ceb3 100644
--- a/include/libfdt.h
+++ b/include/libfdt.h
@@ -441,6 +441,30 @@ int fdt_first_property_offset(const void *fdt, int nodeoffset);
int fdt_next_property_offset(const void *fdt, int offset);
/**
+ * fdt_for_each_property - iterate over all properties of a node
+ * @property_offset: property offset (int)
+ * @fdt: FDT blob (const void *)
+ * @node: node offset (int)
+ *
+ * This is actually a wrapper around a for loop and would be used like so:
+ *
+ * fdt_for_each_property(fdt, node, property) {
+ * ...
+ * use property
+ * ...
+ * }
+ *
+ * Note that this is implemented as a macro and property is used as
+ * iterator in the loop. It should therefore be a locally allocated
+ * variable. The node variable on the other hand is never modified, so
+ * it can be constant or even a literal.
+ */
+#define fdt_for_each_property_offset(property, fdt, node) \
+ for (property = fdt_first_property_offset(fdt, node); \
+ property >= 0; \
+ property = fdt_next_property_offset(fdt, property))
+
+/**
* fdt_get_property_by_offset - retrieve the property at a given offset
* @fdt: pointer to the device tree blob
* @offset: offset of the property to retrieve