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 <jianing.ren@rock-chips.com>
This commit is contained in:
Jianing Ren
2020-02-26 11:49:56 +08:00
committed by Tao Huang
parent 404c1b21e0
commit f1b53c2ed2

View File

@@ -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);