diff mbox series

[v9,01/12] device property: add fwnode_find_reference_args()

Message ID 55924e747e4891ae75288343d9f3ad2361174bd2.1748447035.git.Jonathan.Santos@analog.com
State New
Headers show
Series [v9,01/12] device property: add fwnode_find_reference_args() | expand

Commit Message

Jonathan Santos May 29, 2025, 10:48 p.m. UTC
Similarly to fwnode_find_reference(), find and return a named reference
to a fwnode handle, including its arguments. This wrapper facilitates
cleanup handling and improves readability.

Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com>
---
v9 Changes:
* New patch.
---
 drivers/base/property.c  | 32 ++++++++++++++++++++++++++++++++
 include/linux/property.h |  6 ++++++
 2 files changed, 38 insertions(+)

Comments

Andy Shevchenko May 30, 2025, 5:48 p.m. UTC | #1
On Thu, May 29, 2025 at 07:48:17PM -0300, Jonathan Santos wrote:
> Similarly to fwnode_find_reference(), find and return a named reference
> to a fwnode handle, including its arguments. This wrapper facilitates
> cleanup handling and improves readability.

In principle I'm okay with the code, but I probably missed how this new API is
being used (in terms of a need of those arguments to be retrieved).
diff mbox series

Patch

diff --git a/drivers/base/property.c b/drivers/base/property.c
index f42f32ff45fc..b5d82facd7c5 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -645,6 +645,38 @@  struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode,
 }
 EXPORT_SYMBOL_GPL(fwnode_find_reference);
 
+/**
+ * fwnode_find_reference_args - Find named reference to a fwnode_handle with arguments
+ * @fwnode:	Firmware node where to look for the reference
+ * @name:	The name of the reference
+ * @nargs_prop:	The name of the property telling the number of
+ *		arguments in the reference. NULL if @nargs is known,
+ *		otherwise @nargs is ignored. Only relevant on OF.
+ * @nargs:	Number of arguments. Ignored if @nargs_prop is non-NULL.
+ * @index:	Index of the reference
+ *
+ * @index can be used when the named reference holds a table of references.
+ *
+ * The caller is responsible for calling fwnode_handle_put() on the returned
+ * fwnode pointer.
+ *
+ * Return: a pointer to the reference fwnode, when found. Otherwise,
+ * returns an error pointer.
+ */
+struct fwnode_handle *
+fwnode_find_reference_args(const struct fwnode_handle *fwnode,
+			   const char *name, const char *nargs_prop,
+			   unsigned int nargs, unsigned int index,
+			   struct fwnode_reference_args *args)
+{
+	int ret;
+
+	ret = fwnode_property_get_reference_args(fwnode, name, nargs_prop,
+						 nargs, index, args);
+	return ret ? ERR_PTR(ret) : args->fwnode;
+}
+EXPORT_SYMBOL_GPL(fwnode_find_reference_args);
+
 /**
  * fwnode_get_name - Return the name of a node
  * @fwnode: The firmware node
diff --git a/include/linux/property.h b/include/linux/property.h
index 3e83babac0b0..f35ced8f50f7 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -144,6 +144,12 @@  struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode,
 					    const char *name,
 					    unsigned int index);
 
+struct fwnode_handle *
+fwnode_find_reference_args(const struct fwnode_handle *fwnode,
+			   const char *name, const char *nargs_prop,
+			   unsigned int nargs, unsigned int index,
+			   struct fwnode_reference_args *args);
+
 const char *fwnode_get_name(const struct fwnode_handle *fwnode);
 const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode);
 bool fwnode_name_eq(const struct fwnode_handle *fwnode, const char *name);