Skip to contentSkip to conversation

usb: dwc2: host: Protect PCGCTL with lock in dwc2_port_resume()

PATCH In review Douglas Anderson 2 participants 2 messages Oct 14, 2015 – Oct 16, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: dwc2: host: Protect PCGCTL with lock in dwc2_port_resume()

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.

---
 drivers/usb/dwc2/hcd.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/usb/dwc2/hcd.c +4 -1
index af4e4a2..e79baf7 100644
@@ -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;
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
Acked-by on v1 1/1
#1 lore raw
Quoted 26 lines · Douglas Anderson

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.

---
 drivers/usb/dwc2/hcd.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/usb/dwc2/hcd.c +2 -0
index af4e4a2..e79baf7 100644
@@ -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;

drivers/usb/dwc2/hcd.c static void dwc2_port_resume(struct dwc2_hsotg *hsotg) · line 1520

Quoted 10 lines
drivers/usb/dwc2/hcd.c +2 -1
 		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;

John

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html