From: Alan Stern <stern@rowland.harvard.edu>
To: Xu Yang <xu.yang_2@nxp.com>
Cc: gregkh@linuxfoundation.org, khtsai@google.com,
kexinsun@smail.nju.edu.cn, hhhuuu@google.com, kees@kernel.org,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
imx@lists.linux.dev, jun.li@nxp.com
Subject: Re: [PATCH] usb: gadget: udc: skip pullup() if already connected
Date: Wed, 22 Apr 2026 10:24:33 -0400 [thread overview]
Message-ID: <9832a30a-ee4b-4e94-94d4-36bc1e658d9a@rowland.harvard.edu> (raw)
In-Reply-To: <5ybgpy342zdtcudp3brizuxyisrv5zxsfegwawtaxyvlncnvcn@htqd6bnqdv5j>
On Wed, Apr 22, 2026 at 07:31:16PM +0800, Xu Yang wrote:
> On Tue, Apr 21, 2026 at 10:37:53AM -0400, Alan Stern wrote:
> > On Tue, Apr 21, 2026 at 04:20:50PM +0800, Xu Yang wrote:
> > > The device controller may update vbus status via usb_udc_vbus_handler(),
> > > which tries to connect the gadget even though gadget_bind_driver() has
> > > already called usb_udc_connect_control_locked(). This causes pullup() to
> > > be called twice. Avoid this by checking if gadget->connected is true.
> >
> > This patch is wrong. To see why, read the comments just below the end
> > of the patch and see also usb_gadget_activate().
>
> OK. So it breaks usb_gadget_activate() as usb_udc_connect_control_locked()
> return early.
>
> I think usb_gadget_activate() needs to set gadget->connected as false before
> running usb_gadget_connect_locked() just like usb_gadget_deactivate() sets
> gadget->connected as true after running usb_gadget_disconnect_locked().
>
> Then it will work correctly, do you agree?
Yes, that should take care of it. Don't forget to update the patch
description as well.
> > (Also, is there really anything wrong with calling pullup() twice in a
> > row?)
>
> It depends on the device controller driver. But currently only a few drivers
> call usb_udc_vbus_handler(), so I think the issue hasn't shown up.
>
> When you look at the pullup() implementation of some UDC driver, you may see
> they do more complicated thing than just pulling the data line up. Such as
> cdnsp_gadget_pullup(), dwc3_gadget_pullup(), etc.
>
> Therefore, I think the UDC core need to handle this well to avoid calling
> pullup() twice in a row.
Okay.
Alan Stern
prev parent reply other threads:[~2026-04-22 14:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 8:20 Xu Yang
2026-04-21 14:37 ` Alan Stern
2026-04-21 15:27 ` Bjørn Mork
2026-04-21 20:18 ` Alan Stern
2026-04-22 11:31 ` Xu Yang
2026-04-22 14:24 ` Alan Stern [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=9832a30a-ee4b-4e94-94d4-36bc1e658d9a@rowland.harvard.edu \
--to=stern@rowland.harvard.edu \
--cc=gregkh@linuxfoundation.org \
--cc=hhhuuu@google.com \
--cc=imx@lists.linux.dev \
--cc=jun.li@nxp.com \
--cc=kees@kernel.org \
--cc=kexinsun@smail.nju.edu.cn \
--cc=khtsai@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=xu.yang_2@nxp.com \
/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®