mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Clément Léger" <clement.leger@bootlin.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Daniel Scally <djrscally@gmail.com>,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Wolfram Sang <wsa@kernel.org>, Peter Rosin <peda@axentia.se>,
	Rob Herring <robh+dt@kernel.org>,
	Frank Rowand <frowand.list@gmail.com>,
	Len Brown <lenb@kernel.org>
Cc: "Hans de Goede" <hdegoede@redhat.com>,
	"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	"Allan Nielsen" <allan.nielsen@microchip.com>,
	linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org,
	linux-i2c@vger.kernel.org, devicetree@vger.kernel.org,
	"Clément Léger" <clement.leger@bootlin.com>
Subject: [PATCH v3 3/9] device property: add index argument to property_read_string_array() callback
Date: Fri, 25 Mar 2022 12:31:42 +0100	[thread overview]
Message-ID: <20220325113148.588163-4-clement.leger@bootlin.com> (raw)
In-Reply-To: <20220325113148.588163-1-clement.leger@bootlin.com>

This will allow to read a string array from a specified offset. Support
for this new parameter has been added in both of through the use of
of_property_read_string_array_index() and in swnode though the existing
property_entry_read_string_array() function. ACPI support has not yet
been added and only index == 0 is accepted.

Signed-off-by: Clément Léger <clement.leger@bootlin.com>
---
 drivers/acpi/property.c |  5 ++++-
 drivers/base/property.c |  4 ++--
 drivers/base/swnode.c   | 21 +++++++++++++++------
 drivers/of/property.c   |  5 +++--
 include/linux/fwnode.h  |  7 ++++---
 5 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index 12bbfe833609..7847b21c94f7 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -1293,8 +1293,11 @@ acpi_fwnode_property_read_int_array(const struct fwnode_handle *fwnode,
 static int
 acpi_fwnode_property_read_string_array(const struct fwnode_handle *fwnode,
 				       const char *propname, const char **val,
-				       size_t nval)
+				       size_t nval, int index)
 {
+	if (index != 0)
+		return -EINVAL;
+
 	return acpi_node_prop_read(fwnode, propname, DEV_PROP_STRING,
 				   val, nval);
 }
diff --git a/drivers/base/property.c b/drivers/base/property.c
index e6497f6877ee..d95c949e0a79 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -372,12 +372,12 @@ int fwnode_property_read_string_array(const struct fwnode_handle *fwnode,
 	int ret;
 
 	ret = fwnode_call_int_op(fwnode, property_read_string_array, propname,
-				 val, nval);
+				 val, nval, 0);
 	if (ret == -EINVAL && !IS_ERR_OR_NULL(fwnode) &&
 	    !IS_ERR_OR_NULL(fwnode->secondary))
 		ret = fwnode_call_int_op(fwnode->secondary,
 					 property_read_string_array, propname,
-					 val, nval);
+					 val, nval, 0);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(fwnode_property_read_string_array);
diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index 0a482212c7e8..cb80dab041ef 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -184,9 +184,10 @@ static int property_entry_read_int_array(const struct property_entry *props,
 
 static int property_entry_read_string_array(const struct property_entry *props,
 					    const char *propname,
-					    const char **strings, size_t nval)
+					    const char **strings, size_t nval,
+					    int index)
 {
-	const void *pointer;
+	const char * const *pointer;
 	size_t length;
 	int array_len;
 
@@ -200,13 +201,20 @@ static int property_entry_read_string_array(const struct property_entry *props,
 	if (!strings)
 		return array_len;
 
-	array_len = min_t(size_t, nval, array_len);
 	length = array_len * sizeof(*strings);
-
 	pointer = property_entry_find(props, propname, length);
 	if (IS_ERR(pointer))
 		return PTR_ERR(pointer);
 
+	if (index >= array_len)
+		return -ENODATA;
+
+	pointer += index;
+	array_len -= index;
+
+	array_len = min_t(size_t, nval, array_len);
+	length = array_len * sizeof(*strings);
+
 	memcpy(strings, pointer, length);
 
 	return array_len;
@@ -400,12 +408,13 @@ static int software_node_read_int_array(const struct fwnode_handle *fwnode,
 
 static int software_node_read_string_array(const struct fwnode_handle *fwnode,
 					   const char *propname,
-					   const char **val, size_t nval)
+					   const char **val, size_t nval,
+					   int index)
 {
 	struct swnode *swnode = to_swnode(fwnode);
 
 	return property_entry_read_string_array(swnode->node->properties,
-						propname, val, nval);
+						propname, val, nval, index);
 }
 
 static const char *
diff --git a/drivers/of/property.c b/drivers/of/property.c
index 8e90071de6ed..77e8df4a6267 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -906,12 +906,13 @@ static int of_fwnode_property_read_int_array(const struct fwnode_handle *fwnode,
 static int
 of_fwnode_property_read_string_array(const struct fwnode_handle *fwnode,
 				     const char *propname, const char **val,
-				     size_t nval)
+				     size_t nval, int index)
 {
 	const struct device_node *node = to_of_node(fwnode);
 
 	return val ?
-		of_property_read_string_array(node, propname, val, nval) :
+		of_property_read_string_array_index(node, propname, val, nval,
+						    index) :
 		of_property_count_strings(node, propname);
 }
 
diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h
index 3a532ba66f6c..b9e28ba49038 100644
--- a/include/linux/fwnode.h
+++ b/include/linux/fwnode.h
@@ -91,8 +91,9 @@ struct fwnode_reference_args {
  * @property_present: Return true if a property is present.
  * @property_read_int_array: Read an array of integer properties. Return zero on
  *			     success, a negative error code otherwise.
- * @property_read_string_array: Read an array of string properties. Return zero
- *				on success, a negative error code otherwise.
+ * @property_read_string_array: Read an array of string properties starting at
+ *				a specified index. Return zero on success, a
+ *				negative error code otherwise.
  * @get_name: Return the name of an fwnode.
  * @get_name_prefix: Get a prefix for a node (for printing purposes).
  * @get_parent: Return the parent of an fwnode.
@@ -122,7 +123,7 @@ struct fwnode_operations {
 	int
 	(*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
 				      const char *propname, const char **val,
-				      size_t nval);
+				      size_t nval, int index);
 	const char *(*get_name)(const struct fwnode_handle *fwnode);
 	const char *(*get_name_prefix)(const struct fwnode_handle *fwnode);
 	struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
-- 
2.34.1


  parent reply	other threads:[~2022-03-25 11:34 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-25 11:31 [PATCH v3 0/9] introduce fwnode in the I2C subsystem Clément Léger
2022-03-25 11:31 ` [PATCH v3 1/9] of: add of_property_read_string_array_index() Clément Léger
2022-03-29 23:32   ` Rob Herring
2022-03-25 11:31 ` [PATCH v3 2/9] of: unittests: add tests for of_property_read_string_array_index() Clément Léger
2022-03-29 23:32   ` Rob Herring
2022-03-25 11:31 ` Clément Léger [this message]
2022-03-25 14:30   ` [PATCH v3 3/9] device property: add index argument to property_read_string_array() callback Andy Shevchenko
2022-03-28 14:28     ` Clément Léger
2022-04-05 13:22       ` Rafael J. Wysocki
2022-04-05 13:27         ` Clément Léger
2022-03-25 11:31 ` [PATCH v3 4/9] device property: add fwnode_property_read_string_index() Clément Léger
2022-03-25 14:33   ` Andy Shevchenko
2022-03-25 15:10     ` Clément Léger
2022-03-25 11:31 ` [PATCH v3 5/9] device property: add tests for fwnode_property_read_string_index() Clément Léger
2022-03-25 11:31 ` [PATCH v3 6/9] i2c: fwnode: add fwnode_find_i2c_adapter_by_node() Clément Léger
2022-03-25 14:35   ` Andy Shevchenko
2022-03-25 15:09     ` Clément Léger
2022-03-25 15:56       ` Andy Shevchenko
2022-03-25 16:04         ` Clément Léger
2022-03-25 16:29           ` Andy Shevchenko
2022-03-25 11:31 ` [PATCH v3 7/9] i2c: of: use fwnode_get_i2c_adapter_by_node() Clément Léger
2022-03-25 11:31 ` [PATCH v3 8/9] i2c: mux: pinctrl: remove CONFIG_OF dependency and use fwnode API Clément Léger
2022-03-25 14:38   ` Andy Shevchenko
2022-03-25 16:48   ` Peter Rosin
2022-03-31  9:40     ` Clément Léger
2022-03-25 11:31 ` [PATCH v3 9/9] i2c: mux: add support for fwnode Clément Léger
2022-05-14 14:47 ` [PATCH v3 0/9] introduce fwnode in the I2C subsystem Wolfram Sang
2022-05-15 21:34   ` Peter Rosin
2022-05-16  7:34     ` Clément Léger
2022-05-16  8:36       ` Wolfram Sang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220325113148.588163-4-clement.leger@bootlin.com \
    --to=clement.leger@bootlin.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=allan.nielsen@microchip.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=djrscally@gmail.com \
    --cc=frowand.list@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdegoede@redhat.com \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peda@axentia.se \
    --cc=rafael@kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=wsa@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®