[PATCH v2 3/7] software node: implement .property_read_string_index callback

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx>
---
 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




[Index of Archives]     [Linux IBM ACPI]     [Linux Power Management]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux