Re: [PATCH 10/12] pinctrl: sunxi: Serialise per-bank regulator request and free

From: Yang Siyuan

Date: Thu Dec 03 2026 - 22:54:36 EST


Hi Lee,

On Wed, Dec 02, 2026 at 09:30:04AM +0000, Lee Jones wrote:
> The pinmux core invokes pmxops->request() and pmxops->free() without
> holding a controller-wide lock. When two pins in the same 32-pin bank
> are requested or freed concurrently, sunxi_pmx_request() and
> sunxi_pmx_free() race on s_reg->regulator and s_reg->refcount, which can
> result in duplicate regulator_get()/regulator_enable() calls or
> addition-on-zero refcount warnings.
>
> Serialise per-bank regulator acquisition and release in
> sunxi_pmx_request() and sunxi_pmx_free() with a mutex.

The race is real and serialising the two callbacks looks right to me.

One note on merge order: there is an in-flight patch making the per-bank
supply optional:

https://lore.kernel.org/linux-gpio/20261117231807.264348-1-hsyysy@xxxxxxx/

With that patch sunxi_pmx_request() can return without taking a reference
when vcc-pX-supply is absent, so sunxi_pmx_free() must not call
refcount_dec_and_test() for such a bank, or the refcount underflows. That
check has to sit inside reg_lock, after the guard, so it cannot race with
a concurrent acquisition:

guard(mutex)(&pctl->reg_lock);
if (!s_reg->regulator)
return 0;

If this series lands first, I'll rebase the optional-supply patch on top
of pinctrl/for-next and keep that ordering.

Thanks,
Yang