Skip to contentSkip to conversation

ACPI: property: Remove dead code

PATCH Superseded Andy Shevchenko 3 participants 16 messages Feb 10, 2021 – Feb 11, 2021 ACPI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#3 lore raw

PATCH 4/7 ACPI: property: Satisfy kernel doc validator (part 2)

In reply to Andy Shevchenko

CHECK drivers/acpi/property.c
warning: Function parameter or member '__fwnode' not described in 'acpi_graph_get_remote_endpoint'
warning: Excess function parameter 'fwnode' description in 'acpi_graph_get_remote_endpoint'
warning: Excess function parameter 'endpoint' description in 'acpi_graph_get_remote_endpoint'

Fixes 0ef7478639c5 ("ACPI: property: Make the ACPI graph API private")
---
 drivers/acpi/property.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/acpi/property.c +1 -2
index a6b096575fc8..167338fe9b04 100644
@@ -1190,8 +1190,7 @@ static struct fwnode_handle *acpi_graph_get_child_prop_value(
 
 /**
  * acpi_graph_get_remote_endpoint - Parses and returns remote end of an endpoint
- * @fwnode: Endpoint firmware node pointing to a remote device
- * @endpoint: Firmware node of remote endpoint is filled here if not %NULL
+ * @__fwnode: Endpoint firmware node pointing to a remote device
  *
  * Returns the remote endpoint corresponding to @__fwnode. NULL on error.
  */
Signature · 1 line
2.30.0
#0 lore raw

PATCH 1/7 ACPI: property: Remove dead code

After the commit 3a7a2ab839ad couple of functions became a dead code. Moreover, for all these years nobody used them. Remove.

Fixes 3a7a2ab839ad ("ACPI / property: Extend fwnode_property_* to data-only subnodes")
---
 drivers/acpi/property.c | 20 --------------------
 include/linux/acpi.h    | 21 ---------------------
 2 files changed, 41 deletions(-)
drivers/acpi/property.c +0 -20
index 24e87b630573..d9f3132466b5 100644
@@ -829,20 +829,6 @@ static int acpi_data_prop_read_single(const struct acpi_device_data *data,
 	return ret;
 }
 
-int acpi_dev_prop_read_single(struct acpi_device *adev, const char *propname,
-			      enum dev_prop_type proptype, void *val)
-{
-	int ret;
-
-	if (!adev)
-		return -EINVAL;
-
-	ret = acpi_data_prop_read_single(&adev->data, propname, proptype, val);
-	if (ret < 0 || proptype != ACPI_TYPE_STRING)
-		return ret;
-	return 0;
-}
-
 static int acpi_copy_property_array_u8(const union acpi_object *items, u8 *val,
 				       size_t nval)
 {
@@ -973,12 +959,6 @@ static int acpi_data_prop_read(const struct acpi_device_data *data,
 	return ret;
 }
 
-int acpi_dev_prop_read(const struct acpi_device *adev, const char *propname,
-		       enum dev_prop_type proptype, void *val, size_t nval)
-{
-	return adev ? acpi_data_prop_read(&adev->data, propname, proptype, val, nval) : -EINVAL;
-}
-
 /**
  * acpi_node_prop_read - retrieve the value of an ACPI property with given name.
  * @fwnode: Firmware node to get the property from.
include/linux/acpi.h +0 -21
index ea296289a94c..14ac25165ae1 100644
@@ -1121,14 +1121,9 @@ acpi_data_add_props(struct acpi_device_data *data, const guid_t *guid,
 
 int acpi_node_prop_get(const struct fwnode_handle *fwnode, const char *propname,
 		       void **valptr);
-int acpi_dev_prop_read_single(struct acpi_device *adev,
-			      const char *propname, enum dev_prop_type proptype,
-			      void *val);
 int acpi_node_prop_read(const struct fwnode_handle *fwnode,
 			const char *propname, enum dev_prop_type proptype,
 			void *val, size_t nval);
-int acpi_dev_prop_read(const struct acpi_device *adev, const char *propname,
-		       enum dev_prop_type proptype, void *val, size_t nval);
 
 struct fwnode_handle *acpi_get_next_subnode(const struct fwnode_handle *fwnode,
 					    struct fwnode_handle *child);
@@ -1230,14 +1225,6 @@ static inline int acpi_node_prop_get(const struct fwnode_handle *fwnode,
 	return -ENXIO;
 }
 
-static inline int acpi_dev_prop_read_single(const struct acpi_device *adev,
-					    const char *propname,
-					    enum dev_prop_type proptype,
-					    void *val)
-{
-	return -ENXIO;
-}
-
 static inline int acpi_node_prop_read(const struct fwnode_handle *fwnode,
 				      const char *propname,
 				      enum dev_prop_type proptype,
@@ -1246,14 +1233,6 @@ static inline int acpi_node_prop_read(const struct fwnode_handle *fwnode,
 	return -ENXIO;
 }
 
-static inline int acpi_dev_prop_read(const struct acpi_device *adev,
-				     const char *propname,
-				     enum dev_prop_type proptype,
-				     void *val, size_t nval)
-{
-	return -ENXIO;
-}
-
 static inline struct fwnode_handle *
 acpi_get_next_subnode(const struct fwnode_handle *fwnode,
 		      struct fwnode_handle *child)
Signature · 1 line
2.30.0
#1 lore raw

PATCH 2/7 ACPI: property: Make acpi_node_prop_read() static

There is no users outside of property.c. No need to export acpi_node_prop_read(), hence make it static.

Fixes 3708184afc77 ("device property: Move FW type specific functionality to FW specific files")
---
 drivers/acpi/property.c |  6 +++---
 include/linux/acpi.h    | 11 -----------
 2 files changed, 3 insertions(+), 14 deletions(-)
drivers/acpi/property.c +3 -3
index d9f3132466b5..9304c88ce446 100644
@@ -971,9 +971,9 @@ static int acpi_data_prop_read(const struct acpi_device_data *data,
  * of the property.  Otherwise, read at most @nval values to the array at the
  * location pointed to by @val.
  */
-int acpi_node_prop_read(const struct fwnode_handle *fwnode,
-			const char *propname, enum dev_prop_type proptype,
-			void *val, size_t nval)
+static int acpi_node_prop_read(const struct fwnode_handle *fwnode,
+			       const char *propname, enum dev_prop_type proptype,
+			       void *val, size_t nval)
 {
 	return acpi_data_prop_read(acpi_device_data_of_node(fwnode),
 				   propname, proptype, val, nval);
include/linux/acpi.h +0 -11
index 14ac25165ae1..3c5757d539ab 100644
@@ -1121,9 +1121,6 @@ acpi_data_add_props(struct acpi_device_data *data, const guid_t *guid,
 
 int acpi_node_prop_get(const struct fwnode_handle *fwnode, const char *propname,
 		       void **valptr);
-int acpi_node_prop_read(const struct fwnode_handle *fwnode,
-			const char *propname, enum dev_prop_type proptype,
-			void *val, size_t nval);
 
 struct fwnode_handle *acpi_get_next_subnode(const struct fwnode_handle *fwnode,
 					    struct fwnode_handle *child);
@@ -1225,14 +1222,6 @@ static inline int acpi_node_prop_get(const struct fwnode_handle *fwnode,
 	return -ENXIO;
 }
 
-static inline int acpi_node_prop_read(const struct fwnode_handle *fwnode,
-				      const char *propname,
-				      enum dev_prop_type proptype,
-				      void *val, size_t nval)
-{
-	return -ENXIO;
-}
-
 static inline struct fwnode_handle *
 acpi_get_next_subnode(const struct fwnode_handle *fwnode,
 		      struct fwnode_handle *child)
Signature · 1 line
2.30.0
#4 lore raw

PATCH 5/7 ACPI: property: Refactor acpi_data_prop_read_single()

In reply to Andy Shevchenko

Refactor acpi_data_prop_read_single() for less LOCs and better maintenance.

---
 drivers/acpi/property.c | 59 +++++++++++++++++++----------------------
 1 file changed, 28 insertions(+), 31 deletions(-)
drivers/acpi/property.c +28 -31
index 167338fe9b04..f2386ef32ff1 100644
@@ -785,47 +785,44 @@ static int acpi_data_prop_read_single(const struct acpi_device_data *data,
 				      enum dev_prop_type proptype, void *val)
 {
 	const union acpi_object *obj;
-	int ret;
+	int ret = 0;
 
 	if (!val)
 		return -EINVAL;
 
-	if (proptype >= DEV_PROP_U8 && proptype <= DEV_PROP_U64) {
+	if (proptype >= DEV_PROP_U8 && proptype <= DEV_PROP_U64)
 		ret = acpi_data_get_property(data, propname, ACPI_TYPE_INTEGER, &obj);
-		if (ret)
-			return ret;
-
-		switch (proptype) {
-		case DEV_PROP_U8:
-			if (obj->integer.value > U8_MAX)
-				return -EOVERFLOW;
-			*(u8 *)val = obj->integer.value;
-			break;
-		case DEV_PROP_U16:
-			if (obj->integer.value > U16_MAX)
-				return -EOVERFLOW;
-			*(u16 *)val = obj->integer.value;
-			break;
-		case DEV_PROP_U32:
-			if (obj->integer.value > U32_MAX)
-				return -EOVERFLOW;
-			*(u32 *)val = obj->integer.value;
-			break;
-		default:
-			*(u64 *)val = obj->integer.value;
-			break;
-		}
-	} else if (proptype == DEV_PROP_STRING) {
+	else if (proptype == DEV_PROP_STRING)
 		ret = acpi_data_get_property(data, propname, ACPI_TYPE_STRING, &obj);
-		if (ret)
-			return ret;
+	if (ret)
+		return ret;
 
+	switch (proptype) {
+	case DEV_PROP_U8:
+		if (obj->integer.value > U8_MAX)
+			return -EOVERFLOW;
+		*(u8 *)val = obj->integer.value;
+		break;
+	case DEV_PROP_U16:
+		if (obj->integer.value > U16_MAX)
+			return -EOVERFLOW;
+		*(u16 *)val = obj->integer.value;
+		break;
+	case DEV_PROP_U32:
+		if (obj->integer.value > U32_MAX)
+			return -EOVERFLOW;
+		*(u32 *)val = obj->integer.value;
+		break;
+	case DEV_PROP_U64:
+		*(u64 *)val = obj->integer.value;
+		break;
+	case DEV_PROP_STRING:
 		*(char **)val = obj->string.pointer;
-
 		return 1;
-	} else {
-		ret = -EINVAL;
+	default:
+		return -EINVAL;
 	}
+
 	return ret;
 }
 
Signature · 1 line
2.30.0
#5 lore raw

PATCH 6/7 ACPI: property: Allow to validate a single value

In reply to Andy Shevchenko

acpi_data_prop_read_single() doesn't accept a NULL parameter for the value. Let's modify it to accept NULL pointer in order to validate the single value. This will be needed for the further changes.

---
 drivers/acpi/property.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/acpi/property.c +10 -8
index f2386ef32ff1..236316ee0e25 100644
@@ -787,9 +787,6 @@ static int acpi_data_prop_read_single(const struct acpi_device_data *data,
 	const union acpi_object *obj;
 	int ret = 0;
 
-	if (!val)
-		return -EINVAL;
-
 	if (proptype >= DEV_PROP_U8 && proptype <= DEV_PROP_U64)
 		ret = acpi_data_get_property(data, propname, ACPI_TYPE_INTEGER, &obj);
 	else if (proptype == DEV_PROP_STRING)
@@ -801,23 +798,28 @@ static int acpi_data_prop_read_single(const struct acpi_device_data *data,
 	case DEV_PROP_U8:
 		if (obj->integer.value > U8_MAX)
 			return -EOVERFLOW;
-		*(u8 *)val = obj->integer.value;
+		if (val)
+			*(u8 *)val = obj->integer.value;
 		break;
 	case DEV_PROP_U16:
 		if (obj->integer.value > U16_MAX)
 			return -EOVERFLOW;
-		*(u16 *)val = obj->integer.value;
+		if (val)
+			*(u16 *)val = obj->integer.value;
 		break;
 	case DEV_PROP_U32:
 		if (obj->integer.value > U32_MAX)
 			return -EOVERFLOW;
-		*(u32 *)val = obj->integer.value;
+		if (val)
+			*(u32 *)val = obj->integer.value;
 		break;
 	case DEV_PROP_U64:
-		*(u64 *)val = obj->integer.value;
+		if (val)
+			*(u64 *)val = obj->integer.value;
 		break;
 	case DEV_PROP_STRING:
-		*(char **)val = obj->string.pointer;
+		if (val)
+			*(char **)val = obj->string.pointer;
 		return 1;
 	default:
 		return -EINVAL;
Signature · 1 line
2.30.0
#6 lore raw

PATCH 7/7 ACPI: property: Allow counting a single value as an array of 1 element

In reply to Andy Shevchenko

We allow to read the single value as a first element in the array. Unfortunately the counting doesn't work in this case and we can't call fwnode_property_count_*() API without getting an error.

Modify acpi_data_prop_read() to always try the single value read and thus allow counting the single value as an array of 1 element.

---
 drivers/acpi/property.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/acpi/property.c +4 -2
index 236316ee0e25..d6100585fceb 100644
@@ -913,12 +913,14 @@ static int acpi_data_prop_read(const struct acpi_device_data *data,
 	const union acpi_object *items;
 	int ret;
 
-	if (val && nval == 1) {
+	/* Try to read as a single value first */
+	if (!val || nval == 1) {
 		ret = acpi_data_prop_read_single(data, propname, proptype, val);
 		if (ret >= 0)
-			return ret;
+			return val ? ret : 1;
 	}
 
+	/* It's not the single value, get an array instead */
 	ret = acpi_data_get_property_array(data, propname, ACPI_TYPE_ANY, &obj);
 	if (ret)
 		return ret;
Signature · 1 line
2.30.0
#2 lore raw

PATCH 3/7 ACPI: property: Satisfy kernel doc validator (part 1)

In reply to Andy Shevchenko

CHECK drivers/acpi/property.c
warning: Function parameter or member 'data' not described in 'acpi_data_get_property_array'
warning: Excess function parameter 'adev' description in 'acpi_data_get_property_array'

Fixes 3a7a2ab839ad ("ACPI / property: Extend fwnode_property_* to data-only subnodes")
---
 drivers/acpi/property.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/property.c +1 -1
index 9304c88ce446..a6b096575fc8 100644
@@ -564,7 +564,7 @@ int acpi_node_prop_get(const struct fwnode_handle *fwnode,
 
 /**
  * acpi_data_get_property_array - return an ACPI array property with given name
- * @adev: ACPI data object to get the property from
+ * @data: ACPI data object to get the property from
  * @name: Name of the property
  * @type: Expected type of array elements
  * @obj: Location to store a pointer to the property value (if not NULL)
Signature · 1 line
2.30.0
#7 lore raw

Re: [PATCH v1 7/7] ACPI: property: Allow counting a single value as an array of 1 element

In reply to Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

We allow to read the single value as a first element in the array. Unfortunately the counting doesn't work in this case and we can't call fwnode_property_count_*() API without getting an error.

It would be good to mention what the symptom of the issue is here.

Quoted 5 lines

Modify acpi_data_prop_read() to always try the single value read and thus allow counting the single value as an array of 1 element.

This is a bug fix, so it should go in before the cleanups in this series IMO.

Also it looks like stable@vger material.

Quoted 9 lines
---
 drivers/acpi/property.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/acpi/property.c +0 -0
index 236316ee0e25..d6100585fceb 100644

drivers/acpi/property.c static int acpi_data_prop_read(const struct acpi_device_data *data, · line 918

Quoted 7 lines
drivers/acpi/property.c +2 -1
@@ -913,12 +913,14 @@ static int acpi_data_prop_read(const struct acpi_device_data *data,
        const union acpi_object *items;
        int ret;
 
-       if (val && nval == 1) {
+       /* Try to read as a single value first */
+       if (!val || nval == 1) {
                ret = acpi_data_prop_read_single(data, propname, proptype, val);

This returns -EINVAL if val is NULL.

drivers/acpi/property.c static int acpi_data_prop_read(const struct acpi_device_data *data, · line 920

Quoted 3 lines
drivers/acpi/property.c +1 -1
                if (ret >= 0)
-                       return ret;
+                       return val ? ret : 1;

So val cannot be NULL here.

drivers/acpi/property.c static int acpi_data_prop_read(const struct acpi_device_data *data,

Quoted 7 lines
drivers/acpi/property.c +1 -1
        }
 
+       /* It's not the single value, get an array instead */
        ret = acpi_data_get_property_array(data, propname, ACPI_TYPE_ANY, &obj);
        if (ret)
                return ret;
--

To me, acpi_fwnode_property_read_string_array() needs to special-case val == NULL and nval == 0.

#8 lore raw

Re: [PATCH v1 7/7] ACPI: property: Allow counting a single value as an array of 1 element

Quoted 46 lines · CET Rafael J. Wysocki
Quoted 4 lines · Andy Shevchenko

We allow to read the single value as a first element in the array. Unfortunately the counting doesn't work in this case and we can't call fwnode_property_count_*() API without getting an error.

It would be good to mention what the symptom of the issue is here.

Quoted 5 lines

Modify acpi_data_prop_read() to always try the single value read and thus allow counting the single value as an array of 1 element.

This is a bug fix, so it should go in before the cleanups in this series IMO.

Also it looks like stable@vger material.

Quoted 9 lines
---
 drivers/acpi/property.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/acpi/property.c +0 -0
index 236316ee0e25..d6100585fceb 100644

drivers/acpi/property.c static int acpi_data_prop_read(const struct acpi_device_data *data, · line 918

Quoted 7 lines
drivers/acpi/property.c +2 -1
@@ -913,12 +913,14 @@ static int acpi_data_prop_read(const struct acpi_device_data *data,
        const union acpi_object *items;
        int ret;
 
-       if (val && nval == 1) {
+       /* Try to read as a single value first */
+       if (!val || nval == 1) {
                ret = acpi_data_prop_read_single(data, propname, proptype, val);

This returns -EINVAL if val is NULL.

drivers/acpi/property.c static int acpi_data_prop_read(const struct acpi_device_data *data, · line 920

Quoted 3 lines
drivers/acpi/property.c +1 -1
                if (ret >= 0)
-                       return ret;
+                       return val ? ret : 1;

So val cannot be NULL here.

Quoted 2 lines
drivers/acpi/property.c +0 -0
        }
 
Quoted 8 lines

drivers/acpi/property.c static int acpi_data_prop_read(const struct acpi_device_data *data,

Quoted 5 lines
drivers/acpi/property.c +1 -1
+       /* It's not the single value, get an array instead */
        ret = acpi_data_get_property_array(data, propname, ACPI_TYPE_ANY, &obj);
        if (ret)
                return ret;
--

To me, acpi_fwnode_property_read_string_array() needs to special-case val == NULL and nval == 0.

Well, scratch this.

Something like the patch below (untested) should be sufficient to address this if I'm not mistaken.

---
 drivers/acpi/property.c |   17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/acpi/property.c +12 -5
Index: linux-pm/drivers/acpi/property.c
===================================================================
@@ -787,14 +787,14 @@ static int acpi_data_prop_read_single(co
 	const union acpi_object *obj;
 	int ret;
 
-	if (!val)
-		return -EINVAL;
-
 	if (proptype >= DEV_PROP_U8 && proptype <= DEV_PROP_U64) {
 		ret = acpi_data_get_property(data, propname, ACPI_TYPE_INTEGER, &obj);
 		if (ret)
 			return ret;
 
+		if (!val)
+			return 1;
+
 		switch (proptype) {
 		case DEV_PROP_U8:
 			if (obj->integer.value > U8_MAX)
@@ -820,7 +820,8 @@ static int acpi_data_prop_read_single(co
 		if (ret)
 			return ret;
 
-		*(char **)val = obj->string.pointer;
+		if (val)
+			*(char **)val = obj->string.pointer;
 
 		return 1;
 	} else {
@@ -928,10 +929,16 @@ static int acpi_data_prop_read(const str
 	const union acpi_object *items;
 	int ret;
 
-	if (val && nval == 1) {
+	if (nval == 1) {
 		ret = acpi_data_prop_read_single(data, propname, proptype, val);
 		if (ret >= 0)
 			return ret;
+
+		/*
+		 * Reading this property as a single-value one failed, but its
+		 * value may still be represented as one-element array, so
+		 * continue.
+		 */
 	}
 
 	ret = acpi_data_get_property_array(data, propname, ACPI_TYPE_ANY, &obj);
#9 lore raw

Re: [PATCH v1 7/7] ACPI: property: Allow counting a single value as an array of 1 element

Quoted 53 lines · CET Rafael J. Wysocki
Quoted 52 lines · CET Rafael J. Wysocki
Quoted 4 lines · Andy Shevchenko

We allow to read the single value as a first element in the array. Unfortunately the counting doesn't work in this case and we can't call fwnode_property_count_*() API without getting an error.

It would be good to mention what the symptom of the issue is here.

Quoted 5 lines

Modify acpi_data_prop_read() to always try the single value read and thus allow counting the single value as an array of 1 element.

This is a bug fix, so it should go in before the cleanups in this series IMO.

Also it looks like stable@vger material.

Quoted 9 lines
---
 drivers/acpi/property.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/acpi/property.c +0 -0
index 236316ee0e25..d6100585fceb 100644

drivers/acpi/property.c static int acpi_data_prop_read(const struct acpi_device_data *data, · line 918

Quoted 7 lines
drivers/acpi/property.c +2 -1
@@ -913,12 +913,14 @@ static int acpi_data_prop_read(const struct acpi_device_data *data,
        const union acpi_object *items;
        int ret;
 
-       if (val && nval == 1) {
+       /* Try to read as a single value first */
+       if (!val || nval == 1) {
                ret = acpi_data_prop_read_single(data, propname, proptype, val);

This returns -EINVAL if val is NULL.

drivers/acpi/property.c static int acpi_data_prop_read(const struct acpi_device_data *data, · line 920

Quoted 3 lines
drivers/acpi/property.c +1 -1
                if (ret >= 0)
-                       return ret;
+                       return val ? ret : 1;

So val cannot be NULL here.

Quoted 7 lines
drivers/acpi/property.c +1 -1
        }
 
+       /* It's not the single value, get an array instead */
        ret = acpi_data_get_property_array(data, propname, ACPI_TYPE_ANY, &obj);
        if (ret)
                return ret;
--
Quoted 7 lines
Quoted 2 lines

To me, acpi_fwnode_property_read_string_array() needs to special-case val == NULL and nval == 0.

Well, scratch this.

Something like the patch below (untested) should be sufficient to address this if I'm not mistaken.

Well, I am mistaken ->

Quoted 38 lines
---
 drivers/acpi/property.c |   17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

Index: linux-pm/drivers/acpi/property.c
===================================================================

drivers/acpi/property.c +5 -4
@@ -787,14 +787,14 @@ static int acpi_data_prop_read_single(co
 	const union acpi_object *obj;
 	int ret;
 
-	if (!val)
-		return -EINVAL;
-
 	if (proptype >= DEV_PROP_U8 && proptype <= DEV_PROP_U64) {
 		ret = acpi_data_get_property(data, propname, ACPI_TYPE_INTEGER, &obj);
 		if (ret)
 			return ret;
 
+		if (!val)
+			return 1;
+
 		switch (proptype) {
 		case DEV_PROP_U8:
 			if (obj->integer.value > U8_MAX)
@@ -820,7 +820,8 @@ static int acpi_data_prop_read_single(co
 		if (ret)
 			return ret;
 
-		*(char **)val = obj->string.pointer;
+		if (val)
+			*(char **)val = obj->string.pointer;
 
 		return 1;
 	} else {

drivers/acpi/property.c static int acpi_data_prop_read(const str · line 932

Quoted 5 lines
drivers/acpi/property.c +1 -1
@@ -928,10 +929,16 @@ static int acpi_data_prop_read(const str
 	const union acpi_object *items;
 	int ret;
 
-	if (val && nval == 1) {
+	if (nval == 1) {

-> because this would miss the nval == 0 case.

So appended again with this fixed.

---
 drivers/acpi/property.c |   17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/acpi/property.c +12 -5
Index: linux-pm/drivers/acpi/property.c
===================================================================
@@ -787,14 +787,14 @@ static int acpi_data_prop_read_single(co
 	const union acpi_object *obj;
 	int ret;
 
-	if (!val)
-		return -EINVAL;
-
 	if (proptype >= DEV_PROP_U8 && proptype <= DEV_PROP_U64) {
 		ret = acpi_data_get_property(data, propname, ACPI_TYPE_INTEGER, &obj);
 		if (ret)
 			return ret;
 
+		if (!val)
+			return 1;
+
 		switch (proptype) {
 		case DEV_PROP_U8:
 			if (obj->integer.value > U8_MAX)
@@ -820,7 +820,8 @@ static int acpi_data_prop_read_single(co
 		if (ret)
 			return ret;
 
-		*(char **)val = obj->string.pointer;
+		if (val)
+			*(char **)val = obj->string.pointer;
 
 		return 1;
 	} else {
@@ -928,10 +929,16 @@ static int acpi_data_prop_read(const str
 	const union acpi_object *items;
 	int ret;
 
-	if (val && nval == 1) {
+	if (nval <= 1) {
 		ret = acpi_data_prop_read_single(data, propname, proptype, val);
 		if (ret >= 0)
 			return ret;
+
+		/*
+		 * Reading this property as a single-value one failed, but its
+		 * value may still be represented as one-element array, so
+		 * continue.
+		 */
 	}
 
 	ret = acpi_data_get_property_array(data, propname, ACPI_TYPE_ANY, &obj);
#10 lore raw

Re: [PATCH v1 7/7] ACPI: property: Allow counting a single value as an array of 1 element

Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines · CET Rafael J. Wysocki
Quoted 2 lines · CET Rafael J. Wysocki

On Wed, Feb 10, 2021 at 12:51 PM Andy Shevchenko
<[email protected]> wrote:

Rafael, thanks for the review, my answers below.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

We allow to read the single value as a first element in the array. Unfortunately the counting doesn't work in this case and we can't call fwnode_property_count_*() API without getting an error.

It would be good to mention what the symptom of the issue is here.

fwnode_property_match_string() is not working as reported by Calvin.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

Modify acpi_data_prop_read() to always try the single value read and thus allow counting the single value as an array of 1 element.

This is a bug fix, so it should go in before the cleanups in this series IMO.

Seems it was never worked, hence neither Fixes tag nor...

Quoted 1 line
Quoted 1 line
Quoted 1 line

Also it looks like stable@vger material.

...Cc to stable@.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/acpi/property.c static int acpi_data_prop_read(const str · line 933

Quoted 4 lines
drivers/acpi/property.c +2 -1
-       if (val && nval == 1) {
+       /* Try to read as a single value first */
+       if (!val || nval == 1) {
                ret = acpi_data_prop_read_single(data, propname, proptype, val);

This returns -EINVAL if val is NULL.

Nope. That's why it's a patch 7. Patch 6 solves this.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Review

Quoted 3 lines
                if (ret >= 0)
(quoted diff) +1 -1
-                       return ret;
+                       return val ? ret : 1;

So val cannot be NULL here.

Why not? I have changed conditional.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
        }

To me, acpi_fwnode_property_read_string_array() needs to special-case val == NULL and nval == 0.

nval can be anything in the case of val==NULL. So far neither of your proposals conform this.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#11 lore raw

Re: [PATCH v1 7/7] ACPI: property: Allow counting a single value as an array of 1 element

Quoted 31 lines · Andy Shevchenko
Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines · CET Rafael J. Wysocki
Quoted 2 lines · CET Rafael J. Wysocki

On Wed, Feb 10, 2021 at 12:51 PM Andy Shevchenko
<[email protected]> wrote:

Rafael, thanks for the review, my answers below.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

We allow to read the single value as a first element in the array. Unfortunately the counting doesn't work in this case and we can't call fwnode_property_count_*() API without getting an error.

It would be good to mention what the symptom of the issue is here.

fwnode_property_match_string() is not working as reported by Calvin.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

Modify acpi_data_prop_read() to always try the single value read and thus allow counting the single value as an array of 1 element.

This is a bug fix, so it should go in before the cleanups in this series IMO.

Seems it was never worked, hence neither Fixes tag nor...

Quoted 1 line
Quoted 1 line
Quoted 1 line

Also it looks like stable@vger material.

...Cc to stable@.

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/acpi/property.c static int acpi_data_prop_read(const str · line 933

Quoted 4 lines
drivers/acpi/property.c +2 -1
-       if (val && nval == 1) {
+       /* Try to read as a single value first */
+       if (!val || nval == 1) {
                ret = acpi_data_prop_read_single(data, propname, proptype, val);

This returns -EINVAL if val is NULL.

Nope. That's why it's a patch 7. Patch 6 solves this.

That's my point. Patch 7 should be the first one in the series.

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Review

Quoted 3 lines
                if (ret >= 0)
(quoted diff) +1 -1
-                       return ret;
+                       return val ? ret : 1;

So val cannot be NULL here.

Why not? I have changed conditional.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
        }

To me, acpi_fwnode_property_read_string_array() needs to special-case val == NULL and nval == 0.

nval can be anything in the case of val==NULL. So far neither of your proposals conform this.

That is if !val and nval != 0 is regarded as a valid combination of arguments, but is it?

If that is the case, the check in acpi_data_prop_read() in the last patch that I posted needs to be (!val || nval == 1), but that would be it, no?

#12 lore raw

Re: [PATCH v1 7/7] ACPI: property: Allow counting a single value as an array of 1 element

Quoted 7 lines · Rafael J. Wysocki
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines · CET Rafael J. Wysocki
Quoted 2 lines · CET Rafael J. Wysocki

On Wed, Feb 10, 2021 at 12:51 PM Andy Shevchenko
<[email protected]> wrote:

...

Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/acpi/property.c static int acpi_data_prop_read(const str · line 933

Quoted 4 lines
drivers/acpi/property.c +2 -1
-       if (val && nval == 1) {
+       /* Try to read as a single value first */
+       if (!val || nval == 1) {
                ret = acpi_data_prop_read_single(data, propname, proptype, val);

This returns -EINVAL if val is NULL.

Nope. That's why it's a patch 7. Patch 6 solves this.

That's my point. Patch 7 should be the first one in the series.

Ah, okay. Since you want this let me rebase.

Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Review

Quoted 3 lines
                if (ret >= 0)
(quoted diff) +1 -1
-                       return ret;
+                       return val ? ret : 1;

So val cannot be NULL here.

Why not? I have changed conditional.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
        }
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

To me, acpi_fwnode_property_read_string_array() needs to special-case val == NULL and nval == 0.

nval can be anything in the case of val==NULL. So far neither of your proposals conform this.

That is if !val and nval != 0 is regarded as a valid combination of arguments, but is it?

I believe nobody tested that.

Quoted 3 lines

If that is the case, the check in acpi_data_prop_read() in the last patch that I posted needs to be (!val || nval == 1), but that would be it, no?

I think it also needs the conditional at return as in my patch.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#13 lore raw

Re: [PATCH v1 7/7] ACPI: property: Allow counting a single value as an array of 1 element

Quoted 17 lines · Andy Shevchenko
Quoted 7 lines · Rafael J. Wysocki
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines · CET Rafael J. Wysocki
Quoted 2 lines · CET Rafael J. Wysocki

On Wed, Feb 10, 2021 at 12:51 PM Andy Shevchenko
<[email protected]> wrote:

...

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
drivers/acpi/property.c +2 -1
-       if (val && nval == 1) {
+       /* Try to read as a single value first */
+       if (!val || nval == 1) {
                ret = acpi_data_prop_read_single(data, propname, proptype, val);
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

This returns -EINVAL if val is NULL.

Nope. That's why it's a patch 7. Patch 6 solves this.

That's my point. Patch 7 should be the first one in the series.

Ah, okay. Since you want this let me rebase.

Thanks!

Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Review

Quoted 3 lines
                if (ret >= 0)
(quoted diff) +1 -1
-                       return ret;
+                       return val ? ret : 1;

So val cannot be NULL here.

Why not? I have changed conditional.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
        }
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

To me, acpi_fwnode_property_read_string_array() needs to special-case val == NULL and nval == 0.

nval can be anything in the case of val==NULL. So far neither of your proposals conform this.

That is if !val and nval != 0 is regarded as a valid combination of arguments, but is it?

Quoted 7 lines

I believe nobody tested that.

Quoted 3 lines

If that is the case, the check in acpi_data_prop_read() in the last patch that I posted needs to be (!val || nval == 1), but that would be it, no?

I think it also needs the conditional at return as in my patch.

I'm not sure why.

acpi_data_prop_read_single() would return 1 for !val if it finds the property with a single value and that should be sufficient, shouldn't it?

#14 lore raw

Re: [PATCH v1 7/7] ACPI: property: Allow counting a single value as an array of 1 element

Quoted 10 lines · Rafael J. Wysocki
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Rafael J. Wysocki
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines · CET Rafael J. Wysocki
Quoted 2 lines · CET Rafael J. Wysocki

On Wed, Feb 10, 2021 at 12:51 PM Andy Shevchenko
<[email protected]> wrote:

...

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/acpi/property.c static int acpi_data_prop_read(const str · line 933

Quoted 4 lines
drivers/acpi/property.c +2 -1
-       if (val && nval == 1) {
+       /* Try to read as a single value first */
+       if (!val || nval == 1) {
                ret = acpi_data_prop_read_single(data, propname, proptype, val);

This returns -EINVAL if val is NULL.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Nope. That's why it's a patch 7. Patch 6 solves this.

That's my point. Patch 7 should be the first one in the series.

Ah, okay. Since you want this let me rebase.

Thanks!

I started rebasing and realised that your approach has swapped the error codes, i.e. if it's a single-value and it is, e.g., 16-bit wide, the u8 read will return 1, while it has to return -EOVERFLOW.

If you prefer, I can move two patches to the beginning, so one will be a good prerequisite for this fix. And I'm still unsure about stable (Fixes tag is okay to me), because the counting never worked from the day 1.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#15 lore raw

Re: [PATCH v1 7/7] ACPI: property: Allow counting a single value as an array of 1 element

Quoted 26 lines · Andy Shevchenko
Quoted 10 lines · Rafael J. Wysocki
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Rafael J. Wysocki
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines · CET Rafael J. Wysocki
Quoted 2 lines · CET Rafael J. Wysocki

On Wed, Feb 10, 2021 at 12:51 PM Andy Shevchenko
<[email protected]> wrote:

...

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/acpi/property.c static int acpi_data_prop_read(const str · line 933

Quoted 4 lines
drivers/acpi/property.c +2 -1
-       if (val && nval == 1) {
+       /* Try to read as a single value first */
+       if (!val || nval == 1) {
                ret = acpi_data_prop_read_single(data, propname, proptype, val);

This returns -EINVAL if val is NULL.

Nope. That's why it's a patch 7. Patch 6 solves this.

That's my point. Patch 7 should be the first one in the series.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Ah, okay. Since you want this let me rebase.

Thanks!

I started rebasing and realised that your approach has swapped the error codes, i.e. if it's a single-value and it is, e.g., 16-bit wide, the u8 read will return 1, while it has to return -EOVERFLOW.

Well, that's a bug in my patch.

I thought that you would reorder the series to put the fix into the front of it, but I didn't really mean to rebase it on top of my patch. Sorry for the confusion.

However, not that you have started to do it apparently, let me post that patch properly with all of the issues addressed.

Quoted 3 lines

If you prefer, I can move two patches to the beginning, so one will be a good prerequisite for this fix. And I'm still unsure about stable (Fixes tag is okay to me), because the counting never worked from the day 1.

Well, the code has never worked as intended, so why don't we make "stable" work as intended too?