[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220323091810.329217-4-clement.leger@bootlin.com>
Date: Wed, 23 Mar 2022 10:18:06 +0100
From: Clément Léger <clement.leger@...tlin.com>
To: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Daniel Scally <djrscally@...il.com>,
Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
Sakari Ailus <sakari.ailus@...ux.intel.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Rafael J . Wysocki" <rafael@...nel.org>,
Wolfram Sang <wsa@...nel.org>, Peter Rosin <peda@...ntia.se>,
Rob Herring <robh+dt@...nel.org>,
Frank Rowand <frowand.list@...il.com>,
Len Brown <lenb@...nel.org>
Cc: Hans de Goede <hdegoede@...hat.com>,
Thomas Petazzoni <thomas.petazzoni@...tlin.com>,
Alexandre Belloni <alexandre.belloni@...tlin.com>,
Allan Nielsen <allan.nielsen@...rochip.com>,
linux-kernel@...r.kernel.org, linux-acpi@...r.kernel.org,
linux-i2c@...r.kernel.org,
Clément Léger <clement.leger@...tlin.com>
Subject: [PATCH v2 3/7] software node: implement .property_read_string_index callback
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@...tlin.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
Powered by blists - more mailing lists