Skip to contentSkip to conversation

tools: gpio: fix -c option of gpio-event-mon

PATCH In review Ivo Borisov Shopov 3 participants 3 messages Jan 26, 2023 – Jan 27, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: gpio: fix -c option of gpio-event-mon

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")
---
 tools/gpio/gpio-event-mon.c | 1 +
 1 file changed, 1 insertion(+)
tools/gpio/gpio-event-mon.c +1 -0
index 6c122952c589..5dee2b98ab60 100644
@@ -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;
 
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · Ivo Borisov Shopov

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

Quoted 4 lines
    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/

Quoted 1 line

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

Very good explanation for the issue, thanks!

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

Quoted 21 lines
Fixes 62757c32d5db ("tools: gpio: add multi-line monitoring to gpio-event-mon")
---
 tools/gpio/gpio-event-mon.c | 1 +
 1 file changed, 1 insertion(+)
tools/gpio/gpio-event-mon.c +1 -1
index 6c122952c589..5dee2b98ab60 100644
@@ -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

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
In reply to Ivo Borisov Shopov
Quoted 44 lines · Ivo Borisov Shopov

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")
---
 tools/gpio/gpio-event-mon.c | 1 +
 1 file changed, 1 insertion(+)
tools/gpio/gpio-event-mon.c +1 -1
index 6c122952c589..5dee2b98ab60 100644
@@ -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;
 
--
Quoted 2 lines

2.20.1

Queued for fixes with the commit message tweaked.

Bart