* [PATCH] iio: accel: st_accel: Fix invalid mount_matrix on devices without ACPI _ONT method
@ 2023-04-16 21:24 Hans de Goede
2023-04-18 12:32 ` Marius Hoch
0 siblings, 1 reply; 6+ messages in thread
From: Hans de Goede @ 2023-04-16 21:24 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Hans de Goede, Lars-Peter Clausen, Marius Hoch, linux-iio
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.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/iio/accel/st_accel_core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index 1628b177d0ed..f7b823ebc96b 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -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);
--
2.39.2
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] iio: accel: st_accel: Fix invalid mount_matrix on devices without ACPI _ONT method
2023-04-16 21:24 [PATCH] iio: accel: st_accel: Fix invalid mount_matrix on devices without ACPI _ONT method Hans de Goede
@ 2023-04-18 12:32 ` Marius Hoch
2023-04-23 10:48 ` Jonathan Cameron
0 siblings, 1 reply; 6+ messages in thread
From: Marius Hoch @ 2023-04-18 12:32 UTC (permalink / raw)
To: Hans de Goede, Jonathan Cameron; +Cc: Lars-Peter Clausen, linux-iio
On 16/04/2023 23:24, Hans de Goede wrote:
> 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.
>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Tested, with the LSM303D patches applied, on a Lenovo Yoga Tablet 2 1051-F.
Tested-by: Marius Hoch <mail@mariushoch.de>
> ---
> drivers/iio/accel/st_accel_core.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
> index 1628b177d0ed..f7b823ebc96b 100644
> --- a/drivers/iio/accel/st_accel_core.c
> +++ b/drivers/iio/accel/st_accel_core.c
> @@ -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);
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] iio: accel: st_accel: Fix invalid mount_matrix on devices without ACPI _ONT method
2023-04-18 12:32 ` Marius Hoch
@ 2023-04-23 10:48 ` Jonathan Cameron
2023-04-24 7:59 ` Linus Walleij
2023-04-24 9:30 ` Hans de Goede
0 siblings, 2 replies; 6+ messages in thread
From: Jonathan Cameron @ 2023-04-23 10:48 UTC (permalink / raw)
To: Marius Hoch; +Cc: Hans de Goede, Lars-Peter Clausen, linux-iio, Linus Walleij
On Tue, 18 Apr 2023 14:32:42 +0200
Marius Hoch <mail@mariushoch.de> wrote:
> On 16/04/2023 23:24, Hans de Goede wrote:
> > 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.
> >
> > Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> Tested, with the LSM303D patches applied, on a Lenovo Yoga Tablet 2 1051-F.
>
> Tested-by: Marius Hoch <mail@mariushoch.de>
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 :)
>
>
> > ---
> > drivers/iio/accel/st_accel_core.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
> > index 1628b177d0ed..f7b823ebc96b 100644
> > --- a/drivers/iio/accel/st_accel_core.c
> > +++ b/drivers/iio/accel/st_accel_core.c
> > @@ -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);
>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] iio: accel: st_accel: Fix invalid mount_matrix on devices without ACPI _ONT method
2023-04-23 10:48 ` Jonathan Cameron
@ 2023-04-24 7:59 ` Linus Walleij
2023-05-01 15:52 ` Jonathan Cameron
2023-04-24 9:30 ` Hans de Goede
1 sibling, 1 reply; 6+ messages in thread
From: Linus Walleij @ 2023-04-24 7:59 UTC (permalink / raw)
To: Jonathan Cameron, Denis Ciocca
Cc: Marius Hoch, Hans de Goede, Lars-Peter Clausen, linux-iio,
Mario Tesi
On Sun, Apr 23, 2023 at 12:33 PM Jonathan Cameron <jic23@kernel.org> wrote:
> 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.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] iio: accel: st_accel: Fix invalid mount_matrix on devices without ACPI _ONT method
2023-04-24 7:59 ` Linus Walleij
@ 2023-05-01 15:52 ` Jonathan Cameron
0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2023-05-01 15:52 UTC (permalink / raw)
To: Linus Walleij
Cc: Denis Ciocca, Marius Hoch, Hans de Goede, Lars-Peter Clausen,
linux-iio, Mario Tesi
On Mon, 24 Apr 2023 09:59:47 +0200
Linus Walleij <linus.walleij@linaro.org> wrote:
> On Sun, Apr 23, 2023 at 12:33 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> > 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.
>
> However it looks good to me.
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
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
>
> Yours,
> Linus Walleij
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] iio: accel: st_accel: Fix invalid mount_matrix on devices without ACPI _ONT method
2023-04-23 10:48 ` Jonathan Cameron
2023-04-24 7:59 ` Linus Walleij
@ 2023-04-24 9:30 ` Hans de Goede
1 sibling, 0 replies; 6+ messages in thread
From: Hans de Goede @ 2023-04-24 9:30 UTC (permalink / raw)
To: Jonathan Cameron, Marius Hoch
Cc: Lars-Peter Clausen, linux-iio, Linus Walleij
Hi,
On 4/23/23 12:48, Jonathan Cameron wrote:
> On Tue, 18 Apr 2023 14:32:42 +0200
> Marius Hoch <mail@mariushoch.de> wrote:
>
>> On 16/04/2023 23:24, Hans de Goede wrote:
>>> 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.
>>>
>>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> Tested, with the LSM303D patches applied, on a Lenovo Yoga Tablet 2 1051-F.
>>
>> Tested-by: Marius Hoch <mail@mariushoch.de>
>
> 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
>
> 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 :)
>>
>>
>>> ---
>>> drivers/iio/accel/st_accel_core.c | 4 ++--
>>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
>>> index 1628b177d0ed..f7b823ebc96b 100644
>>> --- a/drivers/iio/accel/st_accel_core.c
>>> +++ b/drivers/iio/accel/st_accel_core.c
>>> @@ -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);
>>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-05-01 15:36 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-16 21:24 [PATCH] iio: accel: st_accel: Fix invalid mount_matrix on devices without ACPI _ONT method Hans de Goede
2023-04-18 12:32 ` Marius Hoch
2023-04-23 10:48 ` Jonathan Cameron
2023-04-24 7:59 ` Linus Walleij
2023-05-01 15:52 ` Jonathan Cameron
2023-04-24 9:30 ` Hans de Goede
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox