From f2f05457ef61e89313d30c010fd5c49d0b577960 Mon Sep 17 00:00:00 2001 From: Pratham Pratap Date: Wed, 30 Jun 2021 21:50:48 +0530 Subject: [PATCH] usb: gadget: Restart USB session if start xfer fails for ep0 Currently driver is just proceding further if start xfer times out for ep0. Start xfer failing for ep0 indicates that the controller is already in bad state and it can access unmapped address leading to SMMU fault. Prevent this by marking this as an error event and restart USB session. Change-Id: Ia46387e16a79318ad945079ced7209a8f2bf47ef Signed-off-by: Pratham Pratap --- drivers/usb/dwc3/ep0.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index a0cbefaad94c..eb810f2aa6cb 100644 --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c @@ -78,8 +78,20 @@ static int dwc3_ep0_start_trans(struct dwc3_ep *dep) params.param1 = lower_32_bits(dwc->ep0_trb_addr); ret = dwc3_send_gadget_ep_cmd(dep, DWC3_DEPCMD_STARTTRANSFER, ¶ms); - if (ret < 0) + if (ret < 0) { + if (ret == -ETIMEDOUT) { + /* + * If start transfer is timing out then mark it as an error + * event since the controller is already in an unknown + * state. + */ + dbg_log_string("%s: error event seen\n", __func__); + dwc->err_evt_seen = true; + dwc3_notify_event(dwc, DWC3_CONTROLLER_ERROR_EVENT, 0); + dwc3_notify_event(dwc, DWC3_CONTROLLER_NOTIFY_CLEAR_DB, 0); + } return ret; + } dwc->ep0_next_event = DWC3_EP0_COMPLETE;