mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yaohan Li <shunsheng1218@gmail.com>
To: Oder Chiou <oder_chiou@realtek.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] ASoC: rt5645: stop timer and delayed works on probe error
Date: Mon, 30 Nov 2026 21:28:08 +0800	[thread overview]
Message-ID: <20261130132808.2078478-1-shunsheng1218@gmail.com> (raw)

rt5645_i2c_probe() requests the threaded IRQ before calling
devm_snd_soc_register_component().  If component registration fails,
err_irq calls free_irq() without cancelling rt5645->jack_detect_work,
which the IRQ handler may already have queued to run 250 ms later after
devres frees rt5645.

Match rt5645_i2c_remove() in err_irq: shut down btn_check_timer and
cancel jack_detect_work and rcclock_work after free_irq() so no timer or
delayed work remains active when probe returns an error.

Fixes: cd6e82b814ca ("ASoC: rt5645: Add the workqueue of the jack detect function for the debouncing")
Signed-off-by: Yaohan Li <shunsheng1218@gmail.com>
---
Based on v7.4-rc5 (fe6ff8d5d675).

Tested in QEMU x86_64 (KASAN + PROVE_LOCKING) using a virtual I2C adapter
and a virtual IRQ controller (no physical rt5645 hardware).  Failing
devm_snd_soc_register_component() via failslab while an IRQ fires queues
jack_detect_work, which runs after devres frees rt5645: unpatched hits
a KASAN slab-use-after-free in __run_timer_base on the first of 10/10
fault-injected iterations (single-shot KASAN); with this patch, 10/10
iterations complete and unload cleanly with 0 KASAN reports.

Note that only jack_detect_work was dynamically reproduced on this probe
failure path; btn_check_timer and rcclock_work are not armed while
rt5645->component is NULL and are torn down here to stay symmetric with
rt5645_i2c_remove() and prevent timer/work rearming across teardown.

Build-tested on x86_64 and arm64 with W=1 (0 warnings).  Not tested on
physical hardware.

AI assistance: Claude (Anthropic) helped with the analysis, the QEMU test
harness, and drafting the patch and changelog.  I reviewed the root cause,
teardown order, test results, and the final patch.

 sound/soc/codecs/rt5645.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c
index e14b66d3118d..dbbd12e637e7 100644
--- a/sound/soc/codecs/rt5645.c
+++ b/sound/soc/codecs/rt5645.c
@@ -4282,6 +4282,9 @@ static int rt5645_i2c_probe(struct i2c_client *i2c)
 err_irq:
 	if (rt5645->i2c->irq)
 		free_irq(rt5645->i2c->irq, rt5645);
+	timer_shutdown_sync(&rt5645->btn_check_timer);
+	cancel_delayed_work_sync(&rt5645->jack_detect_work);
+	cancel_delayed_work_sync(&rt5645->rcclock_work);
 err_enable:
 	regulator_bulk_disable(ARRAY_SIZE(rt5645->supplies), rt5645->supplies);
 	return ret;
-- 
2.34.1


                 reply	other threads:[~2026-11-30 13:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261130132808.2078478-1-shunsheng1218@gmail.com \
    --to=shunsheng1218@gmail.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=oder_chiou@realtek.com \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®