* [PATCH] usb: dwc2: host: Protect PCGCTL with lock in dwc2_port_resume()
@ 2015-10-14 22:58 Douglas Anderson
2015-10-16 18:06 ` John Youn
0 siblings, 1 reply; 2+ messages in thread
From: Douglas Anderson @ 2015-10-14 22:58 UTC (permalink / raw)
To: John Youn, balbi
Cc: Yunzhi Li, Heiko Stübner, linux-rockchip, Julius Werner,
gregory.herrero, yousaf.kaukab, dinguyen, Douglas Anderson,
johnyoun, gregkh, linux-usb, linux-kernel
>From code inspection, it appears to be unsafe to do a read-modify-write
of PCGCTL in dwc2_port_resume(). Let's make sure the spinlock is held
around this operation.
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---
drivers/usb/dwc2/hcd.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index af4e4a2..e79baf7 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -1500,6 +1500,8 @@ static void dwc2_port_resume(struct dwc2_hsotg *hsotg)
u32 hprt0;
u32 pcgctl;
+ spin_lock_irqsave(&hsotg->lock, flags);
+
/*
* If hibernation is supported, Phy clock is already resumed
* after registers restore.
@@ -1508,10 +1510,11 @@ static void dwc2_port_resume(struct dwc2_hsotg *hsotg)
pcgctl = dwc2_readl(hsotg->regs + PCGCTL);
pcgctl &= ~PCGCTL_STOPPCLK;
dwc2_writel(pcgctl, hsotg->regs + PCGCTL);
+ spin_unlock_irqrestore(&hsotg->lock, flags);
usleep_range(20000, 40000);
+ spin_lock_irqsave(&hsotg->lock, flags);
}
- spin_lock_irqsave(&hsotg->lock, flags);
hprt0 = dwc2_read_hprt0(hsotg);
hprt0 |= HPRT0_RES;
hprt0 &= ~HPRT0_SUSP;
--
2.6.0.rc2.230.g3dd15c0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] usb: dwc2: host: Protect PCGCTL with lock in dwc2_port_resume()
2015-10-14 22:58 [PATCH] usb: dwc2: host: Protect PCGCTL with lock in dwc2_port_resume() Douglas Anderson
@ 2015-10-16 18:06 ` John Youn
0 siblings, 0 replies; 2+ messages in thread
From: John Youn @ 2015-10-16 18:06 UTC (permalink / raw)
To: Douglas Anderson, John Youn, balbi
Cc: Yunzhi Li, Heiko Stübner, linux-rockchip, Julius Werner,
gregory.herrero, yousaf.kaukab, dinguyen, gregkh, linux-usb,
linux-kernel
On 10/14/2015 3:58 PM, Douglas Anderson wrote:
> From code inspection, it appears to be unsafe to do a read-modify-write
> of PCGCTL in dwc2_port_resume(). Let's make sure the spinlock is held
> around this operation.
>
> Signed-off-by: Douglas Anderson <dianders@chromium.org>
> ---
> drivers/usb/dwc2/hcd.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
> index af4e4a2..e79baf7 100644
> --- a/drivers/usb/dwc2/hcd.c
> +++ b/drivers/usb/dwc2/hcd.c
> @@ -1500,6 +1500,8 @@ static void dwc2_port_resume(struct dwc2_hsotg *hsotg)
> u32 hprt0;
> u32 pcgctl;
>
> + spin_lock_irqsave(&hsotg->lock, flags);
> +
> /*
> * If hibernation is supported, Phy clock is already resumed
> * after registers restore.
> @@ -1508,10 +1510,11 @@ static void dwc2_port_resume(struct dwc2_hsotg *hsotg)
> pcgctl = dwc2_readl(hsotg->regs + PCGCTL);
> pcgctl &= ~PCGCTL_STOPPCLK;
> dwc2_writel(pcgctl, hsotg->regs + PCGCTL);
> + spin_unlock_irqrestore(&hsotg->lock, flags);
> usleep_range(20000, 40000);
> + spin_lock_irqsave(&hsotg->lock, flags);
> }
>
> - spin_lock_irqsave(&hsotg->lock, flags);
> hprt0 = dwc2_read_hprt0(hsotg);
> hprt0 |= HPRT0_RES;
> hprt0 &= ~HPRT0_SUSP;
>
Acked-by: John Youn <johnyoun@synopsys.com>
John
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-10-16 18:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-14 22:58 [PATCH] usb: dwc2: host: Protect PCGCTL with lock in dwc2_port_resume() Douglas Anderson
2015-10-16 18:06 ` John Youn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®