All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: alsa-devel@alsa-project.org
Subject: [PATCH 7/9] ALSA: usb-audio: Add spinlock to stop_urbs()
Date: Wed, 29 Sep 2021 10:08:42 +0200	[thread overview]
Message-ID: <20210929080844.11583-8-tiwai@suse.de> (raw)
In-Reply-To: <20210929080844.11583-1-tiwai@suse.de>

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.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/usb/endpoint.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
index 1f757a7eeafe..c32022672319 100644
--- a/sound/usb/endpoint.c
+++ b/sound/usb/endpoint.c
@@ -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)) {
-- 
2.26.2


  parent reply	other threads:[~2021-09-29  8:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29  8:08 [PATCH 0/9] ALSA: usb-audio: More fixes / improvements on PCM Takashi Iwai
2021-09-29  8:08 ` [PATCH 1/9] ALSA: usb-audio: Restrict rates for the shared clocks Takashi Iwai
2021-09-29  8:08 ` [PATCH 2/9] ALSA: usb-audio: Fix possible race at sync of urb completions Takashi Iwai
2021-09-29  8:08 ` [PATCH 3/9] ALSA: usb-audio: Rename early_playback_start flag with lowlatency_playback Takashi Iwai
2021-09-29  8:08 ` [PATCH 4/9] ALSA: usb-audio: Disable low-latency playback for free-wheel mode Takashi Iwai
2021-09-29  8:08 ` [PATCH 5/9] ALSA: usb-audio: Disable low-latency mode for implicit feedback sync Takashi Iwai
2021-09-29  8:08 ` [PATCH 6/9] ALSA: usb-audio: Check available frames for the next packet size Takashi Iwai
2021-09-29  8:08 ` Takashi Iwai [this message]
2021-09-29  8:08 ` [PATCH 8/9] ALSA: usb-audio: Improved lowlatency playback support Takashi Iwai
2021-09-29  8:08 ` [PATCH 9/9] ALSA: usb-audio: Avoid killing in-flight URBs during draining Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210929080844.11583-8-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.