linux-sound.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ALSA: scarlett2: Add retry on -EPROTO from scarlett2_usb_tx()
@ 2025-07-28  9:30 Geoffrey D. Bennett
  2025-07-28 10:25 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Geoffrey D. Bennett @ 2025-07-28  9:30 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: Takashi Iwai, linux-sound

During communication with Focusrite Scarlett Gen 2/3/4 USB audio
interfaces, -EPROTO is sometimes returned from scarlett2_usb_tx(),
snd_usb_ctl_msg() which can cause initialisation and control
operations to fail intermittently.

This patch adds up to 5 retries in scarlett2_usb(), with a delay
starting at 5ms and doubling each time. This follows the same approach
as the fix for usb_set_interface() in endpoint.c (commit f406005e162b
("ALSA: usb-audio: Add retry on -EPROTO from usb_set_interface()")),
which resolved similar -EPROTO issues during device initialisation,
and is the same approach as in fcp.c:fcp_usb().

Fixes: 9e4d5c1be21f ("ALSA: usb-audio: Scarlett Gen 2 mixer interface")
Closes: https://github.com/geoffreybennett/linux-fcp/issues/41
Cc: stable@vger.kernel.org
Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
---
 sound/usb/mixer_scarlett2.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/sound/usb/mixer_scarlett2.c b/sound/usb/mixer_scarlett2.c
index 93589e86828a..c6dbfbbe24d0 100644
--- a/sound/usb/mixer_scarlett2.c
+++ b/sound/usb/mixer_scarlett2.c
@@ -2351,6 +2351,8 @@ static int scarlett2_usb(
 	struct scarlett2_usb_packet *req, *resp = NULL;
 	size_t req_buf_size = struct_size(req, data, req_size);
 	size_t resp_buf_size = struct_size(resp, data, resp_size);
+	int retries = 0;
+	const int max_retries = 5;
 	int err;
 
 	req = kmalloc(req_buf_size, GFP_KERNEL);
@@ -2374,10 +2376,15 @@ static int scarlett2_usb(
 	if (req_size)
 		memcpy(req->data, req_data, req_size);
 
+retry:
 	err = scarlett2_usb_tx(dev, private->bInterfaceNumber,
 			       req, req_buf_size);
 
 	if (err != req_buf_size) {
+		if (err == -EPROTO && ++retries <= max_retries) {
+			msleep(5 * (1 << (retries - 1)));
+			goto retry;
+		}
 		usb_audio_err(
 			mixer->chip,
 			"%s USB request result cmd %x was %d\n",
-- 
2.45.0


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

* Re: [PATCH] ALSA: scarlett2: Add retry on -EPROTO from scarlett2_usb_tx()
  2025-07-28  9:30 [PATCH] ALSA: scarlett2: Add retry on -EPROTO from scarlett2_usb_tx() Geoffrey D. Bennett
@ 2025-07-28 10:25 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2025-07-28 10:25 UTC (permalink / raw)
  To: Geoffrey D. Bennett; +Cc: Takashi Iwai, Takashi Iwai, linux-sound

On Mon, 28 Jul 2025 11:30:35 +0200,
Geoffrey D. Bennett wrote:
> 
> During communication with Focusrite Scarlett Gen 2/3/4 USB audio
> interfaces, -EPROTO is sometimes returned from scarlett2_usb_tx(),
> snd_usb_ctl_msg() which can cause initialisation and control
> operations to fail intermittently.
> 
> This patch adds up to 5 retries in scarlett2_usb(), with a delay
> starting at 5ms and doubling each time. This follows the same approach
> as the fix for usb_set_interface() in endpoint.c (commit f406005e162b
> ("ALSA: usb-audio: Add retry on -EPROTO from usb_set_interface()")),
> which resolved similar -EPROTO issues during device initialisation,
> and is the same approach as in fcp.c:fcp_usb().
> 
> Fixes: 9e4d5c1be21f ("ALSA: usb-audio: Scarlett Gen 2 mixer interface")
> Closes: https://github.com/geoffreybennett/linux-fcp/issues/41
> Cc: stable@vger.kernel.org
> Signed-off-by: Geoffrey D. Bennett <g@b4.vu>

Thanks, applied now.


Takashi

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

end of thread, other threads:[~2025-07-28 10:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-28  9:30 [PATCH] ALSA: scarlett2: Add retry on -EPROTO from scarlett2_usb_tx() Geoffrey D. Bennett
2025-07-28 10:25 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).