diff mbox

[8/9] usb: dwc2/gadget: fix calls to phy control functions in suspend/resume code

Message ID 1413464285-24172-9-git-send-email-m.szyprowski@samsung.com
State New
Headers show

Commit Message

Marek Szyprowski Oct. 16, 2014, 12:58 p.m. UTC
This patch moves calls to phy enable/disable out of spinlock protected
blocks in device suspend/resume to fix incorrect caller context. Phy
related functions must not be called from atomic context.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
 drivers/usb/dwc2/gadget.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Felipe Balbi Oct. 16, 2014, 1:42 p.m. UTC | #1
Hi,

On Thu, Oct 16, 2014 at 02:58:04PM +0200, Marek Szyprowski wrote:
> This patch moves calls to phy enable/disable out of spinlock protected
> blocks in device suspend/resume to fix incorrect caller context. Phy
> related functions must not be called from atomic context.
> 
> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
> ---
>  drivers/usb/dwc2/gadget.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
> index cdf417a7ae63..052b1a857291 100644
> --- a/drivers/usb/dwc2/gadget.c
> +++ b/drivers/usb/dwc2/gadget.c
> @@ -3656,11 +3656,13 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state)
>  			 hsotg->driver->driver.name);
>  
>  	spin_lock_irqsave(&hsotg->lock, flags);
> +	s3c_hsotg_core_disconnect(hsotg);
>  	s3c_hsotg_disconnect(hsotg);
> -	s3c_hsotg_phy_disable(hsotg);
>  	hsotg->gadget.speed = USB_SPEED_UNKNOWN;
>  	spin_unlock_irqrestore(&hsotg->lock, flags);
>  
> +	s3c_hsotg_phy_disable(hsotg);

this is aching to have a locked version as well as an unlocked version.
Look at what you do here. There's a minor race when you release that
spinlock. By the time ->suspend() is called, IRQs are not yet disabled.
Marek Szyprowski Oct. 20, 2014, 10:46 a.m. UTC | #2
Hello,

On 2014-10-16 15:42, Felipe Balbi wrote:
> On Thu, Oct 16, 2014 at 02:58:04PM +0200, Marek Szyprowski wrote:
>> This patch moves calls to phy enable/disable out of spinlock protected
>> blocks in device suspend/resume to fix incorrect caller context. Phy
>> related functions must not be called from atomic context.
>>
>> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
>> ---
>>   drivers/usb/dwc2/gadget.c | 9 ++++++---
>>   1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
>> index cdf417a7ae63..052b1a857291 100644
>> --- a/drivers/usb/dwc2/gadget.c
>> +++ b/drivers/usb/dwc2/gadget.c
>> @@ -3656,11 +3656,13 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state)
>>   			 hsotg->driver->driver.name);
>>   
>>   	spin_lock_irqsave(&hsotg->lock, flags);
>> +	s3c_hsotg_core_disconnect(hsotg);
>>   	s3c_hsotg_disconnect(hsotg);
>> -	s3c_hsotg_phy_disable(hsotg);
>>   	hsotg->gadget.speed = USB_SPEED_UNKNOWN;
>>   	spin_unlock_irqrestore(&hsotg->lock, flags);
>>   
>> +	s3c_hsotg_phy_disable(hsotg);
> this is aching to have a locked version as well as an unlocked version.
> Look at what you do here. There's a minor race when you release that
> spinlock. By the time ->suspend() is called, IRQs are not yet disabled.

s3c_hsotg_core_disconnect() disconnects the udc hardware from the usb bus, so even
if the irq comes before s3c_hsotg_phy_disable(), nothing wrong happens, because the
driver state is already set to disconnected.

Best regards
diff mbox

Patch

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index cdf417a7ae63..052b1a857291 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -3656,11 +3656,13 @@  static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state)
 			 hsotg->driver->driver.name);
 
 	spin_lock_irqsave(&hsotg->lock, flags);
+	s3c_hsotg_core_disconnect(hsotg);
 	s3c_hsotg_disconnect(hsotg);
-	s3c_hsotg_phy_disable(hsotg);
 	hsotg->gadget.speed = USB_SPEED_UNKNOWN;
 	spin_unlock_irqrestore(&hsotg->lock, flags);
 
+	s3c_hsotg_phy_disable(hsotg);
+
 	if (hsotg->driver) {
 		int ep;
 		for (ep = 0; ep < hsotg->num_of_eps; ep++)
@@ -3689,9 +3691,10 @@  static int s3c_hsotg_resume(struct platform_device *pdev)
 				      hsotg->supplies);
 	}
 
-	spin_lock_irqsave(&hsotg->lock, flags);
 	s3c_hsotg_phy_enable(hsotg);
-	s3c_hsotg_core_init_disconnect(hsotg);
+
+	spin_lock_irqsave(&hsotg->lock, flags);
+	s3c_hsotg_core_init_disconnected(hsotg);
 	s3c_hsotg_core_connect(hsotg);
 	spin_unlock_irqrestore(&hsotg->lock, flags);