All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: sb: wait for the period timer before freeing the pcm private data
@ 2026-12-02  2:11 Hanxiang Xu
  2026-12-02  3:25 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Hanxiang Xu @ 2026-12-02  2:11 UTC (permalink / raw)
  To: Takashi Iwai, Jaroslav Kysela; +Cc: linux-sound, linux-kernel

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@vger.kernel.org>
Signed-off-by: Hanxiang Xu <xuhx@hust.edu.cn>
---
 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-02  3:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02  2:11 [PATCH] ALSA: sb: wait for the period timer before freeing the pcm private data Hanxiang Xu
2026-12-02  3:25 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.