Re: [PATCH] usb: gadget: udc: skip pullup() if already connected
From: Alan Stern
Date: Tue Apr 21 2026 - 10:39:55 EST
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().
(Also, is there really anything wrong with calling pullup() twice in a
row?)
Alan Stern
> Signed-off-by: Xu Yang <xu.yang_2@xxxxxxx>
> ---
> drivers/usb/gadget/udc/core.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
> index e8861eaad907..be29daa7ad3c 100644
> --- a/drivers/usb/gadget/udc/core.c
> +++ b/drivers/usb/gadget/udc/core.c
> @@ -712,6 +712,9 @@ static int usb_gadget_connect_locked(struct usb_gadget *gadget)
> goto out;
> }
>
> + if (gadget->connected)
> + goto out;
> +
> if (gadget->deactivated || !gadget->udc->allow_connect || !gadget->udc->started) {
> /*
> * If the gadget isn't usable (because it is deactivated,
> --
> 2.34.1
>
>