usb: dwc3: gadget: Avoid starting DWC3 gadget during UDC unbind

There is a race present where the DWC3 runtime resume runs in parallel
to the UDC unbind sequence.  This will eventually lead to a possible
scenario where we are enabling the run/stop bit, without a valid
composition defined.

Thread#1 (handling UDC unbind):
--> continue UDC unbind sequence
-->Thread#2 is running in parallel here

Thread#2 (handing next cable connect)
      -->dwc->gadget_driver is NOT NULL yet
      --> _dwc3gadget_start()

Fix this by tracking the pullup disable routine, and avoiding resuming
of the DWC3 gadget.  Once the UDC is re-binded, that will trigger the
pullup enable routine, which would handle enabling the DWC3 gadget.

Acked-by: Felipe Balbi <>
Signed-off-by: Wesley Cheng <>
Signed-off-by: Greg Kroah-Hartman <>
2 files changed