Skip to contentSkip to conversation

device property: Align return codes of acpi_fwnode_get_reference_with_args

PATCH Superseded Sakari Ailus 2 participants 2 messages Sep 8, 2017

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Sakari Ailus

author reviewer
#0 lore raw

PATCH 1/1 device property: Align return codes of acpi_fwnode_get_reference_with_args

acpi_fwnode_get_reference_with_args(), the function implementing ACPI support for fwnode_property_get_reference_with_args(), returns directly error codes from __acpi_node_get_property_reference(). The latter uses different error codes than the OF implementation. In particular, the OF implementation uses -ENOENT to indicate there are no more entries whereas the former uses -ENODATA for the purpose.

To make matters more complicated, the ACPI implementation uses -ENOENT but for a different purpose --- when an entry exists but contains no reference. This isn't recognised by OF.

Document and align the error codes for property for fwnode_property_get_reference_with_args() so that they match with of_parse_phandle_with_args(), with the difference that -ENODATA is returned whenever an entry exists but contains no reference.

Fixes 3e3119d3088f ("device property: Introduce fwnode_property_get_reference_args")
---
 drivers/acpi/property.c | 4 ++++
 drivers/base/property.c | 4 ++++
 2 files changed, 8 insertions(+)
drivers/acpi/property.c +4 -0
index a65c09cc223f..17d760b89908 100644
@@ -1207,6 +1207,10 @@ acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode,
 
 	ret = __acpi_node_get_property_reference(fwnode, prop, index,
 						 args_count, &acpi_args);
+	if (ret == -ENODATA)
+		return -ENOENT;
+	if (ret == -ENOENT)
+		return -ENODATA;
 	if (ret < 0)
 		return ret;
 	if (!args)
drivers/base/property.c +4 -0
index d0b65bbe7e15..686e48f3a617 100644
@@ -682,6 +682,10 @@ EXPORT_SYMBOL_GPL(fwnode_property_match_string);
  * Caller is responsible to call fwnode_handle_put() on the returned
  * args->fwnode pointer.
  *
+ * Returns: %0 on success
+ *	    %-EINVAL on parse error
+ *	    %-ENODATA when an entry exists but contains no reference
+ *	    %-ENOENT when the index is out of bounds
  */
 int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
 				       const char *prop, const char *nargs_prop,
Signature · 1 line
2.11.0
#1 lore raw
Quoted 11 lines · Sakari Ailus

acpi_fwnode_get_reference_with_args(), the function implementing ACPI support for fwnode_property_get_reference_with_args(), returns directly error codes from __acpi_node_get_property_reference(). The latter uses different error codes than the OF implementation. In particular, the OF implementation uses -ENOENT to indicate there are no more entries whereas the former uses -ENODATA for the purpose.

To make matters more complicated, the ACPI implementation uses -ENOENT but for a different purpose --- when an entry exists but contains no reference. This isn't recognised by OF.

Quoted 7 lines

Document and align the error codes for property for fwnode_property_get_reference_with_args() so that they match with of_parse_phandle_with_args(), with the difference that -ENODATA is returned whenever an entry exists but contains no reference.

Fixes 3e3119d3088f ("device property: Introduce fwnode_property_get_reference_args")

You should CC Rafael and linux-acpi.

Also why not follow ACPI error codes and convert the corresponding DT function to return those instead?

Quoted 10 lines
---
 drivers/acpi/property.c | 4 ++++
 drivers/base/property.c | 4 ++++
 2 files changed, 8 insertions(+)
drivers/acpi/property.c +0 -0
index a65c09cc223f..17d760b89908 100644

drivers/acpi/property.c acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode, · line 1213

Quoted 7 lines
drivers/acpi/property.c +4 -0
@@ -1207,6 +1207,10 @@ acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode,
 
 	ret = __acpi_node_get_property_reference(fwnode, prop, index,
 						 args_count, &acpi_args);
+	if (ret == -ENODATA)
+		return -ENOENT;
+	if (ret == -ENOENT)
+		return -ENODATA;

This kind of construct without any comments explaining why this is needed, looks suspicious.