All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tristan Madani" <tristmd@gmail.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH 2/4] ASoC: rt5659: cancel jack_detect_work on component remove
Date: Mon, 26 Oct 2026 12:41:38 +0000	[thread overview]
Message-ID: <sashiko-outbox-185227@kernel.org> (raw)
In-Reply-To: <20261026112212.2519775-3-tristmd@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] ASoC: rt5659: uninitialized delayed_work cancel in rt5659_remove()
- [High] ASoC: rt5659: uninitialized jack_detect_work used when jd_src is unset
--

commit ca81fa64a51ff1ffcf9ce836fb012f5147653078
Author: Tristan Madani <tristan@talencesecurity.com>

ASoC: rt5659: cancel jack_detect_work on component remove

This commit disables the codec IRQ and cancels jack_detect_work
synchronously in rt5659_remove() before resetting the codec, and
re-enables the IRQ in rt5659_probe() on component rebind.

> diff --git a/sound/soc/codecs/rt5659.c b/sound/soc/codecs/rt5659.c
> index af8051fa69f89..d9daede7310ea 100644
> --- a/sound/soc/codecs/rt5659.c
> +++ b/sound/soc/codecs/rt5659.c
[ ... ]
> @@ -3684,7 +3690,14 @@ static int rt5659_probe(struct snd_soc_component *component)
>  static void rt5659_remove(struct snd_soc_component *component)
>  {
>  	struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
> +	struct i2c_client *i2c = to_i2c_client(component->dev);
> +
> +	if (rt5659->irq_acquired) {
> +		disable_irq(i2c->irq);
> +		rt5659->irq_disabled = true;
> +	}
>  
> +	cancel_delayed_work_sync(&rt5659->jack_detect_work);

[Severity: High]
Is rt5659->jack_detect_work guaranteed to be initialized before
rt5659_remove() calls cancel_delayed_work_sync()?

In sound/soc/codecs/rt5659.c, rt5659_i2c_probe() allocates rt5659 with
devm_kzalloc() and only calls INIT_DELAYED_WORK() when
rt5659->pdata.jd_src is RT5659_JD3 or RT5659_JD_HDA_HEADER:

sound/soc/codecs/rt5659.c:rt5659_i2c_probe() {
	...
	switch (rt5659->pdata.jd_src) {
	case RT5659_JD3:
		...
		INIT_DELAYED_WORK(&rt5659->jack_detect_work,
			rt5659_jack_detect_work);
		break;
	case RT5659_JD_HDA_HEADER:
		...
		INIT_DELAYED_WORK(&rt5659->jack_detect_work,
			rt5659_jack_detect_intel_hd_header);
		rt5659_intel_hd_header_probe_setup(rt5659);
		break;
	default:
		break;
	}
	...
}

When the optional realtek,jd-src property is omitted or set to 0
(RT5659_JD_NULL), the default branch is taken and
rt5659->jack_detect_work remains zero-initialized with work.func == NULL
and an uninitialized timer.

When snd_soc_component_remove() -> rt5659_remove() then runs on card
unbind or driver removal, cancel_delayed_work_sync() ->
__cancel_work_sync() calls timer_delete() on the uninitialized timer and
__flush_work() hits WARN_ON(!work->func).

Additionally, because rt5659_i2c_probe() still registers rt5659_irq when
i2c->irq is present and rt5659_set_jack_detect() invokes rt5659_irq(), an
interrupt or jack detection setup with pdata.jd_src == RT5659_JD_NULL will
call queue_delayed_work() on the uninitialized rt5659->jack_detect_work.

Should cancel_delayed_work_sync() (as well as IRQ registration or
work queueing) be guarded by checking whether rt5659->pdata.jd_src
configured jack_detect_work?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261026112212.2519775-1-tristmd@gmail.com?part=2

  reply	other threads:[~2026-10-26 12:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-26 11:22 [PATCH 0/4] ASoC: cancel pending delayed works on component remove Tristan Madani
2026-10-26 11:22 ` [PATCH 1/4] ASoC: rt5668: " Tristan Madani
2026-10-26 12:21   ` sashiko-bot
2026-10-26 11:22 ` [PATCH 2/4] ASoC: rt5659: cancel jack_detect_work " Tristan Madani
2026-10-26 12:41   ` sashiko-bot [this message]
2026-10-26 19:16   ` Mark Brown
2026-10-26 11:22 ` [PATCH 3/4] ASoC: twl6040: cancel headset jack work " Tristan Madani
2026-10-26 11:22 ` [PATCH 4/4] ASoC: wm8994: drain all delayed works " Tristan Madani
2026-10-26 12:57   ` sashiko-bot
2026-10-26 19:16   ` Mark Brown
2026-10-29 10:25 ` [PATCH v9] ASoC: wm8994: drain delayed works on remove and probe error Tristan Madani
2026-10-29 10:42   ` sashiko-bot
2026-10-29 10:57   ` [PATCH v10] " Tristan Madani
2026-10-29 11:11     ` sashiko-bot
2026-10-29 11:18     ` Mark Brown
2026-10-29 11:10   ` [PATCH v9] " Mark Brown

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-185227@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tristmd@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.