* [PATCH] ALSA: line6: Fix endless MIDI transmit loop on closed substream
@ 2026-12-04 16:13 YuanZhe Liu
2026-12-06 11:11 ` Takashi Iwai
0 siblings, 1 reply; 2+ messages in thread
From: YuanZhe Liu @ 2026-12-04 16:13 UTC (permalink / raw)
To: Takashi Iwai
Cc: Jaroslav Kysela, Bin Yu, Cheng Wen, linux-sound, linux-kernel, stable
line6_midi_transmit() moves data from the rawmidi output buffer into the
driver's MIDI buffer in a loop:
for (;;) {
...
done = snd_rawmidi_transmit_peek(substream, chunk, req);
if (done == 0)
break;
line6_midibuf_write(mb, chunk, done);
snd_rawmidi_transmit_ack(substream, done);
}
snd_rawmidi_transmit_peek() returns -EBADFD when the substream has been
closed or its runtime released, but the loop exits only on a zero return.
line6_midibuf_write() turns the negative length into a no-op and
snd_rawmidi_transmit_ack() fails without advancing the buffer pointers,
so the loop spins forever.
That state is reachable when userspace closes the rawmidi output while a
MIDI URB is still in flight. snd_rawmidi_drain_output() skips the
driver's drain callback when the wait is interrupted by a signal, and
line6_midi_output_close() does not stop pending URBs. When such an URB
completes, midi_sent() calls line6_midi_transmit() for the already closed
substream, and the CPU stays in the URB completion softirq without ever
reporting a quiescent state.
Break out of the loop on any non-positive return, treating a negative
error as "no data left", as was already done for the receive path in
commit d683469b3c93 ("ALSA: line6: Fix endless MIDI read loop").
Fixes: 463a20fd3481 ("ALSA: rawmidi: Check stream state at exported functions")
Cc: stable@vger.kernel.org
Co-developed-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Bin Yu <byu@xidian.edu.cn>
Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
---
sound/usb/line6/midi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/usb/line6/midi.c b/sound/usb/line6/midi.c
index af01b649393c..9a0234834eaa 100644
--- a/sound/usb/line6/midi.c
+++ b/sound/usb/line6/midi.c
@@ -48,7 +48,7 @@ static void line6_midi_transmit(struct snd_rawmidi_substream *substream)
LINE6_FALLBACK_MAXPACKETSIZE);
done = snd_rawmidi_transmit_peek(substream, chunk, req);
- if (done == 0)
+ if (done <= 0)
break;
line6_midibuf_write(mb, chunk, done);
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] ALSA: line6: Fix endless MIDI transmit loop on closed substream
2026-12-04 16:13 [PATCH] ALSA: line6: Fix endless MIDI transmit loop on closed substream YuanZhe Liu
@ 2026-12-06 11:11 ` Takashi Iwai
0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2026-12-06 11:11 UTC (permalink / raw)
To: YuanZhe Liu
Cc: Takashi Iwai, Jaroslav Kysela, Bin Yu, Cheng Wen, linux-sound,
linux-kernel, stable
On Fri, 04 Dec 2026 17:13:27 +0100,
YuanZhe Liu wrote:
>
> line6_midi_transmit() moves data from the rawmidi output buffer into the
> driver's MIDI buffer in a loop:
>
> for (;;) {
> ...
> done = snd_rawmidi_transmit_peek(substream, chunk, req);
> if (done == 0)
> break;
> line6_midibuf_write(mb, chunk, done);
> snd_rawmidi_transmit_ack(substream, done);
> }
>
> snd_rawmidi_transmit_peek() returns -EBADFD when the substream has been
> closed or its runtime released, but the loop exits only on a zero return.
> line6_midibuf_write() turns the negative length into a no-op and
> snd_rawmidi_transmit_ack() fails without advancing the buffer pointers,
> so the loop spins forever.
>
> That state is reachable when userspace closes the rawmidi output while a
> MIDI URB is still in flight. snd_rawmidi_drain_output() skips the
> driver's drain callback when the wait is interrupted by a signal, and
> line6_midi_output_close() does not stop pending URBs. When such an URB
> completes, midi_sent() calls line6_midi_transmit() for the already closed
> substream, and the CPU stays in the URB completion softirq without ever
> reporting a quiescent state.
>
> Break out of the loop on any non-positive return, treating a negative
> error as "no data left", as was already done for the receive path in
> commit d683469b3c93 ("ALSA: line6: Fix endless MIDI read loop").
>
> Fixes: 463a20fd3481 ("ALSA: rawmidi: Check stream state at exported functions")
> Cc: stable@vger.kernel.org
> Co-developed-by: Bin Yu <byu@xidian.edu.cn>
> Signed-off-by: Bin Yu <byu@xidian.edu.cn>
> Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn>
> Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn>
> Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
Applied to for-next branch. Thanks.
Takashi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-06 11:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-04 16:13 [PATCH] ALSA: line6: Fix endless MIDI transmit loop on closed substream YuanZhe Liu
2026-12-06 11:11 ` Takashi Iwai
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®