Skip to contentSkip to conversation

Make fwnode_property_get_reference_args accept NULL args

PATCH Superseded Sakari Ailus 3 participants 11 messages Nov 1, 2023 – Nov 2, 2023

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Sakari Ailus

author reviewer
#0 lore raw

cover Make fwnode_property_get_reference_args accept NULL args

Hi all,

The of_parse_phandle_with_args() accepts NULL args but fwnode_property_get_reference_args() does not currently, in its ACPI or software node implementations. Fix this.

Sakari Ailus (3):
acpi: property: Let args be NULL in __acpi_node_get_property_reference software node: Let args be NULL in software_node_get_reference_args device property: fwnode_property_get_reference allows NULL args now

 drivers/acpi/property.c | 15 ++++++++++-----
 drivers/base/property.c |  1 +
 drivers/base/swnode.c   |  3 +++
 3 files changed, 14 insertions(+), 5 deletions(-)
Signature · 1 line
2.39.2
author reviewer
#1 lore raw

PATCH 1/3 acpi: property: Let args be NULL in __acpi_node_get_property_reference

fwnode_get_property_reference() may not be called with args argument NULL on ACPI, OF already supports this. Add the missing NULL checks and document this.

The purpose is to be able to count the references.

---
 drivers/acpi/property.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/acpi/property.c +10 -5
index d60ee0510311..fa473fc2617b 100644
@@ -879,7 +879,8 @@ static struct fwnode_handle *acpi_parse_string_ref(const struct fwnode_handle *f
  * @propname: Name of the property
  * @index: Index of the reference to return
  * @num_args: Maximum number of arguments after each reference
- * @args: Location to store the returned reference with optional arguments
+ * @args: Location to store the returned reference with optional arguments (may
+ *	  be NULL)
  *
  * Find property with @name, verifify that it is a package containing at least
  * one object reference and if so, store the ACPI device object pointer to the
@@ -937,8 +938,10 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,
 		if (!device)
 			return -EINVAL;
 
-		args->fwnode = acpi_fwnode_handle(device);
-		args->nargs = 0;
+		if (args) {
+			args->fwnode = acpi_fwnode_handle(device);
+			args->nargs = 0;
+		}
 
 		return 0;
 	case ACPI_TYPE_STRING:
@@ -949,8 +952,10 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,
 		if (!ref_fwnode)
 			return -EINVAL;
 
-		args->fwnode = ref_fwnode;
-		args->nargs = 0;
+		if (args) {
+			args->fwnode = ref_fwnode;
+			args->nargs = 0;
+		}
 
 		return 0;
 	case ACPI_TYPE_PACKAGE:
Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH 1/3] acpi: property: Let args be NULL in __acpi_node_get_property_reference

Quoted 5 lines · Sakari Ailus

fwnode_get_property_reference() may not be called with args argument NULL on ACPI, OF already supports this. Add the missing NULL checks and document this.

The purpose is to be able to count the references.

...

Quoted 2 lines

+ * @args: Location to store the returned reference with optional arguments (may
+ * be NULL)

I would wrap it as

* @args: Location to store the returned reference with optional arguments
* (may be NULL)

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author reviewer
#3 lore raw

PATCH 2/3 software node: Let args be NULL in software_node_get_reference_args

In reply to Sakari Ailus

fwnode_get_property_reference() may not be called with args argument NULL and while OF already supports this. Add the missing NULL check.

The purpose is to be able to count the references.

---
 drivers/base/swnode.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/base/swnode.c +3 -0
index 1886995a0b3a..079bd14bdedc 100644
@@ -541,6 +541,9 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode,
 	if (nargs > NR_FWNODE_REFERENCE_ARGS)
 		return -EINVAL;
 
+	if (!args)
+		return 0;
+
 	args->fwnode = software_node_get(refnode);
 	args->nargs = nargs;
 
Signature · 1 line
2.39.2
author reviewer
#4 lore raw

PATCH 3/3 device property: fwnode_property_get_reference allows NULL args now

In reply to Sakari Ailus

All three fwnode_property_get_reference() now allow args argument to be NULL. Document this.

---
 drivers/base/property.c | 1 +
 1 file changed, 1 insertion(+)
drivers/base/property.c +1 -0
index 89a6e0833356..b39d3ae04877 100644
@@ -508,6 +508,7 @@ EXPORT_SYMBOL_GPL(fwnode_property_match_string);
  * @nargs:	Number of arguments. Ignored if @nargs_prop is non-NULL.
  * @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.
Signature · 1 line
2.39.2
#5 lore raw
In reply to Sakari Ailus
Quoted 5 lines · Sakari Ailus

Hi all,

The of_parse_phandle_with_args() accepts NULL args but fwnode_property_get_reference_args() does not currently, in its ACPI or software node implementations. Fix this.

The last sentence assumes Fixes tag(s) which I can't see.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author reviewer
#6 lore raw

Hi Andy,

Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Sakari Ailus

Hi all,

The of_parse_phandle_with_args() accepts NULL args but fwnode_property_get_reference_args() does not currently, in its ACPI or software node implementations. Fix this.

The last sentence assumes Fixes tag(s) which I can't see.

This obviously hasn't been an issue for the existing users so backporting it has little value. From API consistency PoV this does matter though.

I can add a Fixes: tag if you like.

Signature · 1 line
Sakari Ailus
#7 lore raw
Quoted 4 lines · Sakari Ailus
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Sakari Ailus

Hi all,

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

The of_parse_phandle_with_args() accepts NULL args but fwnode_property_get_reference_args() does not currently, in its ACPI or software node implementations. Fix this.

The last sentence assumes Fixes tag(s) which I can't see.

This obviously hasn't been an issue for the existing users so backporting it has little value. From API consistency PoV this does matter though.

Fixes is not always about backporting. But if some code starts using that and needs to be backported with that in mind...

Quoted 1 line

I can add a Fixes: tag if you like.

I think some clarity needs to be done, either Fixes tag(s) or changing language to explain that this is an improvement and not an immediate fix.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author reviewer
#8 lore raw
In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Sakari Ailus

Hi all,

The of_parse_phandle_with_args() accepts NULL args but fwnode_property_get_reference_args() does not currently, in its ACPI or software node implementations. Fix this.

The last sentence assumes Fixes tag(s) which I can't see.

Oops. I realised this is actually changing code added in DisCo for Imaging patches. It'd be better to address this before those.

Signature · 1 line
Sakari Ailus
#9 lore raw
Quoted 5 lines · Sakari Ailus
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Sakari Ailus

Hi all,

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

The of_parse_phandle_with_args() accepts NULL args but fwnode_property_get_reference_args() does not currently, in its ACPI or software node implementations. Fix this.

The last sentence assumes Fixes tag(s) which I can't see.

Oops. I realised this is actually changing code added in DisCo for Imaging patches. It'd be better to address this before those.

So how exactly does this affect those patches?

author reviewer
#10 lore raw

Hi Rafael,

Quoted 11 lines · Rafael J. Wysocki
Quoted 9 lines · Sakari Ailus
Quoted 7 lines · Andy Shevchenko
Quoted 5 lines · Sakari Ailus

Hi all,

The of_parse_phandle_with_args() accepts NULL args but fwnode_property_get_reference_args() does not currently, in its ACPI or software node implementations. Fix this.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

The last sentence assumes Fixes tag(s) which I can't see.

Oops. I realised this is actually changing code added in DisCo for Imaging patches. It'd be better to address this before those.

So how exactly does this affect those patches?

Not much --- the patch adding string reference support will move the affected lines, hence the conflict. It's fairly trivial to resolve though. I'll send v2.

Signature · 3 lines
Regards,

Sakari Ailus