Skip to content

Commit 1045f5f

Browse files
committed
ALSA: usb-audio: Avoid superfluous endpoint setup
After splitting to snd_usb_endpoint_set_params() and *_prepare(), the skip of each function should be checked with different flags, while we still use ep->need_setup as the single one. Introduce ep->need_prepare for indicating the need of prepare, and also add the missing check of ep->need_setup at the set_params. Fixes: 2be79d5 ("ALSA: usb-audio: Split endpoint setups for hw_params and prepare (take#2)") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 9355b60 commit 1045f5f

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

sound/usb/card.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ struct snd_usb_endpoint {
129129
in a stream */
130130
bool implicit_fb_sync; /* syncs with implicit feedback */
131131
bool lowlatency_playback; /* low-latency playback mode */
132-
bool need_setup; /* (re-)need for configure? */
132+
bool need_setup; /* (re-)need for hw_params? */
133+
bool need_prepare; /* (re-)need for prepare? */
133134

134135
/* for hw constraints */
135136
const struct audioformat *cur_audiofmt;

sound/usb/endpoint.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ snd_usb_endpoint_open(struct snd_usb_audio *chip,
824824

825825
ep->implicit_fb_sync = fp->implicit_fb;
826826
ep->need_setup = true;
827+
ep->need_prepare = true;
827828

828829
usb_audio_dbg(chip, " channels=%d, rate=%d, format=%s, period_bytes=%d, periods=%d, implicit_fb=%d\n",
829830
ep->cur_channels, ep->cur_rate,
@@ -952,7 +953,7 @@ void snd_usb_endpoint_close(struct snd_usb_audio *chip,
952953
/* Prepare for suspening EP, called from the main suspend handler */
953954
void snd_usb_endpoint_suspend(struct snd_usb_endpoint *ep)
954955
{
955-
ep->need_setup = true;
956+
ep->need_prepare = true;
956957
if (ep->iface_ref)
957958
ep->iface_ref->need_setup = true;
958959
if (ep->clock_ref)
@@ -1335,9 +1336,12 @@ int snd_usb_endpoint_set_params(struct snd_usb_audio *chip,
13351336
struct snd_usb_endpoint *ep)
13361337
{
13371338
const struct audioformat *fmt = ep->cur_audiofmt;
1338-
int err;
1339+
int err = 0;
13391340

13401341
mutex_lock(&chip->mutex);
1342+
if (!ep->need_setup)
1343+
goto unlock;
1344+
13411345
/* release old buffers, if any */
13421346
err = release_urbs(ep, false);
13431347
if (err < 0)
@@ -1386,8 +1390,11 @@ int snd_usb_endpoint_set_params(struct snd_usb_audio *chip,
13861390
ep->curframesize = ep->curpacksize / ep->cur_frame_bytes;
13871391

13881392
err = update_clock_ref_rate(chip, ep);
1389-
if (err >= 0)
1393+
if (err >= 0) {
1394+
ep->need_setup = false;
13901395
err = 0;
1396+
}
1397+
13911398
unlock:
13921399
mutex_unlock(&chip->mutex);
13931400
return err;
@@ -1437,7 +1444,7 @@ int snd_usb_endpoint_prepare(struct snd_usb_audio *chip,
14371444
mutex_lock(&chip->mutex);
14381445
if (WARN_ON(!ep->iface_ref))
14391446
goto unlock;
1440-
if (!ep->need_setup)
1447+
if (!ep->need_prepare)
14411448
goto unlock;
14421449

14431450
/* If the interface has been already set up, just set EP parameters */
@@ -1491,7 +1498,7 @@ int snd_usb_endpoint_prepare(struct snd_usb_audio *chip,
14911498
ep->iface_ref->need_setup = false;
14921499

14931500
done:
1494-
ep->need_setup = false;
1501+
ep->need_prepare = false;
14951502
err = 1;
14961503

14971504
unlock:

0 commit comments

Comments
 (0)