lkml.org 
[lkml]   [2022]   [Mar]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 3/7] software node: implement .property_read_string_index callback
Date
Implement .property_read_string_index callback by fetching the strings
pointers from the software node property and getting the one at the
requested index.

Signed-off-by: Clément Léger <clement.leger@bootlin.com>
---
drivers/base/swnode.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)

diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index 0a482212c7e8..91cefc62adb3 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -182,6 +182,34 @@ static int property_entry_read_int_array(const struct property_entry *props,
return 0;
}

+static int property_entry_read_string_index(const struct property_entry *props,
+ const char *propname, int index,
+ const char **string)
+{
+ const char * const *strings;
+ size_t length;
+ int array_len;
+
+ /* Find out the array length. */
+ array_len = property_entry_count_elems_of_size(props, propname,
+ sizeof(const char *));
+ if (array_len < 0)
+ return array_len;
+
+ if (index >= array_len)
+ return -EINVAL;
+
+ length = array_len * sizeof(const char *);
+
+ strings = property_entry_find(props, propname, length);
+ if (IS_ERR(strings))
+ return PTR_ERR(strings);
+
+ *string = strings[index];
+
+ return 0;
+}
+
static int property_entry_read_string_array(const struct property_entry *props,
const char *propname,
const char **strings, size_t nval)
@@ -408,6 +436,17 @@ static int software_node_read_string_array(const struct fwnode_handle *fwnode,
propname, val, nval);
}

+static int
+software_node_read_string_index(const struct fwnode_handle *fwnode,
+ const char *propname, int index,
+ const char **string)
+{
+ struct swnode *swnode = to_swnode(fwnode);
+
+ return property_entry_read_string_index(swnode->node->properties,
+ propname, index, string);
+}
+
static const char *
software_node_get_name(const struct fwnode_handle *fwnode)
{
@@ -665,6 +704,7 @@ static const struct fwnode_operations software_node_ops = {
.property_present = software_node_property_present,
.property_read_int_array = software_node_read_int_array,
.property_read_string_array = software_node_read_string_array,
+ .property_read_string_index = software_node_read_string_index,
.get_name = software_node_get_name,
.get_name_prefix = software_node_get_name_prefix,
.get_parent = software_node_get_parent,
--
2.34.1
\
 
 \ /
  Last update: 2022-03-23 10:21    [W:0.109 / U:0.224 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site