• Takashi Iwai's avatar
    ALSA: timer: Fix possible race at assigning a timer instance · 6a34367e
    Takashi Iwai authored
    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: default avatarTakashi Iwai <tiwai@suse.de>
    Link: https://lore.kernel.org/r/20191107192008.32331-4-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
    6a34367e
seq_timer.c 11.3 KB