[PATCH v4 0/4] gpio: shared-proxy: Fix line accounting

From: Shawn Guo

Date: Sat Oct 17 2026 - 00:36:46 EST


Four fixes for how the shared GPIO proxy accounts for users and
votes.

Patch 1 fixes a race between consumers that request a shared line
concurrently. Each of them sees usecnt > 1, assumes another user has
already configured the line, and fails with -EPERM. On Nord RRD this
intermittently leaves both DAC supply regulators without their enable
GPIO.

Patch 2 fixes a stale vote left behind when a proxy releases the line
and restoring the default value fails. The line stays at the
non-default value for the remaining users, and votecnt can underflow
when the line is requested again.

Patch 3 fixes gpiod_set_value() to the default value doing nothing on
a line that was requested with GPIOD_ASIS and left at the opposite
value, e.g. by the bootloader.

Patch 4 drops a proxy's vote when it switches the line to input, so
releasing the line no longer fails trying to write the default value
to an input

Changes in v4:
- Patch 4: New. Clear the vote when reinitializing the line as input.
It predates patch 1 (Sashiko)
- Link to v3: https://lore.kernel.org/all/20261017024335.1432020-1-shengchao.guo@xxxxxxxxxxxxxxxx/

Changes in v3:
- Patch 3: New. Drive the default value to the hardware when no votes
are outstanding. It predates patch 1 (Sashiko)
- Link to v2: https://lore.kernel.org/all/20261016144919.1362846-1-shengchao.guo@xxxxxxxxxxxxxxxx/

Changes in v2:
- Patch 1: Also use gpio_shared_proxy_may_init() instead of
usecnt > 1 in set_config, so concurrent first users no longer skip
the hardware config or log a spurious conflict (Sashiko)
- Patch 2: New. Fix the votecnt underflow on a failed write in free.
It predates patch 1 (Sashiko)
- Link to v1: https://lore.kernel.org/all/20261015122740.971792-1-shengchao.guo@xxxxxxxxxxxxxxxx/

Shawn Guo (4):
gpio: shared-proxy: Fix race between concurrent first users
gpio: shared-proxy: Drop the vote of a released proxy on write failure
gpio: shared-proxy: Drive the default value when no votes are cast
gpio: shared-proxy: Drop the vote when switching to input

drivers/gpio/gpio-shared-proxy.c | 94 ++++++++++++++++++++++++++++----
drivers/gpio/gpiolib-shared.h | 1 +
2 files changed, 83 insertions(+), 12 deletions(-)

--
2.43.0