usb: dwc3: core: avoid reading register after bus clk is disabled
Subsystems (3)
PATCH 1/1 usb: dwc3: core: avoid reading register after bus clk is disabled
The driver may go through below sequence when works as device mode:
dwc3_suspend()
dwc3_suspend_common()
dwc3_core_exit()
dwc3_clk_disable()
clk_disable_unprepare(dwc->bus_clk);
dwc3_enable_susphy()
dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(i));Then the driver will read dwc3 register after bus clk is disabled. If this happens, the kernel will hang there. This will move dwc3_enable_susphy() ahead to avoid such issue.
--- drivers/usb/dwc3/core.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/usb/dwc3/core.c +9 -9
@@ -2347,6 +2347,15 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) (dwc3_readl (dwc->regs,DWC3_GUSB3PIPECTL (0 )) &DWC3_GUSB3PIPECTL_SUSPHY ); +if (!PMSG_IS_AUTO (msg)) { +/* +* TI AM62 platform requires SUSPHY to be +* enabled for system suspend to work. +*/ +if (!dwc->susphy_state) +dwc3_enable_susphy (dwc, true); + } +switch (dwc->current_dr_role) {case DWC3_GCTL_PRTCAP_DEVICE :if (pm_runtime_suspended (dwc->dev))
@@ -2398,15 +2407,6 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)break ; } -if (!PMSG_IS_AUTO (msg)) { -/* -* TI AM62 platform requires SUSPHY to be -* enabled for system suspend to work. -*/ -if (!dwc->susphy_state) -dwc3_enable_susphy (dwc, true); - } -return 0 ; }
Signature · 1 line
2.34.1
Hello Xu,
Quoted 10 lines · Xu Yang
The driver may go through below sequence when works as device mode:
dwc3_suspend()
dwc3_suspend_common()dwc3_core_exit() dwc3_clk_disable() clk_disable_unprepare(dwc->bus_clk); dwc3_enable_susphy() dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(i));
Quoted 7 lines
Then the driver will read dwc3 register after bus clk is disabled. If this happens, the kernel will hang there. This will move
dwc3_enable_susphy()ahead to avoid such issue.Fixes 705e3ce37bcc ("usb: dwc3: core: Fix system suspend on TI AM62 platforms")Signed-off-by Xu Yang <[email protected]>
Thank you for the patch. But this was already addressed yesterday.
https://lore.kernel.org/all/[email protected]/
drivers/usb/dwc3/core.c static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) · line 2350
Quoted 13 lines
--- drivers/usb/dwc3/core.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)drivers/usb/dwc3/core.c +1
-0@@ -2347,6 +2347,15 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) (dwc3_readl (dwc->regs,DWC3_GUSB3PIPECTL (0 )) &DWC3_GUSB3PIPECTL_SUSPHY ); +if (!PMSG_IS_AUTO (msg)) {
This alone is not enough as device might have been runtime suspended before system suspend and we will still try to access the registers below causing a fault.
Quoted 27 lines
drivers/usb/dwc3/core.c +8
-9+/* +* TI AM62 platform requires SUSPHY to be +* enabled for system suspend to work. +*/ +if (!dwc->susphy_state) +dwc3_enable_susphy (dwc, true); + } +switch (dwc->current_dr_role) {case DWC3_GCTL_PRTCAP_DEVICE :if (pm_runtime_suspended (dwc->dev))@@ -2398,15 +2407,6 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)break ; } -if (!PMSG_IS_AUTO (msg)) { -/* -* TI AM62 platform requires SUSPHY to be -* enabled for system suspend to work. -*/ -if (!dwc->susphy_state) -dwc3_enable_susphy (dwc, true); - } -return 0 ; }
Signature · 2 lines
cheers, -roger
Quoted 17 lines · Roger Quadros
Hello Xu,
Quoted 14 lines · Xu Yang
The driver may go through below sequence when works as device mode:
dwc3_suspend()
dwc3_suspend_common()dwc3_core_exit() dwc3_clk_disable() clk_disable_unprepare(dwc->bus_clk); dwc3_enable_susphy() dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(i));Then the driver will read dwc3 register after bus clk is disabled. If this happens, the kernel will hang there. This will move
dwc3_enable_susphy()ahead to avoid such issue.
Quoted 7 lines
Quoted 3 lines
Fixes 705e3ce37bcc ("usb: dwc3: core: Fix system suspend on TI AM62 platforms")Signed-off-by Xu Yang <[email protected]>Thank you for the patch. But this was already addressed yesterday.
Got it! Thanks!
Quoted 13 lines
Quoted 13 lines
--- drivers/usb/dwc3/core.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)drivers/usb/dwc3/core.c +0
-0@@ -2347,6 +2347,15 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) (dwc3_readl (dwc->regs,DWC3_GUSB3PIPECTL (0 )) &DWC3_GUSB3PIPECTL_SUSPHY );
Quoted 4 lines
drivers/usb/dwc3/core.c static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) · line 2350
Quoted 1 line
drivers/usb/dwc3/core.c +1
-0+if (!PMSG_IS_AUTO (msg)) {This alone is not enough as device might have been runtime suspended before system suspend and we will still try to access the registers below causing a fault.
Okay. Good!
Best Regards,
Xu Yang