[PATCH] ASoC: rt5645: Shut down the button timer on removal
From: Myeonghun Pak
Date: Wed Oct 14 2026 - 22:51:31 EST
jack_detect_work can rearm btn_check_timer, and the timer callback can
queue jack_detect_work. Deleting the timer before cancelling the work
does not break this cycle: an already running worker can rearm the timer
after timer_delete_sync() returns. The timer can then outlive removal.
Use timer_shutdown_sync() before cancelling the delayed work so that
subsequent attempts to rearm the timer are ignored. The IRQ producer has
already been removed at this point. Keep the restartable timer deletion
in the suspend path.
This issue was identified as part of our ongoing research while
reviewing kernel code.
Fixes: 7ff6319e7da5 ("ASoC: rt5645: use polling to support HS button")
Assisted-by: LLM
Co-developed-by: Ijae Kim <ae878000@xxxxxxxxx>
Signed-off-by: Ijae Kim <ae878000@xxxxxxxxx>
Signed-off-by: Myeonghun Pak <mhun512@xxxxxxxxx>
---
Compile-tested with GCC, W=1 (x86_64). No runtime testing.
sound/soc/codecs/rt5645.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c
index 7313ea7..3c4354d 100644
--- a/sound/soc/codecs/rt5645.c
+++ b/sound/soc/codecs/rt5645.c
@@ -19,6 +19,7 @@
#include <linux/acpi.h>
#include <linux/dmi.h>
#include <linux/regulator/consumer.h>
+#include <linux/timer.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
@@ -4292,10 +4293,10 @@ static void rt5645_i2c_remove(struct i2c_client *i2c)
free_irq(i2c->irq, rt5645);
/*
- * Since the rt5645_btn_check_callback() can queue jack_detect_work,
- * the timer need to be delted first
+ * The timer and jack_detect_work can rearm each other. Shut down the
+ * timer before cancelling the work.
*/
- timer_delete_sync(&rt5645->btn_check_timer);
+ timer_shutdown_sync(&rt5645->btn_check_timer);
cancel_delayed_work_sync(&rt5645->jack_detect_work);
cancel_delayed_work_sync(&rt5645->rcclock_work);