Linux Sound subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Amadeusz Sławiński" <amade@asmblr.net>, linux-sound@vger.kernel.org
Subject: Re: [PATCH 03/12] ASoC: codecs: wm8994: Implement set_jack callback
Date: Mon, 26 Oct 2026 20:34:59 +0000	[thread overview]
Message-ID: <sashiko-outbox-185729@kernel.org> (raw)
In-Reply-To: <20261026201915.57184-4-amade@asmblr.net>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] ASoC: wm8994: stale jack pointer and active work in wm8958_mic_detect()
--

commit 0dc23f1f04114660da148a373855c1151a4983df
Author: Amadeusz Sławiński <amade@asmblr.net>

ASoC: codecs: wm8994: Implement set_jack callback

This commit implements the set_jack callback for the wm8994 component driver,
delegating to wm8994_mic_detect() for WM8994 and wm8958_mic_detect() for
WM1811 and WM8958 so machine drivers can use snd_soc_component_set_jack().

> diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c
> index 6b91e02f130b3..69afba1764eb7 100644
> --- a/sound/soc/codecs/wm8994.c
> +++ b/sound/soc/codecs/wm8994.c
> @@ -4642,12 +4642,30 @@ static void wm8994_component_remove(struct snd_soc_component *component)
>  	kfree(wm8994->retune_mobile_texts);
>  }
>  
> +static int wm8994_set_jack(struct snd_soc_component *component,
> +			   struct snd_soc_jack *jack, void *data)
> +{
> +	struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
> +	struct wm8994 *control = wm8994->wm8994;
> +
> +	switch (control->type) {
> +	case WM8994:
> +		return wm8994_mic_detect(component, jack, data ? *(int *)data : 1);
> +	case WM1811:
> +	case WM8958:
> +		return wm8958_mic_detect(component, jack, NULL, NULL, NULL, NULL);

[Severity: High]
When snd_soc_component_set_jack(component, NULL, NULL) is called during jack
teardown or card unbind on WM1811 or WM8958, wm8994_set_jack() passes a NULL
jack pointer to wm8958_mic_detect().

In sound/soc/codecs/wm8994.c, the NULL jack branch of wm8958_mic_detect()
does not clear wm8994->micdet[0].jack or cancel pending delayed work:

	} else {
		snd_soc_component_update_bits(component, WM8958_MIC_DETECT_1,
				    WM8958_MICD_ENA, 0);
		wm1811_jackdet_set_mode(component, WM1811_JACKDET_MODE_NONE);
		snd_soc_dapm_disable_pin(dapm, "CLK_SYS");
		snd_soc_dapm_sync(dapm);
	}

Because wm8994->micdet[0].jack remains non-NULL, wm1811_jackdet_set_mode()
still treats jack detection as active:

	if (!wm8994->jackdet || !wm8994->micdet[0].jack)
		return;

	if (wm8994->active_refcount)
		mode = WM1811_JACKDET_MODE_AUDIO;

If wm8994->active_refcount is non-zero during teardown,
wm1811_jackdet_set_mode() overrides WM1811_JACKDET_MODE_NONE with
WM1811_JACKDET_MODE_AUDIO, and subsequent active_dereference() calls re-arm
hardware jack or microphone detection.

In addition, pending delayed work items such as wm8958_open_circuit_work,
wm1811_jackdet_bootstrap, wm1811_mic_work, and wm8958_mic_work are not
canceled and can still dereference the stale wm8994->micdet[0].jack pointer:

	snd_soc_jack_report(wm8994->micdet[0].jack, 0,
			    wm8994->btn_mask |
			    SND_JACK_HEADSET);

Can this leave a dangling jack pointer and cause a use-after-free in
snd_soc_jack_report() after the jack is freed?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261026201915.57184-1-amade@asmblr.net?part=3

  reply	other threads:[~2026-10-26 20:34 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-26 20:19 [PATCH 00/12] ASoC: Convert last few codecs to set_jack Amadeusz Sławiński
2026-10-26 20:19 ` [PATCH 01/12] ASoC: codecs: wm8903: Implement set_jack callback Amadeusz Sławiński
2026-10-26 20:19 ` [PATCH 02/12] ASoC: codecs: wm8962: " Amadeusz Sławiński
2026-10-26 20:19 ` [PATCH 03/12] ASoC: codecs: wm8994: " Amadeusz Sławiński
2026-10-26 20:34   ` sashiko-bot [this message]
2026-10-27 19:23     ` Amadeusz Sławiński
2026-10-26 20:19 ` [PATCH 04/12] ASoC: tegra: tegra_wm8903: Use standard callback to set jack Amadeusz Sławiński
2026-10-26 20:19 ` [PATCH 05/12] ASoC: tegra: tegra_wm8962: " Amadeusz Sławiński
2026-10-26 20:19 ` [PATCH 06/12] ASoC: tegra: tegra_wm8994: " Amadeusz Sławiński
2026-10-26 20:19 ` [PATCH 07/12] ASoC: samsung: littlemill: " Amadeusz Sławiński
2026-10-26 20:19 ` [PATCH 08/12] ASoC: samsung: midas_wm1811: " Amadeusz Sławiński
2026-10-26 20:19 ` [PATCH 09/12] ASoC: samsung: tobermory: " Amadeusz Sławiński
2026-10-26 20:19 ` [PATCH 10/12] ASoC: codecs: wm8903: Make wm8903_mic_detect() static Amadeusz Sławiński
2026-10-26 20:19 ` [PATCH 11/12] ASoC: codecs: wm8962: Make wm8962_mic_detect() static Amadeusz Sławiński
2026-10-26 20:19 ` [PATCH 12/12] ASoC: codecs: wm8994: Make mic detect functions static Amadeusz Sławiński
2026-10-27 10:04 ` [PATCH 00/12] ASoC: Convert last few codecs to set_jack Charles Keepax

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-185729@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=amade@asmblr.net \
    --cc=linux-sound@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox