]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - include/libfdt.h
libfdt: Add iterator over properties
[people/ms/u-boot.git] / include / libfdt.h
index 74b1d149c2dde2d3b9b72fba0dd1cbb6c47ac664..fbbe58ceb3f161905cb0e6332b39d23839c060d7 100644 (file)
@@ -440,6 +440,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