public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Anderson <sean.anderson@linux.dev>
To: netdev@vger.kernel.org, Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Russell King <linux@armlinux.org.uk>
Cc: linux-kernel@vger.kernel.org, upstream@airoha.com,
	Christian Marangi <ansuelsmth@gmail.com>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Kory Maincent <kory.maincent@bootlin.com>,
	Sean Anderson <sean.anderson@linux.dev>
Subject: [net-next PATCH v2 03/14] device property: Add fwnode_property_get_reference_optional_args
Date: Mon,  7 Apr 2025 19:17:34 -0400	[thread overview]
Message-ID: <20250407231746.2316518-4-sean.anderson@linux.dev> (raw)
In-Reply-To: <20250407231746.2316518-1-sean.anderson@linux.dev>

Add a fwnode variant of of_parse_phandle_with_optional_args to allow
nargs_prop to be absent from the referenced node. This improves
compatibility for references where the devicetree might not always have
nargs_prop.

Signed-off-by: Sean Anderson <sean.anderson@linux.dev>
---
This commit has been submitted separately as [1] and is included here
solely so CI will run.

[1] https://lore.kernel.org/all/20250407223714.2287202-3-sean.anderson@linux.dev

Changes in v2:
- New

 drivers/base/property.c  | 46 ++++++++++++++++++++++++++++++++++++++++
 include/linux/property.h |  4 ++++
 2 files changed, 50 insertions(+)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index 049f8a6088a1..ef13ca32079b 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -618,6 +618,52 @@ int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
 }
 EXPORT_SYMBOL_GPL(fwnode_property_get_reference_args);
 
+/**
+ * fwnode_property_get_reference_optional_args() - Find a reference with optional arguments
+ * @fwnode:	Firmware node where to look for the reference
+ * @prop:	The name of the property
+ * @nargs_prop:	The name of the property telling the number of
+ *		arguments in the referred node.
+ * @index:	Index of the reference, from zero onwards.
+ * @args:	Result structure with reference and integer arguments.
+ *		May be NULL.
+ *
+ * Obtain a reference based on a named property in an fwnode, with
+ * integer arguments. If @nargs_prop is absent from the referenced node, then
+ * number of arguments is be assumed to be 0.
+ *
+ * The caller is responsible for calling fwnode_handle_put() on the returned
+ * @args->fwnode pointer.
+ *
+ * Return: %0 on success
+ *	    %-ENOENT when the index is out of bounds, the index has an empty
+ *		     reference or the property was not found
+ *	    %-EINVAL on parse error
+ */
+int fwnode_property_get_reference_optional_args(const struct fwnode_handle *fwnode,
+						const char *prop,
+						const char *nargs_prop,
+						unsigned int index,
+						struct fwnode_reference_args *args)
+{
+	int ret;
+
+	if (IS_ERR_OR_NULL(fwnode))
+		return -ENOENT;
+
+	ret = fwnode_call_int_op(fwnode, get_reference_args, prop, nargs_prop,
+				 0, index, args);
+	if (ret == 0)
+		return ret;
+
+	if (IS_ERR_OR_NULL(fwnode->secondary))
+		return ret;
+
+	return fwnode_call_int_op(fwnode->secondary, get_reference_args, prop, nargs_prop,
+				  0, index, args);
+}
+EXPORT_SYMBOL_GPL(fwnode_property_get_reference_optional_args);
+
 /**
  * fwnode_find_reference - Find named reference to a fwnode_handle
  * @fwnode: Firmware node where to look for the reference
diff --git a/include/linux/property.h b/include/linux/property.h
index e214ecd241eb..a1662b36d15f 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -139,6 +139,10 @@ int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
 				       const char *prop, const char *nargs_prop,
 				       unsigned int nargs, unsigned int index,
 				       struct fwnode_reference_args *args);
+int fwnode_property_get_reference_optional_args(const struct fwnode_handle *fwnode,
+						const char *prop, const char *nargs_prop,
+						unsigned int index,
+						struct fwnode_reference_args *args);
 
 struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode,
 					    const char *name,
-- 
2.35.1.1320.gc452695387.dirty


  parent reply	other threads:[~2025-04-07 23:18 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-07 23:17 [net-next PATCH v2 00/14] Add PCS core support Sean Anderson
2025-04-07 23:17 ` [net-next PATCH v2 01/14] dt-bindings: net: Add Xilinx PCS Sean Anderson
2025-04-11 14:46   ` Rob Herring
2025-04-07 23:17 ` [net-next PATCH v2 02/14] device property: Add optional nargs_prop for get_reference_args Sean Anderson
2025-04-09  2:21   ` kernel test robot
2025-04-09  2:32   ` kernel test robot
2025-04-07 23:17 ` Sean Anderson [this message]
2025-04-07 23:17 ` [net-next PATCH v2 04/14] scripts: kernel-doc: fix parsing function-like typedefs (again) Sean Anderson
2025-04-07 23:17 ` [net-next PATCH v2 05/14] net: phylink: Support setting PCS link change callbacks Sean Anderson
2025-04-07 23:17 ` [net-next PATCH v2 06/14] net: pcs: Add subsystem Sean Anderson
2025-04-07 23:17 ` [net-next PATCH v2 07/14] net: dsa: ocelot: suppress PHY device scanning on the internal MDIO bus Sean Anderson
2025-04-07 23:17 ` [net-next PATCH v2 08/14] net: pcs: lynx: Convert to an MDIO driver Sean Anderson
2025-04-07 23:17 ` [net-next PATCH v2 09/14] net: phy: Export some functions Sean Anderson
2025-04-07 23:17 ` [net-next PATCH v2 10/14] net: pcs: Add Xilinx PCS driver Sean Anderson
2025-04-07 23:20 ` [net-next PATCH v2 11/14] net: axienet: Convert to use PCS subsystem Sean Anderson
2025-04-08 12:19   ` Gupta, Suraj
2025-04-08 15:33     ` Sean Anderson
2025-04-09  2:32   ` kernel test robot
2025-04-07 23:21 ` [net-next PATCH v2 12/14] net: macb: Move most of mac_config to mac_prepare Sean Anderson
2025-04-07 23:21 ` [net-next PATCH v2 13/14] net: macb: Support external PCSs Sean Anderson
2025-04-07 23:22 ` [net-next PATCH v2 14/14] of: property: Add device link support for PCS Sean Anderson
2025-04-11 14:47   ` Rob Herring (Arm)
2025-04-11 19:44     ` Saravana Kannan
2025-04-08 14:50 ` [net-next PATCH v2 00/14] Add PCS core support Jakub Kicinski
2025-04-08 15:30   ` Sean Anderson
2025-04-08 15:33     ` Jakub Kicinski
2025-04-08 17:27     ` Russell King (Oracle)

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=20250407231746.2316518-4-sean.anderson@linux.dev \
    --to=sean.anderson@linux.dev \
    --cc=andrew+netdev@lunn.ch \
    --cc=ansuelsmth@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=kory.maincent@bootlin.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=upstream@airoha.com \
    /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