From: Greg KH <gregkh@linuxfoundation.org>
To: Haoli Zhang <26031212468@stu.xidian.edu.cn>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH] usb: gadget: f_midi2: disable endpoints before freeing descriptors
Date: Fri, 20 Nov 2026 09:10:36 +0100 [thread overview]
Message-ID: <2026112002-agony-calibrate-ce07@gregkh> (raw)
In-Reply-To: <20261120042607.1347854-1-26031212468@stu.xidian.edu.cn>
On Fri, Nov 20, 2026 at 12:26:07PM +0800, Haoli Zhang wrote:
> The dummy_hcd driver keeps a pointer to an endpoint descriptor while the
> endpoint is enabled, and its timer dereferences that pointer in
> find_endpoint(). However, f_midi2_unbind() frees the function descriptors,
> while f_midi2_disable() currently only resets operation_mode. When the
> function is removed, an endpoint can therefore remain enabled while its
> descriptor storage is released.
>
> Disable the MIDI 1.0 endpoints and all MIDI 2.0 endpoints from
> f_midi2_disable() before the unbind callback releases the descriptors.
> Keep f_midi2_stop_eps() unchanged so altsetting transitions retain their
> existing request cleanup behavior.
>
> Reported-by: syzbot+599d4e8994a656eafe15@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=599d4e8994a656eafe15
> Co-developed-by: Jinning Zhang <25031212117@stu.xidian.edu.cn>
> Signed-off-by: Jinning Zhang <25031212117@stu.xidian.edu.cn>
> Co-developed-by: Bin Yu <byu@xidian.edu.cn>
> Signed-off-by: Bin Yu <byu@xidian.edu.cn>
> Signed-off-by: Haoli Zhang <26031212468@stu.xidian.edu.cn>
> ---
> drivers/usb/gadget/function/f_midi2.c | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git a/drivers/usb/gadget/function/f_midi2.c b/drivers/usb/gadget/function/f_midi2.c
> --- a/drivers/usb/gadget/function/f_midi2.c
> +++ b/drivers/usb/gadget/function/f_midi2.c
> @@ -1167,6 +1167,13 @@
> f_midi2_free_ep_reqs(ep_out);
> }
>
> +/* Disable an EP before its descriptors are released. */
That's not a good description of this function at all :(
> +static void f_midi2_disable_ep(struct f_midi2_usb_ep *usb_ep)
> +{
> + if (usb_ep->usb_ep)
> + usb_ep_disable(usb_ep->usb_ep);
> +}
> +
> /* start/queue both IN and OUT EPs */
> static int f_midi2_start_eps(struct f_midi2_usb_ep *ep_in,
> struct f_midi2_usb_ep *ep_out,
> @@ -1343,8 +1350,17 @@
> static void f_midi2_disable(struct usb_function *fn)
> {
> struct f_midi2 *midi2 = func_to_midi2(fn);
> + struct f_midi2_ep *ep;
> + int i;
>
> midi2->operation_mode = MIDI_OP_MODE_UNSET;
> + f_midi2_disable_ep(&midi2->midi1_ep_in);
> + f_midi2_disable_ep(&midi2->midi1_ep_out);
> + for (i = 0; i < midi2->num_eps; i++) {
> + ep = &midi2->midi2_eps[i];
> + f_midi2_disable_ep(&ep->ep_in);
> + f_midi2_disable_ep(&ep->ep_out);
Please just open-code the function you tried to write above, it will
make more sense here.
thanks,
greg k-h
next prev parent reply other threads:[~2026-11-20 8:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 4:26 [PATCH] usb: gadget: f_midi2: disable endpoints before freeing descriptors Haoli Zhang
2026-11-20 4:38 ` sashiko-bot
2026-11-20 8:10 ` Greg KH [this message]
2026-11-20 8:10 ` Greg KH
2026-11-20 9:21 ` [PATCH v2] " Haoli Zhang
2026-11-20 9:29 ` sashiko-bot
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=2026112002-agony-calibrate-ce07@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=26031212468@stu.xidian.edu.cn \
--cc=linux-usb@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.