mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] tools: gpio: fix -c option of gpio-event-mon
@ 2023-01-26 13:10 Ivo Borisov Shopov
  2023-01-26 13:26 ` Andy Shevchenko
  2023-01-27 10:15 ` Bartosz Golaszewski
  0 siblings, 2 replies; 3+ messages in thread
From: Ivo Borisov Shopov @ 2023-01-26 13:10 UTC (permalink / raw)
  To: Linus Walleij
  Cc: ivoshopov, Bartosz Golaszewski, Andy Shevchenko, Kent Gibson,
	linux-gpio, linux-kernel

Following line should listen for a rising edge and exit after the first
one since '-c 1' is provided.

    # gpio-event-mon -n gpiochip1 -o 0 -r -c 1

It works with kernel 4.19 but it doesn't work with 5.10. In 5.10 the
above command doesn't exit after the first rising edge it keep listening
for an event forever. The '-c 1' is not taken into an account.
The problem is in commit 62757c32d5db ("tools: gpio: add multi-line
monitoring to gpio-event-mon").
Before this commit the iterator 'i' in monitor_device() is used for
counting of the events (loops). In the case of the above command (-c 1)
we should start from 0 and increment 'i' only ones and hit the 'break'
statement and exit the process. But after the above commit counting
doesn't start from 0, it start from 1 when we listen on one line.
It is because 'i' is used from one more purpose, counting of lines
(num_lines) and it isn't restore to 0 after following code

    for (i = 0; i < num_lines; i++)
        gpiotools_set_bit(&values.mask, i);

This patch just restore the initial value of the iterator to 0 in
order to allow counting of loops to work for any cases.

Fixes: 62757c32d5db ("tools: gpio: add multi-line monitoring to gpio-event-mon")
Signed-off-by: Ivo Borisov Shopov <ivoshopov@gmail.com>
---
 tools/gpio/gpio-event-mon.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/gpio/gpio-event-mon.c b/tools/gpio/gpio-event-mon.c
index 6c122952c589..5dee2b98ab60 100644
--- a/tools/gpio/gpio-event-mon.c
+++ b/tools/gpio/gpio-event-mon.c
@@ -86,6 +86,7 @@ int monitor_device(const char *device_name,
 			gpiotools_test_bit(values.bits, i));
 	}
 
+	i = 0;
 	while (1) {
 		struct gpio_v2_line_event event;
 
-- 
2.20.1


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

* Re: [PATCH] tools: gpio: fix -c option of gpio-event-mon
  2023-01-26 13:10 [PATCH] tools: gpio: fix -c option of gpio-event-mon Ivo Borisov Shopov
@ 2023-01-26 13:26 ` Andy Shevchenko
  2023-01-27 10:15 ` Bartosz Golaszewski
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2023-01-26 13:26 UTC (permalink / raw)
  To: Ivo Borisov Shopov
  Cc: Linus Walleij, Bartosz Golaszewski, Kent Gibson, linux-gpio,
	linux-kernel

On Thu, Jan 26, 2023 at 3:11 PM Ivo Borisov Shopov <ivoshopov@gmail.com> wrote:
>
> Following line should listen for a rising edge and exit after the first
> one since '-c 1' is provided.
>
>     # gpio-event-mon -n gpiochip1 -o 0 -r -c 1
>
> It works with kernel 4.19 but it doesn't work with 5.10. In 5.10 the
> above command doesn't exit after the first rising edge it keep listening
> for an event forever. The '-c 1' is not taken into an account.
> The problem is in commit 62757c32d5db ("tools: gpio: add multi-line
> monitoring to gpio-event-mon").
> Before this commit the iterator 'i' in monitor_device() is used for
> counting of the events (loops). In the case of the above command (-c 1)
> we should start from 0 and increment 'i' only ones and hit the 'break'
> statement and exit the process. But after the above commit counting
> doesn't start from 0, it start from 1 when we listen on one line.
> It is because 'i' is used from one more purpose, counting of lines
> (num_lines) and it isn't restore to 0 after following code
>
>     for (i = 0; i < num_lines; i++)
>         gpiotools_set_bit(&values.mask, i);
>
> This patch just restore the initial value of the iterator to 0 in

s/This patch just restore/Restore/

> order to allow counting of loops to work for any cases.

Very good explanation for the issue, thanks!
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

P.S. No need to resend to address above, I think Bart can amend that
when applying.

> Fixes: 62757c32d5db ("tools: gpio: add multi-line monitoring to gpio-event-mon")
> Signed-off-by: Ivo Borisov Shopov <ivoshopov@gmail.com>
> ---
>  tools/gpio/gpio-event-mon.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/tools/gpio/gpio-event-mon.c b/tools/gpio/gpio-event-mon.c
> index 6c122952c589..5dee2b98ab60 100644
> --- a/tools/gpio/gpio-event-mon.c
> +++ b/tools/gpio/gpio-event-mon.c
> @@ -86,6 +86,7 @@ int monitor_device(const char *device_name,
>                         gpiotools_test_bit(values.bits, i));
>         }
>
> +       i = 0;
>         while (1) {
>                 struct gpio_v2_line_event event;
>
> --
> 2.20.1
>


-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH] tools: gpio: fix -c option of gpio-event-mon
  2023-01-26 13:10 [PATCH] tools: gpio: fix -c option of gpio-event-mon Ivo Borisov Shopov
  2023-01-26 13:26 ` Andy Shevchenko
@ 2023-01-27 10:15 ` Bartosz Golaszewski
  1 sibling, 0 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2023-01-27 10:15 UTC (permalink / raw)
  To: Ivo Borisov Shopov
  Cc: Linus Walleij, Andy Shevchenko, Kent Gibson, linux-gpio, linux-kernel

On Thu, Jan 26, 2023 at 2:11 PM Ivo Borisov Shopov <ivoshopov@gmail.com> wrote:
>
> Following line should listen for a rising edge and exit after the first
> one since '-c 1' is provided.
>
>     # gpio-event-mon -n gpiochip1 -o 0 -r -c 1
>
> It works with kernel 4.19 but it doesn't work with 5.10. In 5.10 the
> above command doesn't exit after the first rising edge it keep listening
> for an event forever. The '-c 1' is not taken into an account.
> The problem is in commit 62757c32d5db ("tools: gpio: add multi-line
> monitoring to gpio-event-mon").
> Before this commit the iterator 'i' in monitor_device() is used for
> counting of the events (loops). In the case of the above command (-c 1)
> we should start from 0 and increment 'i' only ones and hit the 'break'
> statement and exit the process. But after the above commit counting
> doesn't start from 0, it start from 1 when we listen on one line.
> It is because 'i' is used from one more purpose, counting of lines
> (num_lines) and it isn't restore to 0 after following code
>
>     for (i = 0; i < num_lines; i++)
>         gpiotools_set_bit(&values.mask, i);
>
> This patch just restore the initial value of the iterator to 0 in
> order to allow counting of loops to work for any cases.
>
> Fixes: 62757c32d5db ("tools: gpio: add multi-line monitoring to gpio-event-mon")
> Signed-off-by: Ivo Borisov Shopov <ivoshopov@gmail.com>
> ---
>  tools/gpio/gpio-event-mon.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/tools/gpio/gpio-event-mon.c b/tools/gpio/gpio-event-mon.c
> index 6c122952c589..5dee2b98ab60 100644
> --- a/tools/gpio/gpio-event-mon.c
> +++ b/tools/gpio/gpio-event-mon.c
> @@ -86,6 +86,7 @@ int monitor_device(const char *device_name,
>                         gpiotools_test_bit(values.bits, i));
>         }
>
> +       i = 0;
>         while (1) {
>                 struct gpio_v2_line_event event;
>
> --
> 2.20.1
>

Queued for fixes with the commit message tweaked.

Bart

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

end of thread, other threads:[~2023-01-27 10:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-26 13:10 [PATCH] tools: gpio: fix -c option of gpio-event-mon Ivo Borisov Shopov
2023-01-26 13:26 ` Andy Shevchenko
2023-01-27 10:15 ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®