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, andy@kernel.org
Subject: Re: [PATCH v4 1/5] gpiolib: cdev: relocate debounce_period_us from struct gpio_desc
Date: Tue, 19 Dec 2023 00:08:23 +0800	[thread overview]
Message-ID: <ZYBud4tobG3x9Zhh@rigel> (raw)
In-Reply-To: <CAMRc=MdKfs1ok2KgkO0C64cA9k8bOupxsjReBMQSdZbP+MQMCQ@mail.gmail.com>

On Mon, Dec 18, 2023 at 05:01:32PM +0100, Bartosz Golaszewski wrote:
> On Mon, Dec 18, 2023 at 4:40 PM Kent Gibson <warthog618@gmail.com> wrote:
> >
> > On Mon, Dec 18, 2023 at 04:24:50PM +0100, Bartosz Golaszewski wrote:
> > > On Sat, Dec 16, 2023 at 1:17 AM Kent Gibson <warthog618@gmail.com> wrote:
> > > >

> > > > +static void line_set_debounce_period(struct line *line,
> > > > +                                    unsigned int debounce_period_us)
> > > > +{
> > > > +       bool was_suppl = line_is_supplemental(line);
> > > > +
> > > > +       WRITE_ONCE(line->debounce_period_us, debounce_period_us);
> > > > +
> > > > +       if (line_is_supplemental(line) == was_suppl)
> > > > +               return;
> > > > +
> > > > +       if (was_suppl)
> > > > +               supinfo_erase(line);
> > > > +       else
> > > > +               supinfo_insert(line);
> > >
> > > Could you add a comment here saying it's called with the config mutex
> > > taken as at first glance it looks racy but actually isn't?
> > >
> >
> > Sure.  Though it is also covered by the gdev->sem you added, right?
> > So the config_mutex is now redundant?
> > Should I document it is covered by both?
> > Or drop the config_mutex entirely?
> >
>
> No! The semaphore is a read-write semaphore and we can have multiple
> readers at once. This semaphore only protects us from the chip being
> set to NULL during a system call. It will also go away once I get the
> descriptor access serialized (or not - I'm figuring out a lockless
> approach) and finally use SRCU to protect gdev->chip.
>

Ah, so it is.

> > And you wanted some comments to explain the logic?
> > I thought this is a common "has it changed" pattern, and so didn't
> > require additional explanation, but I guess not as common as I thought.
> >
>
> If line_set_debounce_period() could be called concurrently for the
> same line, this approach would be racy. It cannot but I want a comment
> here as I fear that if in the future we add some more attributes that
> constitute "supplemental info" and which may be changed outside of the
> config lock then this would in fact become racy.
>

If any line config is going to be changed from the userspace side then
it will be by the SET_CONFIG ioctl, and so be covered by the config_mutex,
but it can't hurt to explicitly document it here as well.

Cheers,
Kent.


  reply	other threads:[~2023-12-18 16:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-16  0:16 [PATCH v4 0/5] gpiolib: cdev: relocate debounce_period_us Kent Gibson
2023-12-16  0:16 ` [PATCH v4 1/5] gpiolib: cdev: relocate debounce_period_us from struct gpio_desc Kent Gibson
2023-12-18 15:24   ` Bartosz Golaszewski
2023-12-18 15:40     ` Kent Gibson
2023-12-18 16:01       ` Bartosz Golaszewski
2023-12-18 16:08         ` Kent Gibson [this message]
2023-12-16  0:16 ` [PATCH v4 2/5] gpiolib: remove " Kent Gibson
2023-12-16  0:16 ` [PATCH v4 3/5] gpiolib: cdev: reduce locking in gpio_desc_to_lineinfo() Kent Gibson
2023-12-16  0:16 ` [PATCH v4 4/5] gpiolib: cdev: fully adopt guard() and scoped_guard() Kent Gibson
2023-12-16  0:16 ` [PATCH v4 5/5] gpiolib: cdev: improve documentation of get/set values Kent Gibson
2023-12-18 15:26 ` [PATCH v4 0/5] gpiolib: cdev: relocate debounce_period_us 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=ZYBud4tobG3x9Zhh@rigel \
    --to=warthog618@gmail.com \
    --cc=andy@kernel.org \
    --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).