mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ALSA: usb-audio: don't resubmit MIDI URBs at once on -EPIPE
@ 2026-10-29 16:57 Stjepan Poljak
  0 siblings, 0 replies; only message in thread
From: Stjepan Poljak @ 2026-10-29 16:57 UTC (permalink / raw)
  To: Takashi Iwai, Jaroslav Kysela; +Cc: Clemens Ladisch, linux-sound, linux-kernel

When a USB MIDI device answers with a stall, as a bus-powered keyboard
does while it is being switched off, snd_usbmidi_urb_error() falls
through to the default case: it logs "urb status -32" and returns 0, so
the completion handler resubmits the URB at once. That fails the same
way, so the URBs loop, logging every failure, until the disconnect is
processed.

On a Raspberry Pi 3B+ with a keyboard behind the onboard hub, that
disconnect is never processed. Printing to the framebuffer and serial
consoles holds the loop to about 250 messages a second, and all
interrupts are handled on CPU 0, so the hub's port change isn't handled:
the keyboard stays silent until it is replugged. With loglevel=3, the
same kernel processes the disconnect 0.04-0.24 s after the first error
and the keyboard works again.

Treat -EPIPE like the other errors seen while a device goes away: retry
from the error timer after ERROR_DELAY_JIFFIES, without a message. An
endpoint that is really halted wasn't cleared before either; it is now
retried every 100 ms instead of continuously.

Tested on the Raspberry Pi 3B+ (rpi-6.12.y, dwc_otg) with the default
console settings: after each off/on the disconnect is processed, the
keyboard re-enumerates and plays, and nothing is logged for the stall.

Assisted-by: LLM
Signed-off-by: Stjepan Poljak <stjepan.poljak@gmail.com>
---
This replaces "ALSA: usb-audio: reset a MIDI device whose input is stuck"
(v1: https://lore.kernel.org/linux-sound/20261026125751.1700779-1-stjepan.poljak@gmail.com/
 v2: <20261027152034.1871962-1-stjepan.poljak@gmail.com>). As Takashi
said, resetting the device was the wrong place to fix it. The disconnect
wasn't lost by the USB stack either: on mainline dwc2 and on dwc_otg
with loglevel=3, the same unpatched kernel gets it. It was this driver's
own resubmit loop starving the CPU that handles the interrupts.

The patch is against for-next; on the Pi I tested the same change on
rpi-6.12.y.

 sound/usb/midi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sound/usb/midi.c b/sound/usb/midi.c
index e3d157554061..5604c3fdbe3b 100644
--- a/sound/usb/midi.c
+++ b/sound/usb/midi.c
@@ -194,10 +194,11 @@ static int snd_usbmidi_urb_error(const struct urb *urb)
 	case -ESHUTDOWN:
 	case -ENODEV:
 		return -ENODEV;
-	/* errors that might occur during unplugging */
+	/* errors that might occur during unplugging or switching off */
 	case -EPROTO:
 	case -ETIME:
 	case -EILSEQ:
+	case -EPIPE:
 		return -EIO;
 	default:
 		dev_err(&urb->dev->dev, "urb status %d\n", urb->status);

base-commit: a4311e9447bbb219044db38897f95be112f46a8a
-- 
2.53.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-29 16:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-29 16:57 [PATCH] ALSA: usb-audio: don't resubmit MIDI URBs at once on -EPIPE Stjepan Poljak

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

all inboxes | Powered by JetHome®