[PATCH] ALSA: sb: wait for the period timer before freeing the pcm private data

From: Hanxiang Xu

Date: Tue Dec 01 2026 - 22:12:16 EST


emu8k_pcm_close() kfrees struct snd_emu8k_pcm with no timer
synchronization: stop_voice() uses plain timer_delete(), which does not
wait for a callback instance that is already running, and the callback's
snd_pcm_period_elapsed(rec->substream) runs outside rec->timer_lock.
A close (or a driver removal freeing the substream) that lands while an
instance is in flight reads rec->substream from freed memory; a freed
callback that still re-arms puts a freed timer_list back into the
wheel.

Use timer_shutdown_sync() in emu8k_pcm_close(): it waits for an
in-flight instance and marks the timer so a late mod_timer() from the
callback is ignored. In the common (already stopped) path it returns
immediately.

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

diff --git a/sound/isa/sb/emu8000_pcm.c b/sound/isa/sb/emu8000_pcm.c
index d2ca70a..3aeef31 100644
--- a/sound/isa/sb/emu8000_pcm.c
+++ b/sound/isa/sb/emu8000_pcm.c
@@ -246,6 +246,7 @@ static int emu8k_pcm_open(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