diff mbox series

tools: gpio: fix debounce_period_us output of lsgpio

Message ID 20230504092217.484339-1-milo.spadacini@comelit.it
State New
Headers show
Series tools: gpio: fix debounce_period_us output of lsgpio | expand

Commit Message

Milo Spadacini May 4, 2023, 9:22 a.m. UTC
Fix wrong output that could occurs when more attributes are used and
 GPIO_V2_LINE_ATTR_ID_DEBOUNCE is not the first one.
---
 tools/gpio/lsgpio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--
2.34.1

[https://www.comelitgroup.com/firma/banner.jpg]<https://www.comelitgroup.com/it-it/cctv-advance-la-nuova-gamma-di-videosorveglianza-professionale-di-comelit>

NORME DI ACCESSO E DI COMPORTAMENTO PER ESTERNI<https://www.comelitgroup.com/it-it/norme-accesso-comportamento-esterni>

AVVISO DI CONFIDENZIALITÀ E PRIVACY
Questo messaggio ed i suoi eventuali allegati possono contenere informazioni confidenziali, di proprietà, legalmente protette. È destinato all'utilizzo esclusivo del destinatario sopra indicato; la natura privata e la confidenzialità non sono modificati da eventuali errori di trasmissione, pur avendo il mittente assunto tutte le misure di sicurezza idonee e preventive per evitarli. Il trattamento dei dati ivi contenuti, e quelli che verranno forniti in risposta, è realizzato in conformità alla normativa sulla privacy Reg 679/2016, potrete prendere visione della informativa anche visitando il sito www.comelitgroup.com ovvero sulle app Comelit. Rispondendo alla presente mail dichiarate di aver preso visione della richiamata informativa e di aver prestato il consenso al trattamento dei dati personali. Se il messaggio non è a lei destinato, non deve utilizzarlo, diffonderlo, copiarlo con qualunque mezzo, o intraprendere azioni basandosi su di esso. Se ha ricevuto questo messaggio per errore, la preghiamo di volerlo distruggere (unitamente ad eventuali copie dello stesso e suoi allegati) e di volerci cortesemente informare del fatto scrivendo al mittente.
CONFIDENTIALITY NOTICE AND PRIVACY
This message and its attachments (if any) may contain confidential, proprietary or legally privileged information and it is intended only for the use of the addressee named above. No confidentiality or privilege is waived or lost by any erroneous transmission, despite having taken all the security and preventative measures to avoid it. The processing of personal data contained therein, and those that will be provided in response, is made in compliance with the privacy regulation Reg 679/2016, you can also read the information by visiting www.comelitgroup.com or on Comelit apps. Responding to this email, you declare that you have read the aforementioned information and have given consent to the processing of personal data If you are not the intended recipient of this message, you are hereby notified that you must not use, disseminate, copy it in any form or take any action in reliance on it. If you have received this message in error, please, delete it (and any copies of it and attachment) and kindly inform the sender.

Comments

Kent Gibson May 4, 2023, 1:48 p.m. UTC | #1
On Thu, May 04, 2023 at 11:22:17AM +0200, Milo Spadacini wrote:
> Fix wrong output that could occurs when more attributes are used and

      incorrect output        occur


>  GPIO_V2_LINE_ATTR_ID_DEBOUNCE is not the first one.

Have you actually seen this fault occur anywhere?  I would expect not,
as the debounce_period is the ONLY attr that is returned in practice by
existing kernels. The flags and values attributes are never returned in
the attrs of the gpio_v2_line_info - the flags are returned in their own
field, as they are always present, and the values are not returned in
the info at all.  Those types may be used in the request for multple
lines, but are not returned in the attrs for a single line.

> ---
>  tools/gpio/lsgpio.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/gpio/lsgpio.c b/tools/gpio/lsgpio.c
> index c61d061247e1..52a0be45410c 100644
> --- a/tools/gpio/lsgpio.c
> +++ b/tools/gpio/lsgpio.c
> @@ -94,7 +94,7 @@ static void print_attributes(struct gpio_v2_line_info *info)
>         for (i = 0; i < info->num_attrs; i++) {
>                 if (info->attrs[i].id == GPIO_V2_LINE_ATTR_ID_DEBOUNCE)
>                         fprintf(stdout, ", debounce_period=%dusec",
> -                               info->attrs[0].debounce_period_us);
> +                               info->attrs[i].debounce_period_us);
>         }
>  }
> 

The fix itself is ok for debounce, so no issue with that.

But if there are multiple attributes, as you suggest in your comment,
then how about printing the rest of them rather than omitting them?
So perhaps replace this with an exhaustive decoder for all possible
attributes - probably implemented as a switch on the id and include a
"what the??" for the default case?
The flags and values types could be covered by the default, given we
don't expect them, but if so then add a comment to that effect.

Cheers,
Kent.
Andy Shevchenko May 4, 2023, 4:20 p.m. UTC | #2
Thu, May 04, 2023 at 11:22:17AM +0200, Milo Spadacini kirjoitti:

...

> NORME DI ACCESSO E DI COMPORTAMENTO PER ESTERNI<https://www.comelitgroup.com/it-it/norme-accesso-comportamento-esterni>
> 
> AVVISO DI CONFIDENZIALIT? E PRIVACY
> Questo messaggio ed i suoi eventuali allegati possono contenere informazioni confidenziali, di propriet?, legalmente protette. ? destinato all'utilizzo esclusivo del destinatario sopra indicato; la natura privata e la confidenzialit? non sono modificati da eventuali errori di trasmissione, pur avendo il mittente assunto tutte le misure di sicurezza idonee e preventive per evitarli. Il trattamento dei dati ivi contenuti, e quelli che verranno forniti in risposta, ? realizzato in conformit? alla normativa sulla privacy Reg 679/2016, potrete prendere visione della informativa anche visitando il sito www.comelitgroup.com ovvero sulle app Comelit. Rispondendo alla presente mail dichiarate di aver preso visione della richiamata informativa e di aver prestato il consenso al trattamento dei dati personali. Se il messaggio non ? a lei destinato, non deve utilizzarlo, diffonderlo, copiarlo con qualunque mezzo, o intraprendere azioni basandosi su di esso. Se ha ricevuto questo messaggio per errore, la preghiamo di volerlo distruggere (unitamente ad eventuali copie dello stesso e suoi allegati) e di volerci cortesemente informare del fatto scrivendo al mittente.
> CONFIDENTIALITY NOTICE AND PRIVACY
> This message and its attachments (if any) may contain confidential, proprietary or legally privileged information and it is intended only for the use of the addressee named above. No confidentiality or privilege is waived or lost by any erroneous transmission, despite having taken all the security and preventative measures to avoid it. The processing of personal data contained therein, and those that will be provided in response, is made in compliance with the privacy regulation Reg 679/2016, you can also read the information by visiting www.comelitgroup.com or on Comelit apps. Responding to this email, you declare that you have read the aforementioned information and have given consent to the processing of personal data If you are not the intended recipient of this message, you are hereby notified that you must not use, disseminate, copy it in any form or take any action in reliance on it. If you have received this message in error, please, delete it (and any copies of it and attachment) and kindly inform the sender.

With this footer we may not accept the change, sorry.
You have to remove it.
diff mbox series

Patch

diff --git a/tools/gpio/lsgpio.c b/tools/gpio/lsgpio.c
index c61d061247e1..52a0be45410c 100644
--- a/tools/gpio/lsgpio.c
+++ b/tools/gpio/lsgpio.c
@@ -94,7 +94,7 @@  static void print_attributes(struct gpio_v2_line_info *info)
        for (i = 0; i < info->num_attrs; i++) {
                if (info->attrs[i].id == GPIO_V2_LINE_ATTR_ID_DEBOUNCE)
                        fprintf(stdout, ", debounce_period=%dusec",
-                               info->attrs[0].debounce_period_us);
+                               info->attrs[i].debounce_period_us);
        }
 }