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

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


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

end of thread, other threads:[~2026-12-02  3:22 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:33 [PATCH] ALSA: emu8000: shut down the pcm timer before freeing snd_emu8k_pcm Hanxiang Xu
2026-12-02  3:22 ` 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.