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

From: Andy Shevchenko

Date: Thu Nov 05 2026 - 09:53:25 EST


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//

> 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()?

> + if (old)
> + call_srcu(&desc->gdev->desc_srcu, &old->rh, desc_free_label);
> + }

--
With Best Regards,
Andy Shevchenko