{
        int i;
 
+       /* If req->trb is not set, then the request has not started */
+       if (!req->trb)
+               return;
+
        /*
         * If request was already started, this means we had to
         * stop the transfer. With that we also need to ignore
 {
        struct dwc3_gadget_ep_cmd_params        params;
        struct dwc3                             *dwc = dep->dwc;
+       struct dwc3_request                     *req;
+       struct dwc3_request                     *tmp;
        int                                     ret;
 
        if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) {
                else
                        dep->flags |= DWC3_EP_STALL;
        } else {
+               /*
+                * Don't issue CLEAR_STALL command to control endpoints. The
+                * controller automatically clears the STALL when it receives
+                * the SETUP token.
+                */
+               if (dep->number <= 1) {
+                       dep->flags &= ~(DWC3_EP_STALL | DWC3_EP_WEDGE);
+                       return 0;
+               }
 
                ret = dwc3_send_clear_stall_ep_cmd(dep);
-               if (ret)
+               if (ret) {
                        dev_err(dwc->dev, "failed to clear STALL on %s\n",
                                        dep->name);
-               else
-                       dep->flags &= ~(DWC3_EP_STALL | DWC3_EP_WEDGE);
+                       return ret;
+               }
+
+               dep->flags &= ~(DWC3_EP_STALL | DWC3_EP_WEDGE);
+
+               dwc3_stop_active_transfer(dep, true, true);
+
+               list_for_each_entry_safe(req, tmp, &dep->started_list, list)
+                       dwc3_gadget_move_cancelled_request(req);
+
+               list_for_each_entry_safe(req, tmp, &dep->pending_list, list)
+                       dwc3_gadget_move_cancelled_request(req);
+
+               if (!(dep->flags & DWC3_EP_END_TRANSFER_PENDING)) {
+                       dep->flags &= ~DWC3_EP_DELAY_START;
+                       dwc3_gadget_ep_cleanup_cancelled_requests(dep);
+               }
        }
 
        return ret;