summaryrefslogtreecommitdiffstats
path: root/sound/usb/pcm.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2020-11-23 09:53:27 +0100
committerTakashi Iwai <tiwai@suse.de>2020-11-23 15:14:36 +0100
commit57234bc1038517437d5c589595caf77b2118529e (patch)
tree338117bd31306f490d543ae740d56f34be7aa7ce /sound/usb/pcm.c
parent73037c8dc1c8cf994a38fedba4a5af7e6da5e4f1 (diff)
downloadlinux-stable-57234bc1038517437d5c589595caf77b2118529e.tar.gz
linux-stable-57234bc1038517437d5c589595caf77b2118529e.tar.bz2
linux-stable-57234bc1038517437d5c589595caf77b2118529e.zip
ALSA: usb-audio: Stop both endpoints properly at error
start_endpoints() may leave the data endpoint running if an error happens at starting the sync endpoint. We should stop both streams properly, instead. While we're at it, move the debug prints into the endpoint.c that is a more suitable place. Tested-by: Keith Milner <kamilner@superlative.org> Tested-by: Dylan Robinson <dylan_robinson@motu.com> Link: https://lore.kernel.org/r/20201123085347.19667-22-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/usb/pcm.c')
-rw-r--r--sound/usb/pcm.c39
1 files changed, 17 insertions, 22 deletions
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index 0998be109af3..c4e39aa92a84 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -211,6 +211,17 @@ int snd_usb_init_pitch(struct snd_usb_audio *chip,
}
}
+static void stop_endpoints(struct snd_usb_substream *subs)
+{
+ if (test_and_clear_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags)) {
+ snd_usb_endpoint_stop(subs->sync_endpoint);
+ subs->sync_endpoint->sync_slave = NULL;
+ }
+
+ if (test_and_clear_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags))
+ snd_usb_endpoint_stop(subs->data_endpoint);
+}
+
static int start_endpoints(struct snd_usb_substream *subs)
{
int err;
@@ -221,13 +232,11 @@ static int start_endpoints(struct snd_usb_substream *subs)
if (!test_and_set_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags)) {
struct snd_usb_endpoint *ep = subs->data_endpoint;
- dev_dbg(&subs->dev->dev, "Starting data EP 0x%x\n", ep->ep_num);
-
ep->data_subs = subs;
err = snd_usb_endpoint_start(ep);
if (err < 0) {
clear_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags);
- return err;
+ goto error;
}
}
@@ -235,18 +244,20 @@ static int start_endpoints(struct snd_usb_substream *subs)
!test_and_set_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags)) {
struct snd_usb_endpoint *ep = subs->sync_endpoint;
- dev_dbg(&subs->dev->dev, "Starting sync EP 0x%x\n", ep->ep_num);
-
ep->sync_slave = subs->data_endpoint;
err = snd_usb_endpoint_start(ep);
if (err < 0) {
clear_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags);
ep->sync_slave = NULL;
- return err;
+ goto error;
}
}
return 0;
+
+ error:
+ stop_endpoints(subs);
+ return err;
}
static void sync_pending_stops(struct snd_usb_substream *subs)
@@ -255,22 +266,6 @@ static void sync_pending_stops(struct snd_usb_substream *subs)
snd_usb_endpoint_sync_pending_stop(subs->data_endpoint);
}
-static void stop_endpoints(struct snd_usb_substream *subs)
-{
- if (test_and_clear_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags)) {
- dev_dbg(&subs->dev->dev, "Stopping sync EP 0x%x\n",
- subs->sync_endpoint->ep_num);
- snd_usb_endpoint_stop(subs->sync_endpoint);
- subs->sync_endpoint->sync_slave = NULL;
- }
-
- if (test_and_clear_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags)) {
- dev_dbg(&subs->dev->dev, "Stopping data EP 0x%x\n",
- subs->data_endpoint->ep_num);
- snd_usb_endpoint_stop(subs->data_endpoint);
- }
-}
-
/* PCM sync_stop callback */
static int snd_usb_pcm_sync_stop(struct snd_pcm_substream *substream)
{