]> xenbits.xensource.com Git - xen.git/commitdiff
xen/device-tree: Add dt_property_match_string helper
authorRahul Singh <rahul.singh@arm.com>
Wed, 20 Jan 2021 14:52:40 +0000 (14:52 +0000)
committerJulien Grall <jgrall@amazon.com>
Sat, 23 Jan 2021 11:48:33 +0000 (11:48 +0000)
Import the Linux helper of_property_match_string. This function searches
a string list property and returns the index of a specific string value.

Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
xen/common/device_tree.c
xen/include/xen/device_tree.h

index e107c6f89f1b79dd312879f667b391e17bd4f84f..18825e333edd648cb2e748a4422d338b55ec49c9 100644 (file)
@@ -208,6 +208,33 @@ int dt_property_read_string(const struct dt_device_node *np,
     return 0;
 }
 
+int dt_property_match_string(const struct dt_device_node *np,
+                             const char *propname, const char *string)
+{
+    const struct dt_property *dtprop = dt_find_property(np, propname, NULL);
+    size_t l;
+    int i;
+    const char *p, *end;
+
+    if ( !dtprop )
+        return -EINVAL;
+    if ( !dtprop->value )
+        return -ENODATA;
+
+    p = dtprop->value;
+    end = p + dtprop->length;
+
+    for ( i = 0; p < end; i++, p += l )
+    {
+        l = strnlen(p, end - p) + 1;
+        if ( p + l > end )
+            return -EILSEQ;
+        if ( strcmp(string, p) == 0 )
+            return i; /* Found it; return index */
+    }
+    return -ENODATA;
+}
+
 bool_t dt_device_is_compatible(const struct dt_device_node *device,
                                const char *compat)
 {
index f2ad22b79c63944add59a44aa00fb9c02e3e57ef..b02696be9416e17afaf779112a2d570c460039df 100644 (file)
@@ -400,6 +400,18 @@ static inline bool_t dt_property_read_bool(const struct dt_device_node *np,
 int dt_property_read_string(const struct dt_device_node *np,
                             const char *propname, const char **out_string);
 
+/**
+ * dt_property_match_string() - Find string in a list and return index
+ * @np: pointer to node containing string list property
+ * @propname: string list property name
+ * @string: pointer to string to search for in string list
+ *
+ * This function searches a string list property and returns the index
+ * of a specific string value.
+ */
+int dt_property_match_string(const struct dt_device_node *np,
+                             const char *propname, const char *string);
+
 /**
  * Checks if the given "compat" string matches one of the strings in
  * the device's "compatible" property