Skip to contentSkip to conversation

iio: accel: st_accel: Fix invalid mount_matrix on devices without ACPI _ONT method

PATCH Applied Hans de Goede 4 participants 6 messages Apr 16, 2023 – May 1, 2023 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: accel: st_accel: Fix invalid mount_matrix on devices without ACPI _ONT method

When apply_acpi_orientation() fails, st_accel_common_probe() will fall back to iio_read_mount_matrix(), which checks for a mount-matrix device property and if that is not set falls back to the identity matrix.

But when a sensor has no ACPI companion fwnode, or when the ACPI fwnode does not have a "_ONT" method apply_acpi_orientation() was returning 0, causing iio_read_mount_matrix() to never get called resulting in an invalid mount_matrix:

[root@fedora ~]# cat /sys/bus/iio/devices/iio\:device0/mount_matrix (null), (null), (null); (null), (null), (null); (null), (null), (null)

Fix this by making apply_acpi_orientation() always return an error when it did not set the mount_matrix.

---
 drivers/iio/accel/st_accel_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/accel/st_accel_core.c +2 -2
index 1628b177d0ed..f7b823ebc96b 100644
@@ -1291,12 +1291,12 @@ static int apply_acpi_orientation(struct iio_dev *indio_dev)
 
 	adev = ACPI_COMPANION(indio_dev->dev.parent);
 	if (!adev)
-		return 0;
+		return -ENXIO;
 
 	/* Read _ONT data, which should be a package of 6 integers. */
 	status = acpi_evaluate_object(adev->handle, "_ONT", NULL, &buffer);
 	if (status == AE_NOT_FOUND) {
-		return 0;
+		return -ENXIO;
 	} else if (ACPI_FAILURE(status)) {
 		dev_warn(&indio_dev->dev, "failed to execute _ONT: %d\n",
 			 status);
Signature · 1 line
2.39.2
Tested-by on v1 1/1
#1 lore raw
Quoted 9 lines · Hans de Goede

When apply_acpi_orientation() fails, st_accel_common_probe() will fall back to iio_read_mount_matrix(), which checks for a mount-matrix device property and if that is not set falls back to the identity matrix.

But when a sensor has no ACPI companion fwnode, or when the ACPI fwnode does not have a "_ONT" method apply_acpi_orientation() was returning 0, causing iio_read_mount_matrix() to never get called resulting in an invalid mount_matrix:

Quoted 7 lines

[root@fedora ~]# cat /sys/bus/iio/devices/iio\:device0/mount_matrix (null), (null), (null); (null), (null), (null); (null), (null), (null)

Fix this by making apply_acpi_orientation() always return an error when it did not set the mount_matrix.

Tested, with the LSM303D patches applied, on a Lenovo Yoga Tablet 2 1051-F.

Quoted 23 lines
---
  drivers/iio/accel/st_accel_core.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/accel/st_accel_core.c +2 -2
index 1628b177d0ed..f7b823ebc96b 100644
@@ -1291,12 +1291,12 @@ static int apply_acpi_orientation(struct iio_dev *indio_dev)
 
  	adev = ACPI_COMPANION(indio_dev->dev.parent);
  	if (!adev)
-		return 0;
+		return -ENXIO;
 
  	/* Read _ONT data, which should be a package of 6 integers. */
  	status = acpi_evaluate_object(adev->handle, "_ONT", NULL, &buffer);
  	if (status == AE_NOT_FOUND) {
-		return 0;
+		return -ENXIO;
  	} else if (ACPI_FAILURE(status)) {
  		dev_warn(&indio_dev->dev, "failed to execute _ONT: %d\n",
  			 status);
maintainer
#2 lore raw
Quoted 13 lines · On Tue, 18 Apr 2023 14:32:42 +0200 Marius Hoch <[email protected]> wrote:
Quoted 12 lines · Hans de Goede

When apply_acpi_orientation() fails, st_accel_common_probe() will fall back to iio_read_mount_matrix(), which checks for a mount-matrix device property and if that is not set falls back to the identity matrix.

But when a sensor has no ACPI companion fwnode, or when the ACPI fwnode does not have a "_ONT" method apply_acpi_orientation() was returning 0, causing iio_read_mount_matrix() to never get called resulting in an invalid mount_matrix:

[root@fedora ~]# cat /sys/bus/iio/devices/iio\:device0/mount_matrix (null), (null), (null); (null), (null), (null); (null), (null), (null)

Quoted 7 lines
Quoted 4 lines

Fix this by making apply_acpi_orientation() always return an error when it did not set the mount_matrix.

Tested, with the LSM303D patches applied, on a Lenovo Yoga Tablet 2 1051-F.

Needs a fixes tag:. I think...

Fixes 3d8ad94bb175 ("iio: accel: st_sensors: Support generic mounting matrix")

actually introduced the issue rather than the patch that added the _ONT support

Linus, that's one of yours. Could you also take a glance at this.

Seems 'obviously' correct but I've been wrong before :)

Quoted 26 lines
Quoted 25 lines

---
  drivers/iio/accel/st_accel_core.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/accel/st_accel_core.c +2 -2
index 1628b177d0ed..f7b823ebc96b 100644
@@ -1291,12 +1291,12 @@ static int apply_acpi_orientation(struct iio_dev *indio_dev)
 
  	adev = ACPI_COMPANION(indio_dev->dev.parent);
  	if (!adev)
-		return 0;
+		return -ENXIO;
 
  	/* Read _ONT data, which should be a package of 6 integers. */
  	status = acpi_evaluate_object(adev->handle, "_ONT", NULL, &buffer);
  	if (status == AE_NOT_FOUND) {
-		return 0;
+		return -ENXIO;
  	} else if (ACPI_FAILURE(status)) {
  		dev_warn(&indio_dev->dev, "failed to execute _ONT: %d\n",
  			 status);  
Reviewed-by
#3 lore raw
Quoted 1 line · Jonathan Cameron

Linus, that's one of yours. Could you also take a glance at this.

Heh it should really be looked after by Denis Ciocca or Mario Tesi I think. I don't know if ST MEMS has an official Linux contact point, but I would like to nudge them to get one :)

However it looks good to me.

Yours,
Linus Walleij

maintainer Applied
#4 lore raw
Quoted 7 lines · On Mon, 24 Apr 2023 09:59:47 +0200 Linus Walleij <[email protected]>…
Quoted 1 line · Jonathan Cameron

Linus, that's one of yours. Could you also take a glance at this.

Heh it should really be looked after by Denis Ciocca or Mario Tesi I think. I don't know if ST MEMS has an official Linux contact point, but I would like to nudge them to get one :)

Always good to get input from Denis or Mario.

Quoted 3 lines

However it looks good to me.

Meh, I consider this one obvious enough that the current set of eyes would probably have noticed if it was horribly broken.

Applied to the fixes-togreg branch of iio.git and marked for stable.

There's about a week left before rc1 so time for people to scream if I'm wrong :)

Jonathan

Quoted 3 lines

Yours,
Linus Walleij

#5 lore raw
In reply to Jonathan Cameron

Hi,

Quoted 19 lines · Jonathan Cameron
Quoted 16 lines · On Tue, 18 Apr 2023 14:32:42 +0200 Marius Hoch <[email protected]> wrote:
Quoted 15 lines · Hans de Goede

When apply_acpi_orientation() fails, st_accel_common_probe() will fall back to iio_read_mount_matrix(), which checks for a mount-matrix device property and if that is not set falls back to the identity matrix.

But when a sensor has no ACPI companion fwnode, or when the ACPI fwnode does not have a "_ONT" method apply_acpi_orientation() was returning 0, causing iio_read_mount_matrix() to never get called resulting in an invalid mount_matrix:

[root@fedora ~]# cat /sys/bus/iio/devices/iio\:device0/mount_matrix (null), (null), (null); (null), (null), (null); (null), (null), (null)

Fix this by making apply_acpi_orientation() always return an error when it did not set the mount_matrix.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Tested, with the LSM303D patches applied, on a Lenovo Yoga Tablet 2 1051-F.

Needs a fixes tag:. I think...

Fixes 3d8ad94bb175 ("iio: accel: st_sensors: Support generic mounting matrix")

Right, ack for adding that fixes tag.

Regards,

Hans

Quoted 33 lines

actually introduced the issue rather than the patch that added the _ONT support

Linus, that's one of yours. Could you also take a glance at this.

Seems 'obviously' correct but I've been wrong before :)

Quoted 26 lines
Quoted 25 lines

---
  drivers/iio/accel/st_accel_core.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/accel/st_accel_core.c +2 -2
index 1628b177d0ed..f7b823ebc96b 100644
@@ -1291,12 +1291,12 @@ static int apply_acpi_orientation(struct iio_dev *indio_dev)
 
  	adev = ACPI_COMPANION(indio_dev->dev.parent);
  	if (!adev)
-		return 0;
+		return -ENXIO;
 
  	/* Read _ONT data, which should be a package of 6 integers. */
  	status = acpi_evaluate_object(adev->handle, "_ONT", NULL, &buffer);
  	if (status == AE_NOT_FOUND) {
-		return 0;
+		return -ENXIO;
  	} else if (ACPI_FAILURE(status)) {
  		dev_warn(&indio_dev->dev, "failed to execute _ONT: %d\n",
  			 status);