[PATCH 2/4] ASoC: simple-card: Free jack GPIOs on card remove

From: Chancel Liu

Date: Sun Sep 13 2026 - 06:26:12 EST


From: Chancel Liu <chancel.liu@xxxxxxx>

simple_soc_probe() sets up the headphone and microphone jacks, which
takes a reference on the jack detection GPIO and registers an IRQ, a PM
notifier, a delayed work and a sysfs export for it. simple-card has no
card->remove() callback, so none of this is released when the card is
torn down.

This 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 example 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.

Add simple_soc_remove() as the counterpart of simple_soc_probe() and
release both jacks from there.

Signed-off-by: Chancel Liu <chancel.liu@xxxxxxx>
---
sound/soc/generic/simple-card.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index 0a769c177149..b2fc91b8ab81 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -666,6 +666,16 @@ static int simple_soc_probe(struct snd_soc_card *card)
return simple_ret(priv, ret);
}

+static int simple_soc_remove(struct snd_soc_card *card)
+{
+ struct simple_util_priv *priv = snd_soc_card_get_drvdata(card);
+
+ simple_util_remove_jack(&priv->hp_jack);
+ simple_util_remove_jack(&priv->mic_jack);
+
+ return 0;
+}
+
static int simple_parse_of(struct simple_util_priv *priv)
{
struct snd_soc_card *card = simple_priv_to_card(priv);
@@ -754,6 +764,7 @@ static int simple_probe(struct platform_device *pdev)
card->owner = THIS_MODULE;
card->dev = dev;
card->probe = simple_soc_probe;
+ card->remove = simple_soc_remove;
card->driver_name = "simple-card";

return simple_parse_of(priv);
--
2.50.1