diff options
| author | Mark Brown <broonie@kernel.org> | 2026-09-15 17:35:05 +0100 |
|---|---|---|
| committer | Mark Brown <broonie@kernel.org> | 2026-09-15 17:35:05 +0100 |
| commit | 82ecb042d5f4efc01298fbf7575e22fadfd8dfd3 (patch) | |
| tree | ff2799c20bd35a2e4129b47710138d8b1dd05d75 | |
| parent | 247b84c07b7ea4940f69995cc4fc4f20d8c0c615 (diff) | |
| parent | df0afa439044d7099055d5dc27189a083d8c9899 (diff) | |
| download | linux-next-82ecb042d5f4efc01298fbf7575e22fadfd8dfd3.tar.gz linux-next-82ecb042d5f4efc01298fbf7575e22fadfd8dfd3.zip | |
ASoC: generic: Free jack GPIOs on card remove
Chancel Liu <chancel.liu@oss.nxp.com> says:
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.
Link: https://patch.msgid.link/20260913102502.2805912-1-chancel.liu@oss.nxp.com
| -rw-r--r-- | include/sound/simple_card_utils.h | 2 | ||||
| -rw-r--r-- | sound/soc/generic/audio-graph-card.c | 1 | ||||
| -rw-r--r-- | sound/soc/generic/audio-graph-card2.c | 1 | ||||
| -rw-r--r-- | sound/soc/generic/simple-card-utils.c | 21 | ||||
| -rw-r--r-- | sound/soc/generic/simple-card.c | 11 |
5 files changed, 36 insertions, 0 deletions
diff --git a/include/sound/simple_card_utils.h b/include/sound/simple_card_utils.h index bd8c3a033577..68faec56970e 100644 --- a/include/sound/simple_card_utils.h +++ b/include/sound/simple_card_utils.h @@ -219,12 +219,14 @@ 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); void simple_util_remove(struct platform_device *pdev); int graph_util_card_probe(struct snd_soc_card *card); +int graph_util_card_remove(struct snd_soc_card *card); int graph_util_is_ports0(struct device_node *port); int graph_util_parse_dai(struct simple_util_priv *priv, struct device_node *ep, struct snd_soc_dai_link_component *dlc, int *is_single_link); diff --git a/sound/soc/generic/audio-graph-card.c b/sound/soc/generic/audio-graph-card.c index 0a8a6d891d1f..127c2e6b308e 100644 --- a/sound/soc/generic/audio-graph-card.c +++ b/sound/soc/generic/audio-graph-card.c @@ -629,6 +629,7 @@ static int graph_probe(struct platform_device *pdev) card->dapm_widgets = graph_dapm_widgets; card->num_dapm_widgets = ARRAY_SIZE(graph_dapm_widgets); card->probe = graph_util_card_probe; + card->remove = graph_util_card_remove; if (of_device_get_match_data(dev)) priv->dpcm_selectable = 1; diff --git a/sound/soc/generic/audio-graph-card2.c b/sound/soc/generic/audio-graph-card2.c index 9fb3d3df5cf6..e11bc8135cb0 100644 --- a/sound/soc/generic/audio-graph-card2.c +++ b/sound/soc/generic/audio-graph-card2.c @@ -1310,6 +1310,7 @@ int audio_graph2_parse_of(struct simple_util_priv *priv, struct device *dev, goto end; card->probe = graph_util_card_probe; + card->remove = graph_util_card_remove; card->owner = THIS_MODULE; card->dev = dev; diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c index 7df5253499cd..de27163eeb0b 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); @@ -1018,6 +1028,17 @@ end: } EXPORT_SYMBOL_GPL(graph_util_card_probe); +int graph_util_card_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; +} +EXPORT_SYMBOL_GPL(graph_util_card_remove); + int graph_util_is_ports0(struct device_node *np) { struct device_node *parent __free(device_node) = of_get_parent(np); 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 @@ end: 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); |
