Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ALSA: usb-audio: Add retry on -EPROTO from usb_set_interface()
@ 2025-04-16 18:49 Geoffrey D. Bennett
  2025-04-20  8:39 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Geoffrey D. Bennett @ 2025-04-16 18:49 UTC (permalink / raw)
  To: Takashi Iwai, Jaroslav Kysela; +Cc: linux-sound

During initialisation of Focusrite USB audio interfaces, -EPROTO is
sometimes returned from usb_set_interface(), which sometimes prevents
the device from working: subsequent usb_set_interface() and
uac_clock_source_is_valid() calls fail.

This patch adds up to 5 retries in endpoint_set_interface(), with a
delay starting at 5ms and doubling each time. 5 retries was chosen to
allow for longer than expected waits for the interface to start
responding correctly; in testing, a single 5ms delay was sufficient to
fix the issue.

Closes: https://github.com/geoffreybennett/fcp-support/issues/2
Cc: stable@vger.kernel.org
Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
---
 sound/usb/endpoint.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
index a29f28eb7d0c..f36ec98da460 100644
--- a/sound/usb/endpoint.c
+++ b/sound/usb/endpoint.c
@@ -926,6 +926,8 @@ static int endpoint_set_interface(struct snd_usb_audio *chip,
 {
 	int altset = set ? ep->altsetting : 0;
 	int err;
+	int retries = 0;
+	const int max_retries = 5;
 
 	if (ep->iface_ref->altset == altset)
 		return 0;
@@ -935,8 +937,13 @@ static int endpoint_set_interface(struct snd_usb_audio *chip,
 
 	usb_audio_dbg(chip, "Setting usb interface %d:%d for EP 0x%x\n",
 		      ep->iface, altset, ep->ep_num);
+retry:
 	err = usb_set_interface(chip->dev, ep->iface, altset);
 	if (err < 0) {
+		if (err == -EPROTO && ++retries <= max_retries) {
+			msleep(5 * (1 << (retries - 1)));
+			goto retry;
+		}
 		usb_audio_err_ratelimited(
 			chip, "%d:%d: usb_set_interface failed (%d)\n",
 			ep->iface, altset, err);
-- 
2.45.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ALSA: usb-audio: Add retry on -EPROTO from usb_set_interface()
  2025-04-16 18:49 [PATCH] ALSA: usb-audio: Add retry on -EPROTO from usb_set_interface() Geoffrey D. Bennett
@ 2025-04-20  8:39 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2025-04-20  8:39 UTC (permalink / raw)
  To: Geoffrey D. Bennett; +Cc: Takashi Iwai, Jaroslav Kysela, linux-sound

On Wed, 16 Apr 2025 20:49:23 +0200,
Geoffrey D. Bennett wrote:
> 
> During initialisation of Focusrite USB audio interfaces, -EPROTO is
> sometimes returned from usb_set_interface(), which sometimes prevents
> the device from working: subsequent usb_set_interface() and
> uac_clock_source_is_valid() calls fail.
> 
> This patch adds up to 5 retries in endpoint_set_interface(), with a
> delay starting at 5ms and doubling each time. 5 retries was chosen to
> allow for longer than expected waits for the interface to start
> responding correctly; in testing, a single 5ms delay was sufficient to
> fix the issue.
> 
> Closes: https://github.com/geoffreybennett/fcp-support/issues/2
> Cc: stable@vger.kernel.org
> Signed-off-by: Geoffrey D. Bennett <g@b4.vu>

Applied now.  Thanks.


Takashi

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-04-20  8:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-16 18:49 [PATCH] ALSA: usb-audio: Add retry on -EPROTO from usb_set_interface() Geoffrey D. Bennett
2025-04-20  8:39 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox