linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kent Gibson <warthog618@gmail.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org,
	linus.walleij@linaro.org
Subject: Re: [PATCH 2/4] gpiolib: cdev: Ignore reconfiguration without direction
Date: Thu, 27 Jun 2024 22:22:48 +0800	[thread overview]
Message-ID: <20240627142248.GA414403@rigel> (raw)
In-Reply-To: <CAMRc=Me1_4xjbt51j+gFVzR71VUwMSAm+dT=UtgOY-1xYoAF5g@mail.gmail.com>

On Thu, Jun 27, 2024 at 04:06:21PM +0200, Bartosz Golaszewski wrote:
> On Wed, Jun 26, 2024 at 7:29 AM Kent Gibson <warthog618@gmail.com> wrote:
> >
> > linereq_set_config() behaves badly when direction is not set.
> > The configuration validation is borrowed from linereq_create(), where,
> > to verify the intent of the user, the direction must be set to in order to
> > effect a change to the electrical configuration of a line. But, when
> > applied to reconfiguration, that validation does not allow for the unset
> > direction case, making it possible to clear flags set previously without
> > specifying the line direction.
> >
> > Adding to the inconsistency, those changes are not immediately applied by
> > linereq_set_config(), but will take effect when the line value is next get
> > or set.
> >
> > For example, by requesting a configuration with no flags set, an output
> > line with GPIO_V2_LINE_FLAG_ACTIVE_LOW and GPIO_V2_LINE_FLAG_OPEN_DRAIN
> > set could have those flags cleared, inverting the sense of the line and
> > changing the line drive to push-pull on the next line value set.
> >
> > Skip the reconfiguration of lines for which the direction is not set, and
> > only reconfigure the lines for which direction is set.
> >
> > Fixes: a54756cb24ea ("gpiolib: cdev: support GPIO_V2_LINE_SET_CONFIG_IOCTL")
> > Signed-off-by: Kent Gibson <warthog618@gmail.com>
> > ---
> >  drivers/gpio/gpiolib-cdev.c | 12 +++++++-----
> >  1 file changed, 7 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
> > index f7a129d67b7d..ef08b23a56e2 100644
> > --- a/drivers/gpio/gpiolib-cdev.c
> > +++ b/drivers/gpio/gpiolib-cdev.c
> > @@ -1534,12 +1534,14 @@ static long linereq_set_config(struct linereq *lr, void __user *ip)
> >                 line = &lr->lines[i];
> >                 desc = lr->lines[i].desc;
> >                 flags = gpio_v2_line_config_flags(&lc, i);
> > +               /*
> > +                * Lines not explicitly reconfigured as input or output
> > +                * are left unchanged.
> > +                */
> > +               if (!(flags & GPIO_V2_LINE_DIRECTION_FLAGS))
> > +                       continue;
>
> Series looks good, thanks. I'd say that this bit here calls for at
> least a debug-level message since we don't return an error unlike v1.
> What do you think?
>

The change to the libgpiod Python bindings makes use of this to support
reconfiguration of subsets, so on its own it isn't an abnormal path and
I'm not sure it warrants even a debug.

OTOH, I did consider if there should be a check that at least one line
in the reconfig has a direction, returning an error if there are none, but
was on the fence about it and left it out as it added complexity.

Would that make more sense?
Or do you have a problem with reconfiguring subsets?

Cheers,
Kent.

  reply	other threads:[~2024-06-27 14:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-26  5:29 [PATCH 0/4] gpiolib: cdev: directionless line reconfiguration Kent Gibson
2024-06-26  5:29 ` [PATCH 1/4] gpiolib: cdev: Disallow reconfiguration without direction (uAPI v1) Kent Gibson
2024-06-26  5:29 ` [PATCH 2/4] gpiolib: cdev: Ignore reconfiguration without direction Kent Gibson
2024-06-27 14:06   ` Bartosz Golaszewski
2024-06-27 14:22     ` Kent Gibson [this message]
2024-06-27 14:44       ` Bartosz Golaszewski
2024-06-27 14:49         ` Kent Gibson
2024-06-27 14:51           ` Bartosz Golaszewski
2024-06-26  5:29 ` [PATCH 3/4] Documentation: gpio: Reconfiguration with unset direction (uAPI v1) Kent Gibson
2024-06-26  5:29 ` [PATCH 4/4] Documentation: gpio: Reconfiguration with unset direction (uAPI v2) Kent Gibson
2024-06-27 15:23 ` [PATCH 0/4] gpiolib: cdev: directionless line reconfiguration Bartosz Golaszewski
2024-07-01  7:39 ` Bartosz Golaszewski

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=20240627142248.GA414403@rigel \
    --to=warthog618@gmail.com \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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).