Re: [PATCH] usb: gadget: udc: skip pullup() if already connected

From: Xu Yang

Date: Wed Apr 22 2026 - 07:36:31 EST


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?

>
> (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.

Thanks,
Xu Yang