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>
---
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-2-sean.anderson@linux.dev
Changes in v2:
- New
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 0731994b9d7c..2f71830a1418 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
Hi Sean,
kernel test robot noticed the following build errors:
[auto build test ERROR on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Sean-Anderson/dt-bindings-net-Add-Xilinx-PCS/20250408-072650
base: net-next/main
patch link: https://lore.kernel.org/r/20250407231746.2316518-3-sean.anderson%40linux.dev
patch subject: [net-next PATCH v2 02/14] device property: Add optional nargs_prop for get_reference_args
config: riscv-randconfig-001-20250409 (https://download.01.org/0day-ci/archive/20250409/202504091059.k4s8cs0e-lkp@intel.com/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project 92c93f5286b9ff33f27ff694d2dc33da1c07afdd)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250409/202504091059.k4s8cs0e-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202504091059.k4s8cs0e-lkp@intel.com/
All errors (new ones prefixed by >>):
>> drivers/acpi/property.c:1680:1: error: incompatible function pointer types initializing 'int (*)(const struct fwnode_handle *, const char *, const char *, int, unsigned int, struct fwnode_reference_args *)' with an expression of type 'int (const struct fwnode_handle *, const char *, const char *, unsigned int, unsigned int, struct fwnode_reference_args *)' [-Wincompatible-function-pointer-types]
1680 | DECLARE_ACPI_FWNODE_OPS(acpi_device_fwnode_ops);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/acpi/property.c:1669:25: note: expanded from macro 'DECLARE_ACPI_FWNODE_OPS'
1669 | .get_reference_args = acpi_fwnode_get_reference_args, \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/acpi/property.c:1681:1: error: incompatible function pointer types initializing 'int (*)(const struct fwnode_handle *, const char *, const char *, int, unsigned int, struct fwnode_reference_args *)' with an expression of type 'int (const struct fwnode_handle *, const char *, const char *, unsigned int, unsigned int, struct fwnode_reference_args *)' [-Wincompatible-function-pointer-types]
1681 | DECLARE_ACPI_FWNODE_OPS(acpi_data_fwnode_ops);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/acpi/property.c:1669:25: note: expanded from macro 'DECLARE_ACPI_FWNODE_OPS'
1669 | .get_reference_args = acpi_fwnode_get_reference_args, \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.
vim +1680 drivers/acpi/property.c
99c63707bafd15 Sakari Ailus 2022-03-31 1650
db3e50f3234ba1 Sakari Ailus 2017-07-21 1651 #define DECLARE_ACPI_FWNODE_OPS(ops) \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1652 const struct fwnode_operations ops = { \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1653 .device_is_available = acpi_fwnode_device_is_available, \
146b4dbb0eef36 Sinan Kaya 2017-12-13 1654 .device_get_match_data = acpi_fwnode_device_get_match_data, \
8c756a0a2de17f Sakari Ailus 2022-03-31 1655 .device_dma_supported = \
8c756a0a2de17f Sakari Ailus 2022-03-31 1656 acpi_fwnode_device_dma_supported, \
8c756a0a2de17f Sakari Ailus 2022-03-31 1657 .device_get_dma_attr = acpi_fwnode_device_get_dma_attr, \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1658 .property_present = acpi_fwnode_property_present, \
bb3914101f704a Rob Herring (Arm 2025-01-09 1659) .property_read_bool = acpi_fwnode_property_present, \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1660 .property_read_int_array = \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1661 acpi_fwnode_property_read_int_array, \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1662 .property_read_string_array = \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1663 acpi_fwnode_property_read_string_array, \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1664 .get_parent = acpi_node_get_parent, \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1665 .get_next_child_node = acpi_get_next_subnode, \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1666 .get_named_child_node = acpi_fwnode_get_named_child_node, \
bc0500c1e43d95 Sakari Ailus 2019-10-03 1667 .get_name = acpi_fwnode_get_name, \
e7e242bccb209b Sakari Ailus 2019-10-03 1668 .get_name_prefix = acpi_fwnode_get_name_prefix, \
3e3119d3088f41 Sakari Ailus 2017-07-21 1669 .get_reference_args = acpi_fwnode_get_reference_args, \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1670 .graph_get_next_endpoint = \
0ef7478639c516 Sakari Ailus 2018-07-17 1671 acpi_graph_get_next_endpoint, \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1672 .graph_get_remote_endpoint = \
0ef7478639c516 Sakari Ailus 2018-07-17 1673 acpi_graph_get_remote_endpoint, \
37ba983cfb47cc Sakari Ailus 2017-07-21 1674 .graph_get_port_parent = acpi_fwnode_get_parent, \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1675 .graph_parse_endpoint = acpi_fwnode_graph_parse_endpoint, \
99c63707bafd15 Sakari Ailus 2022-03-31 1676 .irq_get = acpi_fwnode_irq_get, \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1677 }; \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1678 EXPORT_SYMBOL_GPL(ops)
db3e50f3234ba1 Sakari Ailus 2017-07-21 1679
db3e50f3234ba1 Sakari Ailus 2017-07-21 @1680 DECLARE_ACPI_FWNODE_OPS(acpi_device_fwnode_ops);
db3e50f3234ba1 Sakari Ailus 2017-07-21 1681 DECLARE_ACPI_FWNODE_OPS(acpi_data_fwnode_ops);
db3e50f3234ba1 Sakari Ailus 2017-07-21 1682 const struct fwnode_operations acpi_static_fwnode_ops;
9e987b70ada275 John Hubbard 2017-09-15 1683
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Hi Sean,
kernel test robot noticed the following build errors:
[auto build test ERROR on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Sean-Anderson/dt-bindings-net-Add-Xilinx-PCS/20250408-072650
base: net-next/main
patch link: https://lore.kernel.org/r/20250407231746.2316518-3-sean.anderson%40linux.dev
patch subject: [net-next PATCH v2 02/14] device property: Add optional nargs_prop for get_reference_args
config: i386-buildonly-randconfig-003-20250409 (https://download.01.org/0day-ci/archive/20250409/202504091003.Hc0Ig56O-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-12) 11.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250409/202504091003.Hc0Ig56O-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202504091003.Hc0Ig56O-lkp@intel.com/
All errors (new ones prefixed by >>):
>> drivers/acpi/property.c:1669:39: error: initialization of 'int (*)(const struct fwnode_handle *, const char *, const char *, int, unsigned int, struct fwnode_reference_args *)' from incompatible pointer type 'int (*)(const struct fwnode_handle *, const char *, const char *, unsigned int, unsigned int, struct fwnode_reference_args *)' [-Werror=incompatible-pointer-types]
1669 | .get_reference_args = acpi_fwnode_get_reference_args, \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/acpi/property.c:1680:1: note: in expansion of macro 'DECLARE_ACPI_FWNODE_OPS'
1680 | DECLARE_ACPI_FWNODE_OPS(acpi_device_fwnode_ops);
| ^~~~~~~~~~~~~~~~~~~~~~~
drivers/acpi/property.c:1669:39: note: (near initialization for 'acpi_device_fwnode_ops.get_reference_args')
1669 | .get_reference_args = acpi_fwnode_get_reference_args, \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/acpi/property.c:1680:1: note: in expansion of macro 'DECLARE_ACPI_FWNODE_OPS'
1680 | DECLARE_ACPI_FWNODE_OPS(acpi_device_fwnode_ops);
| ^~~~~~~~~~~~~~~~~~~~~~~
>> drivers/acpi/property.c:1669:39: error: initialization of 'int (*)(const struct fwnode_handle *, const char *, const char *, int, unsigned int, struct fwnode_reference_args *)' from incompatible pointer type 'int (*)(const struct fwnode_handle *, const char *, const char *, unsigned int, unsigned int, struct fwnode_reference_args *)' [-Werror=incompatible-pointer-types]
1669 | .get_reference_args = acpi_fwnode_get_reference_args, \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/acpi/property.c:1681:1: note: in expansion of macro 'DECLARE_ACPI_FWNODE_OPS'
1681 | DECLARE_ACPI_FWNODE_OPS(acpi_data_fwnode_ops);
| ^~~~~~~~~~~~~~~~~~~~~~~
drivers/acpi/property.c:1669:39: note: (near initialization for 'acpi_data_fwnode_ops.get_reference_args')
1669 | .get_reference_args = acpi_fwnode_get_reference_args, \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/acpi/property.c:1681:1: note: in expansion of macro 'DECLARE_ACPI_FWNODE_OPS'
1681 | DECLARE_ACPI_FWNODE_OPS(acpi_data_fwnode_ops);
| ^~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
vim +1669 drivers/acpi/property.c
99c63707bafd15 Sakari Ailus 2022-03-31 1650
db3e50f3234ba1 Sakari Ailus 2017-07-21 1651 #define DECLARE_ACPI_FWNODE_OPS(ops) \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1652 const struct fwnode_operations ops = { \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1653 .device_is_available = acpi_fwnode_device_is_available, \
146b4dbb0eef36 Sinan Kaya 2017-12-13 1654 .device_get_match_data = acpi_fwnode_device_get_match_data, \
8c756a0a2de17f Sakari Ailus 2022-03-31 1655 .device_dma_supported = \
8c756a0a2de17f Sakari Ailus 2022-03-31 1656 acpi_fwnode_device_dma_supported, \
8c756a0a2de17f Sakari Ailus 2022-03-31 1657 .device_get_dma_attr = acpi_fwnode_device_get_dma_attr, \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1658 .property_present = acpi_fwnode_property_present, \
bb3914101f704a Rob Herring (Arm 2025-01-09 1659) .property_read_bool = acpi_fwnode_property_present, \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1660 .property_read_int_array = \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1661 acpi_fwnode_property_read_int_array, \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1662 .property_read_string_array = \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1663 acpi_fwnode_property_read_string_array, \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1664 .get_parent = acpi_node_get_parent, \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1665 .get_next_child_node = acpi_get_next_subnode, \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1666 .get_named_child_node = acpi_fwnode_get_named_child_node, \
bc0500c1e43d95 Sakari Ailus 2019-10-03 1667 .get_name = acpi_fwnode_get_name, \
e7e242bccb209b Sakari Ailus 2019-10-03 1668 .get_name_prefix = acpi_fwnode_get_name_prefix, \
3e3119d3088f41 Sakari Ailus 2017-07-21 @1669 .get_reference_args = acpi_fwnode_get_reference_args, \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1670 .graph_get_next_endpoint = \
0ef7478639c516 Sakari Ailus 2018-07-17 1671 acpi_graph_get_next_endpoint, \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1672 .graph_get_remote_endpoint = \
0ef7478639c516 Sakari Ailus 2018-07-17 1673 acpi_graph_get_remote_endpoint, \
37ba983cfb47cc Sakari Ailus 2017-07-21 1674 .graph_get_port_parent = acpi_fwnode_get_parent, \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1675 .graph_parse_endpoint = acpi_fwnode_graph_parse_endpoint, \
99c63707bafd15 Sakari Ailus 2022-03-31 1676 .irq_get = acpi_fwnode_irq_get, \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1677 }; \
db3e50f3234ba1 Sakari Ailus 2017-07-21 1678 EXPORT_SYMBOL_GPL(ops)
db3e50f3234ba1 Sakari Ailus 2017-07-21 1679
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
© 2016 - 2025 Red Hat, Inc.