Re: [PATCH] gpiolib: synchronize updates of descriptor labels

From: Bartosz Golaszewski

Date: Fri Nov 06 2026 - 04:34:26 EST


On Thu, Nov 05, 2026 at 04:53:10PM +0200, Andy Shevchenko wrote:
> On Thu, Nov 05, 2026 at 02:23:45PM +0100, Bartosz Golaszewski wrote:
> > desc_set_label() swaps desc->label with rcu_replace_pointer() but
> > without any synchronization of concurrent updates. The swap is a plain
> > read + write: two threads can observe the same old label and then call
>
> s/call//

Why? It's "call $function_name" which happens to be call_srcu().

>
> > call_scru() on the same SRCU head corrupting the state of the chain.
> >
> > Add a spinlock to struct gpio_device - we're using a single spinlock for
> > all descriptors as using a per-descriptor lock would unnecessarily bloat
> > the size of the desc array with very little chance and no consequences of
> > contention - and use it to serialize the pointer update.
>
> ...
>
> > - old = rcu_replace_pointer(desc->label, new, 1);
> > - if (old)
> > - call_srcu(&desc->gdev->desc_srcu, &old->rh, desc_free_label);
> > + scoped_guard(spinlock, &desc->gdev->desc_lock) {
> > + old = rcu_replace_pointer(desc->label, new,
> > + lockdep_is_held(&desc->gdev->desc_lock));
>
> Can lockdep_is_held() return anything except LOCK_STATE_HELD here? Or is it
> checked outside of this scoped_guard()?
>

No, but I'm doing it for completness and to self-document the intention.

Bart

> > + if (old)
> > + call_srcu(&desc->gdev->desc_srcu, &old->rh, desc_free_label);
> > + }
>
> --
> With Best Regards,
> Andy Shevchenko
>
>