* FAILED: patch "[PATCH] iio: adc: hx711: fix bug in sampling of data" failed to apply to 4.14-stable tree
@ 2019-10-14 15:01 gregkh
2019-10-15 0:57 ` Sasha Levin
0 siblings, 1 reply; 2+ messages in thread
From: gregkh @ 2019-10-14 15:01 UTC (permalink / raw)
To: ak, Jonathan.Cameron, Stable; +Cc: stable
The patch below does not apply to the 4.14-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 4043ecfb5fc4355a090111e14faf7945ff0fdbd5 Mon Sep 17 00:00:00 2001
From: Andreas Klinger <ak@it-klinger.de>
Date: Mon, 9 Sep 2019 14:37:21 +0200
Subject: [PATCH] iio: adc: hx711: fix bug in sampling of data
Fix bug in sampling function hx711_cycle() when interrupt occures while
PD_SCK is high. If PD_SCK is high for at least 60 us power down mode of
the sensor is entered which in turn leads to a wrong measurement.
Switch off interrupts during a PD_SCK high period and move query of DOUT
to the latest point of time which is at the end of PD_SCK low period.
This bug exists in the driver since it's initial addition. The more
interrupts on the system the higher is the probability that it happens.
Fixes: c3b2fdd0ea7e ("iio: adc: hx711: Add IIO driver for AVIA HX711")
Signed-off-by: Andreas Klinger <ak@it-klinger.de>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c
index 88c7fe15003b..62e6c8badd22 100644
--- a/drivers/iio/adc/hx711.c
+++ b/drivers/iio/adc/hx711.c
@@ -100,14 +100,14 @@ struct hx711_data {
static int hx711_cycle(struct hx711_data *hx711_data)
{
- int val;
+ unsigned long flags;
/*
* if preempted for more then 60us while PD_SCK is high:
* hx711 is going in reset
* ==> measuring is false
*/
- preempt_disable();
+ local_irq_save(flags);
gpiod_set_value(hx711_data->gpiod_pd_sck, 1);
/*
@@ -117,7 +117,6 @@ static int hx711_cycle(struct hx711_data *hx711_data)
*/
ndelay(hx711_data->data_ready_delay_ns);
- val = gpiod_get_value(hx711_data->gpiod_dout);
/*
* here we are not waiting for 0.2 us as suggested by the datasheet,
* because the oscilloscope showed in a test scenario
@@ -125,7 +124,7 @@ static int hx711_cycle(struct hx711_data *hx711_data)
* and 0.56 us for PD_SCK low on TI Sitara with 800 MHz
*/
gpiod_set_value(hx711_data->gpiod_pd_sck, 0);
- preempt_enable();
+ local_irq_restore(flags);
/*
* make it a square wave for addressing cases with capacitance on
@@ -133,7 +132,8 @@ static int hx711_cycle(struct hx711_data *hx711_data)
*/
ndelay(hx711_data->data_ready_delay_ns);
- return val;
+ /* sample as late as possible */
+ return gpiod_get_value(hx711_data->gpiod_dout);
}
static int hx711_read(struct hx711_data *hx711_data)
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: FAILED: patch "[PATCH] iio: adc: hx711: fix bug in sampling of data" failed to apply to 4.14-stable tree
2019-10-14 15:01 FAILED: patch "[PATCH] iio: adc: hx711: fix bug in sampling of data" failed to apply to 4.14-stable tree gregkh
@ 2019-10-15 0:57 ` Sasha Levin
0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2019-10-15 0:57 UTC (permalink / raw)
To: gregkh; +Cc: ak, Jonathan.Cameron, Stable
On Mon, Oct 14, 2019 at 05:01:26PM +0200, gregkh@linuxfoundation.org wrote:
>
>The patch below does not apply to the 4.14-stable tree.
>If someone wants it applied there, or to any other stable or longterm
>tree, then please email the backport, including the original git commit
>id to <stable@vger.kernel.org>.
>
>thanks,
>
>greg k-h
>
>------------------ original commit in Linus's tree ------------------
>
>From 4043ecfb5fc4355a090111e14faf7945ff0fdbd5 Mon Sep 17 00:00:00 2001
>From: Andreas Klinger <ak@it-klinger.de>
>Date: Mon, 9 Sep 2019 14:37:21 +0200
>Subject: [PATCH] iio: adc: hx711: fix bug in sampling of data
>
>Fix bug in sampling function hx711_cycle() when interrupt occures while
>PD_SCK is high. If PD_SCK is high for at least 60 us power down mode of
>the sensor is entered which in turn leads to a wrong measurement.
>
>Switch off interrupts during a PD_SCK high period and move query of DOUT
>to the latest point of time which is at the end of PD_SCK low period.
>
>This bug exists in the driver since it's initial addition. The more
>interrupts on the system the higher is the probability that it happens.
>
>Fixes: c3b2fdd0ea7e ("iio: adc: hx711: Add IIO driver for AVIA HX711")
>Signed-off-by: Andreas Klinger <ak@it-klinger.de>
>Cc: <Stable@vger.kernel.org>
>Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
I've queued up this patch in addition: 461631face580 ("iio: hx711: add
delay until DOUT is ready") and queued both for 4.14. It's not needed on
older kernels.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-10-15 0:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-14 15:01 FAILED: patch "[PATCH] iio: adc: hx711: fix bug in sampling of data" failed to apply to 4.14-stable tree gregkh
2019-10-15 0:57 ` Sasha Levin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.