ALSA: usb-audio: Add spinlock to stop_urbs()
authorTakashi Iwai <tiwai@suse.de>
Wed, 29 Sep 2021 08:08:42 +0000 (10:08 +0200)
committerTakashi Iwai <tiwai@suse.de>
Thu, 30 Sep 2021 11:55:23 +0000 (13:55 +0200)
In theory, stop_urbs() may be called concurrently.
Although we have the state check beforehand, it's safer to apply
ep->lock during the critical list head manipulations.

Link: https://lore.kernel.org/r/20210929080844.11583-8-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/usb/endpoint.c

index 1f757a7eeafecfde63fa9a891dde89b430ac8416..c32022672319993fb8bcf19e6d4f6b22a1306666 100644 (file)
@@ -927,6 +927,7 @@ void snd_usb_endpoint_sync_pending_stop(struct snd_usb_endpoint *ep)
 static int stop_urbs(struct snd_usb_endpoint *ep, bool force)
 {
        unsigned int i;
+       unsigned long flags;
 
        if (!force && atomic_read(&ep->running))
                return -EBUSY;
@@ -934,9 +935,11 @@ static int stop_urbs(struct snd_usb_endpoint *ep, bool force)
        if (!ep_state_update(ep, EP_STATE_RUNNING, EP_STATE_STOPPING))
                return 0;
 
+       spin_lock_irqsave(&ep->lock, flags);
        INIT_LIST_HEAD(&ep->ready_playback_urbs);
        ep->next_packet_head = 0;
        ep->next_packet_queued = 0;
+       spin_unlock_irqrestore(&ep->lock, flags);
 
        for (i = 0; i < ep->nurbs; i++) {
                if (test_bit(i, &ep->active_mask)) {