* [PATCH] ASoC: rt5645: stop timer and delayed works on probe error
@ 2026-11-30 13:28 Yaohan Li
0 siblings, 0 replies; only message in thread
From: Yaohan Li @ 2026-11-30 13:28 UTC (permalink / raw)
To: Oder Chiou, Liam Girdwood, Mark Brown
Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, linux-kernel
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-30 13:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 13:28 [PATCH] ASoC: rt5645: stop timer and delayed works on probe error Yaohan Li
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®