From: Sean Anderson <sean.anderson@linux.dev>
To: Rob Herring <robh@kernel.org>,
Saravana Kannan <saravanak@google.com>,
devicetree@vger.kernel.org
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J . Wysocki" <rafael@kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Len Brown <lenb@kernel.org>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Daniel Scally <djrscally@gmail.com>,
linux-kernel@vger.kernel.org, Danilo Krummrich <dakr@kernel.org>,
linux-acpi@vger.kernel.org,
Sean Anderson <sean.anderson@linux.dev>
Subject: [PATCH 1/2] device property: Add optional nargs_prop for get_reference_args
Date: Mon, 7 Apr 2025 18:37:13 -0400 [thread overview]
Message-ID: <20250407223714.2287202-2-sean.anderson@linux.dev> (raw)
In-Reply-To: <20250407223714.2287202-1-sean.anderson@linux.dev>
get_reference_args does not permit falling back to nargs when nargs_prop
is missing. This makes it difficult to support older devicetrees where
nargs_prop may not be present. Add support for this by converting nargs
to a signed value. Where before nargs was ignored if nargs_prop was
passed, now nargs is only ignored if it is strictly negative. When it is
positive, nargs represents the fallback cells to use if nargs_prop is
absent.
Signed-off-by: Sean Anderson <sean.anderson@linux.dev>
---
drivers/base/property.c | 4 ++--
drivers/base/swnode.c | 13 +++++++++----
drivers/of/property.c | 10 +++-------
include/linux/fwnode.h | 2 +-
4 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/drivers/base/property.c b/drivers/base/property.c
index c1392743df9c..049f8a6088a1 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -606,7 +606,7 @@ int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
return -ENOENT;
ret = fwnode_call_int_op(fwnode, get_reference_args, prop, nargs_prop,
- nargs, index, args);
+ nargs_prop ? -1 : nargs, index, args);
if (ret == 0)
return ret;
@@ -614,7 +614,7 @@ int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
return ret;
return fwnode_call_int_op(fwnode->secondary, get_reference_args, prop, nargs_prop,
- nargs, index, args);
+ nargs_prop ? -1 : nargs, index, args);
}
EXPORT_SYMBOL_GPL(fwnode_property_get_reference_args);
diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index b1726a3515f6..11af2001478f 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -503,7 +503,7 @@ software_node_get_named_child_node(const struct fwnode_handle *fwnode,
static int
software_node_get_reference_args(const struct fwnode_handle *fwnode,
const char *propname, const char *nargs_prop,
- unsigned int nargs, unsigned int index,
+ int nargs, unsigned int index,
struct fwnode_reference_args *args)
{
struct swnode *swnode = to_swnode(fwnode);
@@ -543,10 +543,15 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode,
error = property_entry_read_int_array(ref->node->properties,
nargs_prop, sizeof(u32),
&nargs_prop_val, 1);
- if (error)
+
+ if (error == -EINVAL) {
+ if (nargs < 0)
+ return error;
+ } else if (error) {
return error;
-
- nargs = nargs_prop_val;
+ } else {
+ nargs = nargs_prop_val;
+ }
}
if (nargs > NR_FWNODE_REFERENCE_ARGS)
diff --git a/drivers/of/property.c b/drivers/of/property.c
index c1feb631e383..c41190e47111 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -1116,19 +1116,15 @@ of_fwnode_get_named_child_node(const struct fwnode_handle *fwnode,
static int
of_fwnode_get_reference_args(const struct fwnode_handle *fwnode,
const char *prop, const char *nargs_prop,
- unsigned int nargs, unsigned int index,
+ int nargs, unsigned int index,
struct fwnode_reference_args *args)
{
struct of_phandle_args of_args;
unsigned int i;
int ret;
- if (nargs_prop)
- ret = of_parse_phandle_with_args(to_of_node(fwnode), prop,
- nargs_prop, index, &of_args);
- else
- ret = of_parse_phandle_with_fixed_args(to_of_node(fwnode), prop,
- nargs, index, &of_args);
+ ret = __of_parse_phandle_with_args(to_of_node(fwnode), prop, nargs_prop,
+ nargs, index, &of_args);
if (ret < 0)
return ret;
if (!args) {
diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h
index 6fa0a268d538..69fe44c68f8c 100644
--- a/include/linux/fwnode.h
+++ b/include/linux/fwnode.h
@@ -163,7 +163,7 @@ struct fwnode_operations {
const char *name);
int (*get_reference_args)(const struct fwnode_handle *fwnode,
const char *prop, const char *nargs_prop,
- unsigned int nargs, unsigned int index,
+ int nargs, unsigned int index,
struct fwnode_reference_args *args);
struct fwnode_handle *
(*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
--
2.35.1.1320.gc452695387.dirty
next prev parent reply other threads:[~2025-04-07 22:37 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-07 22:37 [PATCH 0/2] device property: Add fwnode_property_get_reference_optional_args Sean Anderson
2025-04-07 22:37 ` Sean Anderson [this message]
2025-04-08 8:37 ` [PATCH 1/2] device property: Add optional nargs_prop for get_reference_args Andy Shevchenko
2025-04-08 12:52 ` Rob Herring
2025-04-08 9:14 ` Sakari Ailus
2025-04-08 12:55 ` Rob Herring
2025-04-07 22:37 ` [PATCH 2/2] device property: Add fwnode_property_get_reference_optional_args Sean Anderson
2025-04-08 8:39 ` Andy Shevchenko
2025-04-08 15:10 ` Sean Anderson
2025-04-08 13:00 ` Rob Herring
2025-04-08 15:12 ` Sean Anderson
2025-04-08 15:19 ` Rob Herring
2025-04-08 15:28 ` Sean Anderson
2025-04-08 17:19 ` Rob Herring
2025-04-08 8:40 ` [PATCH 0/2] " Andy Shevchenko
2025-04-08 15:13 ` Sean Anderson
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=20250407223714.2287202-2-sean.anderson@linux.dev \
--to=sean.anderson@linux.dev \
--cc=andriy.shevchenko@linux.intel.com \
--cc=dakr@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=djrscally@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=saravanak@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.