Skip to content

Commit

Permalink
ALSA: usb-audio: Add spinlock to stop_urbs()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Takashi Iwai committed Sep 30, 2021
1 parent d215f63 commit 0ef7436
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sound/usb/endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -927,16 +927,19 @@ 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;

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)) {
Expand Down

0 comments on commit 0ef7436

Please sign in to comment.