From: Jaegyun Lee <dreams200260@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Neill Kapron <nkapron@google.com>
Cc: Jaegyun Lee <dreams200260@gmail.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: [PATCH] usb: gadget: f_midi: restart IN transfers after SET_INTERFACE
Date: Sun, 29 Nov 2026 23:05:55 +0900 [thread overview]
Message-ID: <20261129140555.651497-1-dreams200260@gmail.com> (raw)
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;
}
reply other threads:[~2026-11-29 14:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261129140555.651497-1-dreams200260@gmail.com \
--to=dreams200260@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=nkapron@google.com \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®