From a71cef6f641152c7c7bbc17d86f33a3b45cd10a9 Mon Sep 17 00:00:00 2001 From: Cen Zhang Date: Sun, 25 Oct 2026 00:49:49 +0800 Subject: [PATCH] ALSA: opl3: Initialize the timer before publishing a sequencer port snd_opl3_seq_probe() initializes the delayed-note timer and its lock after snd_opl3_synth_create_port() has made the native port reachable. A direct NOTEON does not require a subscription, and a fixed-duration instrument makes it enter snd_opl3_start_timer(). On sequencer-driver rebind, the card-owned instrument bank remains available. An event delivered as soon as the port appears can race the late initialization: Sequencer driver probe Direct NOTEON ---------------------- ------------- snd_opl3_synth_create_port() snd_seq_event_port_attach() publish port snd_opl3_synth_event_input() snd_opl3_note_on() snd_opl3_start_timer() use tlist and sys_timer_lock timer_setup(tlist) spin_lock_init(sys_timer_lock) sys_timer_status = 0 Initialize the timer, its lock and its status before creating the client and attaching either port. No event can then reach partially initialized timer state or have its newly armed timer reinitialized by the probe. Assisted-by: LLM Signed-off-by: Cen Zhang Signed-off-by: Takashi Iwai Link: https://patch.msgid.link/pm-pmb-4552c4e605507d8d9b16-v9-70247b8436e10e26d324-1@gmail.com --- sound/drivers/opl3/opl3_seq.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c index b77d8e8f12fb..2bacefc3201d 100644 --- a/sound/drivers/opl3/opl3_seq.c +++ b/sound/drivers/opl3/opl3_seq.c @@ -214,6 +214,11 @@ static int snd_opl3_seq_probe(struct snd_seq_device *dev) spin_lock_init(&opl3->voice_lock); + /* Initialize the timer before an attached port can receive events. */ + timer_setup(&opl3->tlist, snd_opl3_timer_func, 0); + spin_lock_init(&opl3->sys_timer_lock); + opl3->sys_timer_status = 0; + opl3->seq_client = -1; /* allocate new client */ @@ -232,11 +237,6 @@ static int snd_opl3_seq_probe(struct snd_seq_device *dev) return err; } - /* setup system timer */ - timer_setup(&opl3->tlist, snd_opl3_timer_func, 0); - spin_lock_init(&opl3->sys_timer_lock); - opl3->sys_timer_status = 0; - #if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS) snd_opl3_init_seq_oss(opl3, name); #endif