All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Suyuan Wang" <shyckless@gmail.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH] ASoC: arizona: Disable jack detection when the component is removed
Date: Tue, 24 Nov 2026 05:17:17 +0000	[thread overview]
Message-ID: <sashiko-outbox-230548@kernel.org> (raw)
In-Reply-To: <20261124-arizona-jack-remove-v1-1-11d8ec426a41@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] ASoC: arizona: GPIO UAF in arizona_jack_codec_dev_remove() on
  codec unbind
- [Medium] ASoC: arizona: stale jack and HPDET state in
  arizona_jack_disable_jack_detect()
--

commit 64c10974d73769b43875985100c8e416d589c894
Author: Suyuan Wang <stevewong@hust.edu.cn>

ASoC: arizona: Disable jack detection when the component is removed

This commit calls arizona_jack_set_jack(component, NULL, NULL) in the
component_remove callbacks of the wm5102, wm5110, wm8997, and wm8998
codec drivers to disable jack detection on teardown.

> diff --git a/sound/soc/codecs/wm5102.c b/sound/soc/codecs/wm5102.c
> index 762e81979cb8d..43df7cb46b599 100644
> --- a/sound/soc/codecs/wm5102.c
> +++ b/sound/soc/codecs/wm5102.c
> @@ -1982,6 +1982,8 @@ static void wm5102_component_remove(struct snd_soc_component *component)
>  {
>  	struct wm5102_priv *priv = snd_soc_component_get_drvdata(component);
>  
> +	arizona_jack_set_jack(component, NULL, NULL);
> +
>  	wm_adsp2_component_remove(&priv->core.adsp[0], component);
>  
>  	priv->core.arizona->dapm = NULL;
> diff --git a/sound/soc/codecs/wm5110.c b/sound/soc/codecs/wm5110.c
> index faa85d88a489b..c772f4380ae7d 100644
> --- a/sound/soc/codecs/wm5110.c
> +++ b/sound/soc/codecs/wm5110.c
> @@ -2340,6 +2340,8 @@ static void wm5110_component_remove(struct snd_soc_component *component)
>  	struct wm5110_priv *priv = snd_soc_component_get_drvdata(component);
>  	int i;
>  
> +	arizona_jack_set_jack(component, NULL, NULL);
> +
>  	for (i = 0; i < WM5110_NUM_ADSP; ++i)
>  		wm_adsp2_component_remove(&priv->core.adsp[i], component);
>  
> diff --git a/sound/soc/codecs/wm8997.c b/sound/soc/codecs/wm8997.c
> index f041dfc905a42..aa9f23ddd9975 100644
> --- a/sound/soc/codecs/wm8997.c
> +++ b/sound/soc/codecs/wm8997.c
> @@ -1077,6 +1077,8 @@ static void wm8997_component_remove(struct snd_soc_component *component)
>  {
>  	struct wm8997_priv *priv = snd_soc_component_get_drvdata(component);
>  
> +	arizona_jack_set_jack(component, NULL, NULL);
> +
>  	priv->core.arizona->dapm = NULL;
>  }
>  
> diff --git a/sound/soc/codecs/wm8998.c b/sound/soc/codecs/wm8998.c
> index 1158e9ca40a13..47adbcd80e077 100644
> --- a/sound/soc/codecs/wm8998.c
> +++ b/sound/soc/codecs/wm8998.c
> @@ -1301,6 +1301,8 @@ static void wm8998_component_remove(struct snd_soc_component *component)
>  {
>  	struct wm8998_priv *priv = snd_soc_component_get_drvdata(component);
>  
> +	arizona_jack_set_jack(component, NULL, NULL);
> +
>  	priv->core.arizona->dapm = NULL;
>  }

[Severity: Medium]
When a codec platform device is unbound while a card is bound, can a jack
IRQ or delayed work use info->micd_pol_gpio or info->hpdet_id_gpio after
they have been freed?

The codec drivers register their ASoC components with
devm_snd_soc_register_component(), whereas their platform_driver.remove
callbacks call arizona_jack_codec_dev_remove() directly.  Because
snd_soc_card_bind() creates a stateless device link, unbinding the codec
runs platform_driver.remove before devres_release_all() unregisters the
component and invokes component_remove:

CPU0                              CPU1
wm5102_remove()
  arizona_jack_codec_dev_remove()
    gpiod_put(info->micd_pol_gpio)
    gpiod_put(info->hpdet_id_gpio)
                                  arizona_hpdet_irq()
                                    gpiod_set_value_cansleep(
                                      info->hpdet_id_gpio, 0)
                                      <-- use-after-free
devres_release_all()
  ...
    wm5102_component_remove()
      arizona_jack_set_jack(..., NULL, NULL)

Calling arizona_jack_disable_jack_detect() inside
arizona_jack_codec_dev_remove() before dropping the GPIO descriptors
(while keeping the call in component_remove for card unbind) would close
this window.

[Severity: Medium]
If the card is unbound and bound again while a jack is plugged in, does
stale state in struct arizona_priv prevent the newly bound card from
detecting the jack?

info->last_jackdet is only initialized in arizona_jack_codec_dev_probe(),
and neither arizona_jack_disable_jack_detect() nor
arizona_jack_enable_jack_detect() resets info->last_jackdet or
info->hpdet_done.  When the card is rebound and sets a new snd_soc_jack,
arizona_jackdet() sees val == info->last_jackdet and suppresses the event
instead of reporting the inserted jack, and stale info->hpdet_done causes
arizona_identify_headphone() to skip headphone detection.

In addition, if arizona_jack_disable_jack_detect() runs while an HPDET
measurement is in flight (info->hpdet_active is true), freeing
ARIZONA_IRQ_HPDET prevents arizona_hpdet_irq() from clearing
arizona->hpdet_clamp and dropping the pm_runtime_get_sync() reference
taken when starting HPDET.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-arizona-jack-remove-v1-1-11d8ec426a41@gmail.com?part=1

  reply	other threads:[~2026-11-24  5:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  5:02 [PATCH] ASoC: arizona: Disable jack detection when the component is removed Suyuan Wang
2026-11-24  5:02 ` Suyuan Wang via B4 Relay
2026-11-24  5:17 ` sashiko-bot [this message]
2026-11-24  6:09   ` Wong Steve

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-230548@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shyckless@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.