mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: f_midi: restart IN transfers after SET_INTERFACE
@ 2026-11-29 14:05 Jaegyun Lee
  0 siblings, 0 replies; only message in thread
From: Jaegyun Lee @ 2026-11-29 14:05 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Neill Kapron
  Cc: Jaegyun Lee, linux-usb, linux-kernel, stable

When the host sends SET_INTERFACE for the MIDIStreaming interface,
f_midi_set_alt() calls f_midi_start_ep(), which starts with
usb_ep_disable(). f_midi_disable() is not called first, so the IN
requests stay in midi->in_req_fifo. usb_ep_disable() gives back the
queued IN requests with an error status, but f_midi_complete() only
resets req->length on a successful completion; the -ECONNABORTED/
-ECONNRESET/-ESHUTDOWN branch handles the OUT endpoint only:

	if (ep == midi->out_ep) {
		f_midi_handle_out_data(ep, req);
		/* We don't need to free IN requests because it's handled
		 * by the midi->in_req_fifo. */
		free_ep_req(ep, req);
	}
	return;

If any of them was in flight when the host sent SET_INTERFACE, it
stays in the fifo with req->length > 0; once it reaches the head,
f_midi_do_transmit() returns without queueing anything:

	if (req->length > 0)
		return 0;

Since nothing is queued on the re-enabled IN endpoint, no completion
ever resets a length and MIDI output from the gadget stays stopped
until the function is disabled (disconnect or SET_CONFIGURATION).
A writer on the gadget's rawmidi device blocks in snd_rawmidi_write().

To reproduce, fill the IN requests from the gadget while the host does
not read, then send SET_INTERFACE(1, 0) from the host and read bulk IN.

Mark IN requests given back with an error as free, and restart
transmission after SET_INTERFACE.

Fixes: e1e3d7ec5da3 ("usb: gadget: f_midi: pre-allocate IN requests")
Cc: stable@vger.kernel.org
Assisted-by: ZCode:GLM-5.4
Signed-off-by: Jaegyun Lee <dreams200260@gmail.com>
---
 drivers/usb/gadget/function/f_midi.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -299,6 +299,8 @@ f_midi_complete(struct usb_ep *ep, struc
 			/* We don't need to free IN requests because it's handled
 			 * by the midi->in_req_fifo. */
 			free_ep_req(ep, req);
+		} else if (ep == midi->in_ep) {
+			req->length = 0;
 		}
 		return;
 
@@ -412,6 +414,8 @@ static int f_midi_set_alt(struct usb_fun
 		}
 	}
 
+	queue_work(system_highpri_wq, &midi->work);
+
 	return 0;
 }
 

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

only message in thread, other threads:[~2026-11-29 14:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29 14:05 [PATCH] usb: gadget: f_midi: restart IN transfers after SET_INTERFACE Jaegyun Lee

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®