Skip to content

Commit f0a8687

Browse files
rostedttiwai
authored andcommitted
ALSA: Use del_timer_sync() before freeing timer
The current code for freeing the emux timer is extremely dangerous: CPU0 CPU1 ---- ---- snd_emux_timer_callback() snd_emux_free() spin_lock(&emu->voice_lock) del_timer(&emu->tlist); <-- returns immediately spin_unlock(&emu->voice_lock); [..] kfree(emu); spin_lock(&emu->voice_lock); [BOOM!] Instead just use del_timer_sync() which will wait for the timer to finish before continuing. No need to check if the timer is active or not when doing so. This doesn't fix the race of a possible re-arming of the timer, but at least it won't use the data that has just been freed. [ Fixed unused variable warning by tiwai ] Cc: [email protected] Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Steven Rostedt (Google) <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 4a4c848 commit f0a8687

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

sound/synth/emux/emux.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,10 @@ EXPORT_SYMBOL(snd_emux_register);
126126
*/
127127
int snd_emux_free(struct snd_emux *emu)
128128
{
129-
unsigned long flags;
130-
131129
if (! emu)
132130
return -EINVAL;
133131

134-
spin_lock_irqsave(&emu->voice_lock, flags);
135-
if (emu->timer_active)
136-
del_timer(&emu->tlist);
137-
spin_unlock_irqrestore(&emu->voice_lock, flags);
132+
del_timer_sync(&emu->tlist);
138133

139134
snd_emux_proc_free(emu);
140135
snd_emux_delete_virmidi(emu);

0 commit comments

Comments
 (0)