[PATCH] ALSA: emu8000: shut down the pcm timer before freeing snd_emu8k_pcm

From: Hanxiang Xu

Date: Tue Dec 01 2026 - 22:08:05 EST


emu8k_pcm_timer_func() re-arms itself unconditionally every jiffy
while the stream runs (emu8000_pcm.c:200), without checking
rec->timer_running or rec->running. stop_voice() only performs a
non-synchronizing timer_delete(), so a callback that is already
dequeued on another CPU re-arms the timer after the stop believes it
dead. emu8k_pcm_close() then kfree()s the struct with the timer
still armed, and the timer core executes the callback on the freed
memory (and re-arms the freed timer_list).

Check the stop flag inside the callback before re-arming, and shut
the timer down synchronously in emu8k_pcm_close() before freeing the
struct.

Cc: <stable@xxxxxxxxxxxxxxx>
Signed-off-by: Hanxiang Xu <xuhx@xxxxxxxxxxx>
---
sound/isa/sb/emu8000_pcm.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletions(-)

diff --git a/sound/isa/sb/emu8000_pcm.c b/sound/isa/sb/emu8000_pcm.c
index d2ca70aad1621eecfe1dc39451cb100c85ed3a29..360e0d05a5fd6398feb26bf2efeb64900e479ee9 100644
@@ -197,7 +197,8 @@
rec->last_ptr = ptr;

/* reprogram timer */
- mod_timer(&rec->timer, jiffies + 1);
+ if (rec->timer_running)
+ mod_timer(&rec->timer, jiffies + 1);

/* update period */
if (rec->period_pos >= (int)rec->period_size) {
@@ -246,6 +247,8 @@ static int emu8k_pcm_close(struct snd_pcm_substream *subs)
static int emu8k_pcm_close(struct snd_pcm_substream *subs)
{
struct snd_emu8k_pcm *rec = subs->runtime->private_data;
+
+ timer_shutdown_sync(&rec->timer);
kfree(rec);
subs->runtime->private_data = NULL;
return 0;
--
2.43.0