diff mbox

[RFC,09/31] xen/device-tree: Add dt_property_for_each_string macros

Message ID 1510247421-24094-10-git-send-email-olekstysh@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Oleksandr Tyshchenko Nov. 9, 2017, 5:09 p.m. UTC
From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>

This is a port from Linux.

Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Julien Grall <julien.grall@linaro.org>
---
 xen/common/device_tree.c      | 18 ++++++++++++++++++
 xen/include/xen/device_tree.h | 21 +++++++++++++++++++++
 2 files changed, 39 insertions(+)
diff mbox

Patch

diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
index 60b0095..08f8072 100644
--- a/xen/common/device_tree.c
+++ b/xen/common/device_tree.c
@@ -208,6 +208,24 @@  int dt_property_read_string(const struct dt_device_node *np,
     return 0;
 }
 
+const char *dt_property_next_string(const struct dt_property *prop,
+                                    const char *cur)
+{
+    const void *curv = cur;
+
+    if ( !prop )
+        return NULL;
+
+    if ( !cur )
+        return prop->value;
+
+    curv += strlen(cur) + 1;
+    if ( curv >= prop->value + prop->length )
+        return NULL;
+
+    return curv;
+}
+
 bool_t dt_device_is_compatible(const struct dt_device_node *device,
                                const char *compat)
 {
diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h
index 738f1b6..9e0931c 100644
--- a/xen/include/xen/device_tree.h
+++ b/xen/include/xen/device_tree.h
@@ -420,6 +420,27 @@  int dt_property_read_string(const struct dt_device_node *np,
                             const char *propname, const char **out_string);
 
 /**
+ * dt_property_for_each_string - Iterate over an array of strings within
+ * a property with a given name for a given node.
+ *
+ * Example:
+ *
+ * struct dt_property *prop;
+ * const char *s;
+ *
+ * dt_property_for_each_string(np, "propname", prop, s)
+ *     printk("String value: %s\n", s);
+ */
+const char *dt_property_next_string(const struct dt_property *prop,
+                                    const char *cur);
+
+#define dt_property_for_each_string(np, propname, prop, s)    \
+    for (prop = dt_find_property(np, propname, NULL),         \
+        s = dt_property_next_string(prop, NULL);              \
+        s;                                                    \
+        s = dt_property_next_string(prop, s))
+
+/**
  * Checks if the given "compat" string matches one of the strings in
  * the device's "compatible" property
  */