From f1b53c2ed22701ea33d917752fc405dc987872ed Mon Sep 17 00:00:00 2001 From: Jianing Ren Date: Wed, 26 Feb 2020 11:49:56 +0800 Subject: [PATCH] usb: dwc3: gadget: fixed crash when unplugged usb cable If the USB cable is unplugged when powered on or connected to PC, it will cause the system to freeze. The final log is as follows: [ 5.109122] read descriptors [ 5.109180] read strings [ 5.113205] udc fe800000.dwc3: registering UDC driver [g1] The crash is caused by visit registers of dwc3 when PD is off. the function dwc3_gadget_set_speed is added in udc_bind_to_driver in kernel 4.19 update. We need jump of this function when dwc3 is suspended. Change-Id: Ie0337aaf225543b4e9e05ee57a5eb7416797d56e Signed-off-by: Jianing Ren --- drivers/usb/dwc3/gadget.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 1d408f1f1750..6eead843769b 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2174,6 +2174,14 @@ static void dwc3_gadget_set_speed(struct usb_gadget *g, unsigned long flags; u32 reg; + /* + * To prevent Android 10 from trying to call UDC and failed constantly + * while dwc3 is suspended, we let the UDC node always exist. + * If not return here, it may cause crashes. + */ + if (pm_runtime_suspended(dwc->dev)) + return; + spin_lock_irqsave(&dwc->lock, flags); reg = dwc3_readl(dwc->regs, DWC3_DCFG); reg &= ~(DWC3_DCFG_SPEED_MASK);