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 --- 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; }