All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: proximity: as3935: fix iio_trigger_poll issue
@ 2017-05-05  0:32 Matt Ranostay
  2017-05-07 12:21 ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Matt Ranostay @ 2017-05-05  0:32 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Matt Ranostay, stable

Using iio_trigger_poll() can oops when multiple interrupts
happen before the first is handled.

Use iio_trigger_poll_chained() instead and use the timestamp
when processed, since it will be in theory be 2 ms max latency.

Fixes: 24ddb0e4bba4 ("iio: Add AS3935 lightning sensor support")
Cc: stable@vger.kernel.org
Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
---
 drivers/iio/proximity/as3935.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c
index ddf9bee89f77..d98d38227f26 100644
--- a/drivers/iio/proximity/as3935.c
+++ b/drivers/iio/proximity/as3935.c
@@ -215,7 +215,7 @@ static irqreturn_t as3935_trigger_handler(int irq, void *private)
 
 	st->buffer[0] = val & AS3935_DATA_MASK;
 	iio_push_to_buffers_with_timestamp(indio_dev, &st->buffer,
-					   pf->timestamp);
+					   iio_get_time_ns(indio_dev));
 err_read:
 	iio_trigger_notify_done(indio_dev->trig);
 
@@ -244,7 +244,7 @@ static void as3935_event_work(struct work_struct *work)
 
 	switch (val) {
 	case AS3935_EVENT_INT:
-		iio_trigger_poll(st->trig);
+		iio_trigger_poll_chained(st->trig);
 		break;
 	case AS3935_NOISE_INT:
 		dev_warn(&st->spi->dev, "noise level is too high\n");
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: proximity: as3935: fix iio_trigger_poll issue
  2017-05-05  0:32 [PATCH] iio: proximity: as3935: fix iio_trigger_poll issue Matt Ranostay
@ 2017-05-07 12:21 ` Jonathan Cameron
  2017-05-07 23:58   ` Matt Ranostay
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2017-05-07 12:21 UTC (permalink / raw)
  To: Matt Ranostay; +Cc: linux-iio, stable

On 05/05/17 01:32, Matt Ranostay wrote:
> Using iio_trigger_poll() can oops when multiple interrupts
> happen before the first is handled.
> 
Ah. I see. This should cause all sorts of trouble and warnings.

It's calling the irq_chip infrastructure without going through the
dance necessary to make that happen from an irq context.

This is indeed the simplest fix.

Jonathan
> Use iio_trigger_poll_chained() instead and use the timestamp
> when processed, since it will be in theory be 2 ms max latency.
> 
> Fixes: 24ddb0e4bba4 ("iio: Add AS3935 lightning sensor support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
> ---
>  drivers/iio/proximity/as3935.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c
> index ddf9bee89f77..d98d38227f26 100644
> --- a/drivers/iio/proximity/as3935.c
> +++ b/drivers/iio/proximity/as3935.c
> @@ -215,7 +215,7 @@ static irqreturn_t as3935_trigger_handler(int irq, void *private)
>  
>  	st->buffer[0] = val & AS3935_DATA_MASK;
>  	iio_push_to_buffers_with_timestamp(indio_dev, &st->buffer,
> -					   pf->timestamp);
> +					   iio_get_time_ns(indio_dev));
>  err_read:
>  	iio_trigger_notify_done(indio_dev->trig);
>  
> @@ -244,7 +244,7 @@ static void as3935_event_work(struct work_struct *work)
>  
>  	switch (val) {
>  	case AS3935_EVENT_INT:
> -		iio_trigger_poll(st->trig);
> +		iio_trigger_poll_chained(st->trig);
>  		break;
>  	case AS3935_NOISE_INT:
>  		dev_warn(&st->spi->dev, "noise level is too high\n");
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: proximity: as3935: fix iio_trigger_poll issue
  2017-05-07 12:21 ` Jonathan Cameron
@ 2017-05-07 23:58   ` Matt Ranostay
  0 siblings, 0 replies; 3+ messages in thread
From: Matt Ranostay @ 2017-05-07 23:58 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: open list:IIO SUBSYSTEM AND..., stable

On Sun, May 7, 2017 at 5:21 AM, Jonathan Cameron <jic23@kernel.org> wrote:
> On 05/05/17 01:32, Matt Ranostay wrote:
>> Using iio_trigger_poll() can oops when multiple interrupts
>> happen before the first is handled.
>>
> Ah. I see. This should cause all sorts of trouble and warnings.
>
> It's calling the irq_chip infrastructure without going through the
> dance necessary to make that happen from an irq context.
>
> This is indeed the simplest fix.

Yeah only saw this because of a lightning storm last week (which never
happens here :)).

- Matt

>
> Jonathan
>> Use iio_trigger_poll_chained() instead and use the timestamp
>> when processed, since it will be in theory be 2 ms max latency.
>>
>> Fixes: 24ddb0e4bba4 ("iio: Add AS3935 lightning sensor support")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
>> ---
>>  drivers/iio/proximity/as3935.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c
>> index ddf9bee89f77..d98d38227f26 100644
>> --- a/drivers/iio/proximity/as3935.c
>> +++ b/drivers/iio/proximity/as3935.c
>> @@ -215,7 +215,7 @@ static irqreturn_t as3935_trigger_handler(int irq, void *private)
>>
>>       st->buffer[0] = val & AS3935_DATA_MASK;
>>       iio_push_to_buffers_with_timestamp(indio_dev, &st->buffer,
>> -                                        pf->timestamp);
>> +                                        iio_get_time_ns(indio_dev));
>>  err_read:
>>       iio_trigger_notify_done(indio_dev->trig);
>>
>> @@ -244,7 +244,7 @@ static void as3935_event_work(struct work_struct *work)
>>
>>       switch (val) {
>>       case AS3935_EVENT_INT:
>> -             iio_trigger_poll(st->trig);
>> +             iio_trigger_poll_chained(st->trig);
>>               break;
>>       case AS3935_NOISE_INT:
>>               dev_warn(&st->spi->dev, "noise level is too high\n");
>>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-05-07 23:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-05  0:32 [PATCH] iio: proximity: as3935: fix iio_trigger_poll issue Matt Ranostay
2017-05-07 12:21 ` Jonathan Cameron
2017-05-07 23:58   ` Matt Ranostay

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.