[PATCH 0/4] ASoC: generic: Free jack GPIOs on card remove

Chancel Liu posted 4 patches 1 week, 5 days ago
include/sound/simple_card_utils.h     |  2 ++
sound/soc/generic/audio-graph-card.c  |  1 +
sound/soc/generic/audio-graph-card2.c |  1 +
sound/soc/generic/simple-card-utils.c | 21 +++++++++++++++++++++
sound/soc/generic/simple-card.c       | 11 +++++++++++
5 files changed, 36 insertions(+)
[PATCH 0/4] ASoC: generic: Free jack GPIOs on card remove
Posted by Chancel Liu 1 week, 5 days ago
From: Chancel Liu <chancel.liu@nxp.com>

simple_util_init_jack() acquires a jack detection GPIO with
gpiod_get_optional() and passes it to snd_soc_jack_add_gpios(), which
also installs an IRQ handler, a PM notifier, a delayed work and a sysfs
export for it. None of simple-card, audio-graph-card or
audio-graph-card2 implements a card->remove() callback, so none of this
is ever released.

That goes unnoticed while the card is only torn down together with its
platform device, because the devres cleanup registered by
snd_soc_jack_add_gpios() is tied to that platform device. It becomes a
problem once the card alone is unregistered and registered again while
the platform device stays bound - for instance when a codec component is
unbound and bound again. card->probe() then runs a second time and
gpiod_get_optional() fails with -EBUSY, because the descriptor is still
held by the previous bind. The card is not registered again and audio
stays broken until the platform device itself is unbound.

Patch 1 adds the simple_util_remove_jack() helper, patches 2-4 wire it
up in the three generic card drivers.

Verified with audio-graph-card2 and a wm8962 codec using hp-det-gpios.
Before the series, the first

  echo 3-001a > /sys/bus/i2c/drivers/wm8962/unbind
  echo 3-001a > /sys/bus/i2c/drivers/wm8962/bind

leaves the GPIO line and IRQ claimed while the card is gone, and the
re-bind fails with

  ASoC error (-16): at graph_util_card_probe()
  ASoC error (-16): at snd_soc_card_probe() on wm8962-audio

after which the sound card never comes back. With the series applied,
both codec unbind/bind and platform unbind/bind cycles release the GPIO
and IRQ on unbind and fully restore the card.

Chancel Liu (4):
  ASoC: simple-card-utils: Add simple_util_remove_jack()
  ASoC: simple-card: Free jack GPIOs on card remove
  ASoC: audio-graph-card: Free jack GPIOs on card remove
  ASoC: audio-graph-card2: Free jack GPIOs on card remove

 include/sound/simple_card_utils.h     |  2 ++
 sound/soc/generic/audio-graph-card.c  |  1 +
 sound/soc/generic/audio-graph-card2.c |  1 +
 sound/soc/generic/simple-card-utils.c | 21 +++++++++++++++++++++
 sound/soc/generic/simple-card.c       | 11 +++++++++++
 5 files changed, 36 insertions(+)

--
2.50.1
Re: [PATCH 0/4] ASoC: generic: Free jack GPIOs on card remove
Posted by Mark Brown 1 week, 2 days ago
On Sun, 13 Sep 2026 19:24:58 +0900, Chancel Liu wrote:
> ASoC: generic: Free jack GPIOs on card remove
> 
> From: Chancel Liu <chancel.liu@nxp.com>
> 
> simple_util_init_jack() acquires a jack detection GPIO with
> gpiod_get_optional() and passes it to snd_soc_jack_add_gpios(), which
> also installs an IRQ handler, a PM notifier, a delayed work and a sysfs
> export for it. None of simple-card, audio-graph-card or
> audio-graph-card2 implements a card->remove() callback, so none of this
> is ever released.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.4

Thanks!

[1/4] ASoC: simple-card-utils: Add simple_util_remove_jack()
      https://git.kernel.org/broonie/sound/c/c7420dd9213d
[2/4] ASoC: simple-card: Free jack GPIOs on card remove
      https://git.kernel.org/broonie/sound/c/b59a20808727
[3/4] ASoC: audio-graph-card: Free jack GPIOs on card remove
      https://git.kernel.org/broonie/sound/c/698fdd31522c
[4/4] ASoC: audio-graph-card2: Free jack GPIOs on card remove
      https://git.kernel.org/broonie/sound/c/df0afa439044

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark