* bit.
         */
        dwc3_stop_active_transfers(dwc);
-       __dwc3_gadget_stop(dwc);
        spin_unlock_irqrestore(&dwc->lock, flags);
 
        /*
         * remaining event generated by the controller while polling for
         * DSTS.DEVCTLHLT.
         */
-       return dwc3_gadget_run_stop(dwc, false);
+       ret = dwc3_gadget_run_stop(dwc, false);
+
+       /*
+        * Stop the gadget after controller is halted, so that if needed, the
+        * events to update EP0 state can still occur while the run/stop
+        * routine polls for the halted state.  DEVTEN is cleared as part of
+        * gadget stop.
+        */
+       spin_lock_irqsave(&dwc->lock, flags);
+       __dwc3_gadget_stop(dwc);
+       spin_unlock_irqrestore(&dwc->lock, flags);
+
+       return ret;
 }
 
 static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)