linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpiolib: skip unwanted events, don't convert them to opposite edge
@ 2017-07-03  9:12 Bartosz Golaszewski
  2017-07-03 11:07 ` Andy Shevchenko
  2017-08-01 12:08 ` Linus Walleij
  0 siblings, 2 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2017-07-03  9:12 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

The previous fix for filtering out of unwatched events was not entirely
correct. Instead of skipping the events we don't want, they are now
interpreted as events with opposing edge.

In order to fix it: always read the GPIO line value on interrupt and
only emit the event if it corresponds with the event type we requested.

Fixes: ad537b822577 ("gpiolib: fix filtering out unwanted events")
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
Hi Linus,

I tested my previous fix on a real board, where I got a storm of
interrupts from simply playing with a GPIO manually. It looked ok so I
posted the patch, but I didn't notice that when waiting for rising-edge
events, all falling-edge events got interpreted as such. This patch
should actually fix this bug. Tested carefully with gpio-mockup this
time.

 drivers/gpio/gpiolib.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index a42a1ee..2e96b3d 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -704,24 +704,23 @@ static irqreturn_t lineevent_irq_thread(int irq, void *p)
 {
 	struct lineevent_state *le = p;
 	struct gpioevent_data ge;
-	int ret;
+	int ret, level;
 
 	ge.timestamp = ktime_get_real_ns();
+	level = gpiod_get_value_cansleep(le->desc);
 
 	if (le->eflags & GPIOEVENT_REQUEST_RISING_EDGE
 	    && le->eflags & GPIOEVENT_REQUEST_FALLING_EDGE) {
-		int level = gpiod_get_value_cansleep(le->desc);
-
 		if (level)
 			/* Emit low-to-high event */
 			ge.id = GPIOEVENT_EVENT_RISING_EDGE;
 		else
 			/* Emit high-to-low event */
 			ge.id = GPIOEVENT_EVENT_FALLING_EDGE;
-	} else if (le->eflags & GPIOEVENT_REQUEST_RISING_EDGE) {
+	} else if (le->eflags & GPIOEVENT_REQUEST_RISING_EDGE && level) {
 		/* Emit low-to-high event */
 		ge.id = GPIOEVENT_EVENT_RISING_EDGE;
-	} else if (le->eflags & GPIOEVENT_REQUEST_FALLING_EDGE) {
+	} else if (le->eflags & GPIOEVENT_REQUEST_FALLING_EDGE && !level) {
 		/* Emit high-to-low event */
 		ge.id = GPIOEVENT_EVENT_FALLING_EDGE;
 	} else {
-- 
2.9.3

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

* Re: [PATCH] gpiolib: skip unwanted events, don't convert them to opposite edge
  2017-07-03  9:12 [PATCH] gpiolib: skip unwanted events, don't convert them to opposite edge Bartosz Golaszewski
@ 2017-07-03 11:07 ` Andy Shevchenko
  2017-07-04 14:27   ` Bartosz Golaszewski
  2017-08-01 12:08 ` Linus Walleij
  1 sibling, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2017-07-03 11:07 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: Linus Walleij, linux-gpio, linux-kernel

On Mon, Jul 3, 2017 at 12:12 PM, Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> The previous fix for filtering out of unwatched events was not entirely
> correct. Instead of skipping the events we don't want, they are now
> interpreted as events with opposing edge.
>
> In order to fix it: always read the GPIO line value on interrupt and
> only emit the event if it corresponds with the event type we requested.

>         struct lineevent_state *le = p;
>         struct gpioevent_data ge;
> -       int ret;
> +       int ret, level;

I prefer
int level;
int ret;

Though it's matter of taste (I don't remember which one Linus' preferable).

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH] gpiolib: skip unwanted events, don't convert them to opposite edge
  2017-07-03 11:07 ` Andy Shevchenko
@ 2017-07-04 14:27   ` Bartosz Golaszewski
  0 siblings, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2017-07-04 14:27 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Linus Walleij, linux-gpio, linux-kernel

2017-07-03 13:07 GMT+02:00 Andy Shevchenko <andy.shevchenko@gmail.com>:
> On Mon, Jul 3, 2017 at 12:12 PM, Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>> The previous fix for filtering out of unwatched events was not entirely
>> correct. Instead of skipping the events we don't want, they are now
>> interpreted as events with opposing edge.
>>
>> In order to fix it: always read the GPIO line value on interrupt and
>> only emit the event if it corresponds with the event type we requested.
>
>>         struct lineevent_state *le = p;
>>         struct gpioevent_data ge;
>> -       int ret;
>> +       int ret, level;
>
> I prefer
> int level;
> int ret;
>
> Though it's matter of taste (I don't remember which one Linus' preferable).
>
> --
> With Best Regards,
> Andy Shevchenko

Hard to tell, the file uses both styles.

Thanks,
Bartosz

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

* Re: [PATCH] gpiolib: skip unwanted events, don't convert them to opposite edge
  2017-07-03  9:12 [PATCH] gpiolib: skip unwanted events, don't convert them to opposite edge Bartosz Golaszewski
  2017-07-03 11:07 ` Andy Shevchenko
@ 2017-08-01 12:08 ` Linus Walleij
  1 sibling, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2017-08-01 12:08 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: linux-gpio, linux-kernel

On Mon, Jul 3, 2017 at 11:12 AM, Bartosz Golaszewski <brgl@bgdev.pl> wrote:

> The previous fix for filtering out of unwatched events was not entirely
> correct. Instead of skipping the events we don't want, they are now
> interpreted as events with opposing edge.
>
> In order to fix it: always read the GPIO line value on interrupt and
> only emit the event if it corresponds with the event type we requested.
>
> Fixes: ad537b822577 ("gpiolib: fix filtering out unwanted events")
> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
> ---
> Hi Linus,
>
> I tested my previous fix on a real board, where I got a storm of
> interrupts from simply playing with a GPIO manually. It looked ok so I
> posted the patch, but I didn't notice that when waiting for rising-edge
> events, all falling-edge events got interpreted as such. This patch
> should actually fix this bug. Tested carefully with gpio-mockup this
> time.

Patrch applied for fixes and tagged for stable.

Yours,
Linus Walleij

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

end of thread, other threads:[~2017-08-01 12:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-03  9:12 [PATCH] gpiolib: skip unwanted events, don't convert them to opposite edge Bartosz Golaszewski
2017-07-03 11:07 ` Andy Shevchenko
2017-07-04 14:27   ` Bartosz Golaszewski
2017-08-01 12:08 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).