]> git.baikalelectronics.ru Git - kernel.git/commit
ALSA: timer: Fix possible race at assigning a timer instance
authorTakashi Iwai <tiwai@suse.de>
Thu, 7 Nov 2019 19:20:08 +0000 (20:20 +0100)
committerTakashi Iwai <tiwai@suse.de>
Fri, 8 Nov 2019 13:52:44 +0000 (14:52 +0100)
commit3199b21b0adfbff285bfac103ea2bfb53853aa7a
treea52eda441990007a9143d0ecc1f286541bd4a075
parente2e7828f2406d2af6fa00d161aefdc4933736434
ALSA: timer: Fix possible race at assigning a timer instance

When a new timer instance is created and assigned to the active link
in snd_timer_open(), the caller still doesn't (can't) set its callback
and callback data.  In both the user-timer and the sequencer-timer
code, they do manually set up the callbacks after calling
snd_timer_open().  This has a potential risk of race when the timer
instance is added to the already running timer target, as the callback
might get triggered during setting up the callback itself.

This patch tries to address it by changing the API usage slightly:

- An empty timer instance is created at first via the new function
  snd_timer_instance_new().  This object isn't linked to the timer
  list yet.
- The caller sets up the callbacks and others stuff for the new timer
  instance.
- The caller invokes snd_timer_open() with this instance, so that it's
  linked to the target timer.

For closing, do similarly:

- Call snd_timer_close().  This unlinks the timer instance from the
  timer list.
- Free the timer instance via snd_timer_instance_free() after that.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/20191107192008.32331-4-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/sound/timer.h
sound/core/seq/seq_timer.c
sound/core/timer.c