linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kent Gibson <warthog618@gmail.com>
To: Milo Spadacini <milo.spadacini@comelit.it>
Cc: linus.walleij@linaro.org, brgl@bgdev.pl, linux-gpio@vger.kernel.org
Subject: Re: [PATCH] tools: gpio: fix debounce_period_us output of lsgpio
Date: Thu, 4 May 2023 21:48:33 +0800	[thread overview]
Message-ID: <ZFO3sXP3SXiCzI+c@sol> (raw)
In-Reply-To: <20230504092217.484339-1-milo.spadacini@comelit.it>

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.

  reply	other threads:[~2023-05-04 13:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-04  9:22 [PATCH] tools: gpio: fix debounce_period_us output of lsgpio Milo Spadacini
2023-05-04 13:48 ` Kent Gibson [this message]
2023-05-04 16:20 ` andy.shevchenko
     [not found] <CA+1hoUVnw7kXB15rzK=tQdX2cyGMoXEgThOiqA=pYDwqF6TAwQ@mail.gmail.com>
2023-05-05 11:32 ` Linus Walleij
2023-05-05 14:18   ` Kent Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZFO3sXP3SXiCzI+c@sol \
    --to=warthog618@gmail.com \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=milo.spadacini@comelit.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).