The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
Cc: Takashi Iwai <tiwai@suse.de>, Jaroslav Kysela <perex@perex.cz>,
	Bin Yu <byu@xidian.edu.cn>, Cheng Wen <wencheng@xidian.edu.cn>,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] ALSA: line6: Fix endless MIDI transmit loop on closed substream
Date: Sun, 06 Dec 2026 12:11:02 +0100	[thread overview]
Message-ID: <877bhmslyx.wl-tiwai@suse.de> (raw)
In-Reply-To: <20261204161327.16858-1-25031212351@stu.xidian.edu.cn>

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

      reply	other threads:[~2026-12-06 11:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877bhmslyx.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=25031212351@stu.xidian.edu.cn \
    --cc=byu@xidian.edu.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=stable@vger.kernel.org \
    --cc=wencheng@xidian.edu.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox