linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/5] gpiolib: cdev: relocate debounce_period_us
@ 2023-12-14  9:58 Kent Gibson
  2023-12-14  9:58 ` [PATCH v2 1/5] gpiolib: cdev: adopt scoped_guard() Kent Gibson
                   ` (4 more replies)
  0 siblings, 5 replies; 38+ messages in thread
From: Kent Gibson @ 2023-12-14  9:58 UTC (permalink / raw)
  To: linux-kernel, linux-gpio, brgl, linus.walleij, andy; +Cc: Kent Gibson

This series contains minor improvements to gpiolib-cdev.

Patch 1 replaces discrete lock/unlock calls around critical sections
with scoped_guard().  Excludes desc_gpio_to_lineinfo() as delaying
the change until patch 4 produces a cleaner change.

The banner change is relocating the debounce_period_us from gpiolib's
struct gpio_desc to cdev's struct line.  Patch 2 stores the field
locally in cdev.  Patch 3 removes the now unused field from gpiolib.

Patch 4 is somewhat related and removes a FIXME from
gpio_desc_to_lineinfo().  The FIXME relates to a race condition in
the calculation of the used  flag, but I would assert that from
the userspace perspective the read operation itself is inherently racy.
The line being reported as unused in the info provides no guarantee -
it just an indicator that requesting the line is likely to succeed -
assuming the line is not otherwise requested in the meantime.
Give the overall operation is racy, trying to stamp out an unlikely
race within the operation is pointless. Accept it as a possibility
that has negligible side-effects and reduce the number of locks held
simultaneously and the duration that the gpio_lock is held.

Patch 5 is unrelated to debounce or info, but addresses Andy's
recent complaint that the linereq get/set values functions are
confusing and under documented.
Figured I may as well add that while I was in there.

Changes v1 -> v2:
 (changes are to patch 2 unless otherwise noted)
 - adopt scoped_guard() for critical sections, inserting patch 1 and
   updating patch 2 and 4.
 - move rb_node field to beginning of struct line.
 - merge struct supinfo into supinfo var declaration.
 - move rb_tree field to beginning of struct supinfo.
 - replace pr_warn() with WARN().
 - drop explicit int to bool conversion in line_is_supplemental().
 - use continue to bypass cleanup in linereq_free().
 - fix typo in commit message (patch 4)

Kent Gibson (5):
  gpiolib: cdev: adopt scoped_guard()
  gpiolib: cdev: relocate debounce_period_us from struct gpio_desc
  gpiolib: remove debounce_period_us from struct gpio_desc
  gpiolib: cdev: reduce locking in gpio_desc_to_lineinfo()
  gpiolib: cdev: improve documentation of get/set values

 drivers/gpio/gpiolib-cdev.c | 403 +++++++++++++++++++++++-------------
 drivers/gpio/gpiolib.c      |   3 -
 drivers/gpio/gpiolib.h      |   5 -
 3 files changed, 260 insertions(+), 151 deletions(-)

--
2.39.2


^ permalink raw reply	[flat|nested] 38+ messages in thread
* Re: [PATCH v2 2/5] gpiolib: cdev: relocate debounce_period_us from struct gpio_desc
@ 2023-12-14 16:46 Andy Shevchenko
  2023-12-14 21:05 ` Bartosz Golaszewski
  0 siblings, 1 reply; 38+ messages in thread
From: Andy Shevchenko @ 2023-12-14 16:46 UTC (permalink / raw)
  To: Kent Gibson; +Cc: Bartosz Golaszewski, linux-kernel, linux-gpio, linus.walleij


On Thu, Dec 14, 2023 at 11:08:05PM +0800, Kent Gibson wrote:
> On Thu, Dec 14, 2023 at 03:56:37PM +0100, Bartosz Golaszewski wrote:

...

> While I think of it, what tree should I be basing on?
> These patches are based on v6.7-rc5, and I'm not aware of any other
> changes they may contend with, but best to be on the right tree to be
> sure.

General rule is to base on the target subsystem tree. In this case
it's Bart's gpio/for-next AFAIU.

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 38+ messages in thread
* Re: [PATCH v2 2/5] gpiolib: cdev: relocate debounce_period_us from struct gpio_desc
@ 2023-12-15 20:23 Andy Shevchenko
  0 siblings, 0 replies; 38+ messages in thread
From: Andy Shevchenko @ 2023-12-15 20:23 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: Kent Gibson, linux-kernel, linux-gpio, linus.walleij

On Thu, Dec 14, 2023 at 10:06:14PM +0100, Bartosz Golaszewski wrote:
> On Thu, Dec 14, 2023 at 5:41 PM Andy Shevchenko <andy@kernel.org> wrote:
> > On Fri, Dec 15, 2023 at 12:14:41AM +0800, Kent Gibson wrote:
> > > On Thu, Dec 14, 2023 at 05:09:01PM +0200, Andy Shevchenko wrote:
> > > > On Thu, Dec 14, 2023 at 05:03:03PM +0200, Andy Shevchenko wrote:
> > > > > On Thu, Dec 14, 2023 at 05:58:11PM +0800, Kent Gibson wrote:

...

> > > > > > +static void supinfo_init(void)
> > > > > > +{
> > > > > > +       supinfo.tree = RB_ROOT;
> > > > > > +       spin_lock_init(&supinfo.lock);
> > > > > > +}
> > > > >
> > > > > Can it be done statically?
> > > > >
> > > > > supinfo = {
> > > > >   .tree = RB_ROOT,
> > > > >   .lock = __SPIN_LOCK_UNLOCKED(supinfo.lock),
> 
> Double underscore typically means it's private and shouldn't be used.

Right, but when you have a struct you have no other means to initialize this
directly.

> > > > I even checked the current tree, we have 32 users of this pattern in drivers/.

See, there are users of the __ initializers.

> > > Ah, that is what you meant.  Yeah sure can - the supinfo_init() is
> > > another hangover from when I was trying to create the supinfo per chip,
> > > but now it is a global a static initialiser makes sense.
> >
> > Yep, the DEFINE_MUTEX() / DEFINE_SPINLOCK() / etc looks better naturally
> > than above.
> 
> Yeah, so maybe we should use non-struct, global variables after all.

At least this will allow to get rid of (questionable) initcall.

> > > And I still haven't received the email you quote there.
> >
> > :-( I'm not sure we will get it, it most likely that I removed it already
> > and it has disappeared due to problems with email server...

-- 
With Best Regards,
Andy Shevchenko


^ permalink raw reply	[flat|nested] 38+ messages in thread

end of thread, other threads:[~2023-12-18 10:08 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-14  9:58 [PATCH v2 0/5] gpiolib: cdev: relocate debounce_period_us Kent Gibson
2023-12-14  9:58 ` [PATCH v2 1/5] gpiolib: cdev: adopt scoped_guard() Kent Gibson
2023-12-14 11:50   ` Kent Gibson
2023-12-14 14:53     ` Andy Shevchenko
2023-12-14 14:53   ` Andy Shevchenko
2023-12-14  9:58 ` [PATCH v2 2/5] gpiolib: cdev: relocate debounce_period_us from struct gpio_desc Kent Gibson
2023-12-14 14:29   ` Bartosz Golaszewski
2023-12-14 14:45     ` Kent Gibson
2023-12-14 14:56       ` Bartosz Golaszewski
2023-12-14 15:08         ` Kent Gibson
2023-12-14 15:03   ` Andy Shevchenko
2023-12-14 15:09     ` Andy Shevchenko
2023-12-14 16:14       ` Kent Gibson
2023-12-14 16:41         ` Andy Shevchenko
2023-12-14 21:06           ` Bartosz Golaszewski
2023-12-15  1:04             ` Kent Gibson
2023-12-15  8:07               ` Bartosz Golaszewski
2023-12-15  8:15                 ` Kent Gibson
2023-12-15 16:31             ` Andy Shevchenko
2023-12-14  9:58 ` [PATCH v2 3/5] gpiolib: remove " Kent Gibson
2023-12-14  9:58 ` [PATCH v2 4/5] gpiolib: cdev: reduce locking in gpio_desc_to_lineinfo() Kent Gibson
2023-12-14 15:10   ` Andy Shevchenko
2023-12-14 15:19     ` Kent Gibson
2023-12-14 15:27       ` Andy Shevchenko
2023-12-14 15:34         ` Kent Gibson
2023-12-14 15:46           ` Kent Gibson
2023-12-14 15:52             ` Andy Shevchenko
2023-12-14 15:53             ` Kent Gibson
2023-12-14 16:02               ` Andy Shevchenko
2023-12-14 15:50           ` Andy Shevchenko
2023-12-14 16:05             ` Kent Gibson
2023-12-14  9:58 ` [PATCH v2 5/5] gpiolib: cdev: improve documentation of get/set values Kent Gibson
2023-12-14 15:12   ` Andy Shevchenko
2023-12-14 15:23     ` Kent Gibson
2023-12-14 15:27       ` Andy Shevchenko
  -- strict thread matches above, loose matches on Subject: below --
2023-12-14 16:46 [PATCH v2 2/5] gpiolib: cdev: relocate debounce_period_us from struct gpio_desc Andy Shevchenko
2023-12-14 21:05 ` Bartosz Golaszewski
2023-12-15 20:23 Andy Shevchenko

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).