[PATCH 1/4] ASoC: simple-card-utils: Add simple_util_remove_jack()
From: Chancel Liu
Date: Sun Sep 13 2026 - 06:25:41 EST
From: Chancel Liu <chancel.liu@xxxxxxx>
simple_util_init_jack() acquires a GPIO descriptor with
gpiod_get_optional() and hands it to snd_soc_jack_add_gpios(), which
additionally installs an IRQ handler, a PM notifier, a delayed work and
a sysfs export for it. simple-card-utils has no counterpart that
releases any of this again.
Add simple_util_remove_jack(), the counterpart of
simple_util_init_jack(). It releases the jack GPIO and everything
snd_soc_jack_add_gpios() installed for it via snd_soc_jack_free_gpios(),
and clears sjack->gpio.desc so the descriptor is not left dangling after
it has been put.
This gives the generic card drivers a card->remove() path to release the
jack when the card goes away. The devres cleanup alone is not enough:
it is tied to the platform device, so it does not run when the card is
unregistered and re-registered while the platform device stays bound -
for example when a codec component is unbound and bound again.
Signed-off-by: Chancel Liu <chancel.liu@xxxxxxx>
---
include/sound/simple_card_utils.h | 1 +
sound/soc/generic/simple-card-utils.c | 10 ++++++++++
2 files changed, 11 insertions(+)
diff --git a/include/sound/simple_card_utils.h b/include/sound/simple_card_utils.h
index bd8c3a033577..b0e00555092e 100644
--- a/include/sound/simple_card_utils.h
+++ b/include/sound/simple_card_utils.h
@@ -219,6 +219,7 @@ static inline int simple_util_parse_aux_devs(struct simple_util_priv *priv, char
int simple_util_init_jack(struct snd_soc_card *card,
struct simple_util_jack *sjack,
int is_hp, char *prefix, char *pin);
+void simple_util_remove_jack(struct simple_util_jack *sjack);
int simple_util_init_aux_jacks(struct snd_soc_card *card, char *prefix);
int simple_util_init_priv(struct simple_util_priv *priv,
struct link_info *li);
diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
index 7df5253499cd..b91924d31c1a 100644
--- a/sound/soc/generic/simple-card-utils.c
+++ b/sound/soc/generic/simple-card-utils.c
@@ -825,6 +825,16 @@ int simple_util_init_jack(struct snd_soc_card *card,
}
EXPORT_SYMBOL_GPL(simple_util_init_jack);
+void simple_util_remove_jack(struct simple_util_jack *sjack)
+{
+ if (!sjack->gpio.desc)
+ return;
+
+ snd_soc_jack_free_gpios(&sjack->jack, 1, &sjack->gpio);
+ sjack->gpio.desc = NULL;
+}
+EXPORT_SYMBOL_GPL(simple_util_remove_jack);
+
int simple_util_init_aux_jacks(struct snd_soc_card *card, char *prefix)
{
struct simple_util_priv *priv = snd_soc_card_get_drvdata(card);
--
2.50.1