Skip to contentSkip to conversation

Make fwnode_property_get_reference_args accept NULL args

PATCH Superseded Sakari Ailus 2 participants 7 messages Nov 2, 2023

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Sakari Ailus

author reviewer
#0 lore raw

v3 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.

since v2:

- Correct fwnode_property_get_reference_args() name (was fwnode_property_get_reference()) in commit messages.

since v1:

- Applies to Rafael's devprop branch now (i.e. not on top of DisCo for Imaging set).

- Add Fixes: tags.

- Small documentation line wrap change in the first patch.

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_args allows NULL args
now

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

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

fwnode_get_property_reference_args() 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.

Fixes 977d5ad39f3e ("ACPI: Convert ACPI reference args to generic fwnode reference args")
---
 drivers/acpi/property.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/acpi/property.c +5 -2
index 413e4fcadcaf..9ff24d9c19f1 100644
@@ -851,6 +851,7 @@ static int acpi_get_ref_args(struct fwnode_reference_args *args,
  * @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
+ *	  (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
@@ -907,8 +908,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_PACKAGE:
 		/*
Signature · 1 line
2.39.2
#2 lore raw

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

Quoted 5 lines · Sakari Ailus

fwnode_get_property_reference_args() 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 int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, · line 915

Quoted 7 lines
drivers/acpi/property.c +4 -2
-		args->fwnode = acpi_fwnode_handle(device);
-		args->nargs = 0;
+		if (args) {
+			args->fwnode = acpi_fwnode_handle(device);
+			args->nargs = 0;
+		}
 		return 0;

In swnode case you used

	if (!args)
		return 0;

approach. Why not here? It also makes diff cleaner, no?

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

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

Hi Andy,

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

fwnode_get_property_reference_args() 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 int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, · line 915

Quoted 7 lines
drivers/acpi/property.c +4 -2
-		args->fwnode = acpi_fwnode_handle(device);
-		args->nargs = 0;
+		if (args) {
+			args->fwnode = acpi_fwnode_handle(device);
+			args->nargs = 0;
+		}
 		return 0;

In swnode case you used

Quoted 4 lines
	if (!args)
		return 0;

approach. Why not here? It also makes diff cleaner, no?

I'll do that here, too.

Signature · 1 line
Sakari Ailus
author reviewer
#4 lore raw

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

In reply to Sakari Ailus

fwnode_get_property_reference_args() 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.

Fixes b06184acf751 ("software node: Add software_node_get_reference_args()")
---
 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
#5 lore raw

PATCH v3 3/3 device property: fwnode_property_get_reference_args allows NULL args now

In reply to Sakari Ailus

All three fwnode_property_get_reference_args() implemantations 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 8c40abed7852..8667b13639d2 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
reviewer Reviewed-by on the v3 series
#6 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.

One nit in the first patch, otherwise LGTM,

Signature · 2 lines
With Best Regards,
Andy Shevchenko