[rtems commit] libfdt: Add iterator over properties

Sebastian Huber sebh at rtems.org
Thu Jul 19 05:07:41 UTC 2018


Module:    rtems
Branch:    master
Commit:    eda76d492d754d395053995b445c3107ce4a0802
Changeset: http://git.rtems.org/rtems/commit/?id=eda76d492d754d395053995b445c3107ce4a0802

Author:    Maxime Ripard <maxime.ripard at free-electrons.com>
Date:      Wed Jul 27 14:55:54 2016 +0200

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 at free-electrons.com>
Acked-by: Simon Glass <sjg at chromium.org>
[dwg: Removed a stray trailing blank line]
Signed-off-by: David Gibson <david at gibson.dropbear.id.au>

---

 cpukit/include/libfdt.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/cpukit/include/libfdt.h b/cpukit/include/libfdt.h
index 911e548..be109a8 100644
--- a/cpukit/include/libfdt.h
+++ b/cpukit/include/libfdt.h
@@ -459,6 +459,33 @@ int fdt_first_property_offset(const void *fdt, int nodeoffset);
 int fdt_next_property_offset(const void *fdt, int offset);
 
 /**
+ * fdt_for_each_property_offset - iterate over all properties of a node
+ *
+ * @property_offset:	property offset (int, lvalue)
+ * @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_offset(property, fdt, node) {
+ *		Use property
+ *		...
+ *	}
+ *
+ *	if ((property < 0) && (property != -FDT_ERR_NOT_FOUND)) {
+ *		Error handling
+ *	}
+ *
+ * Note that this is implemented as a macro and property is used as
+ * iterator in the loop. The node variable 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



More information about the vc mailing list