linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Fix PM deadlock and card detection problem
@ 2015-01-15  7:14 Roger Tseng
  2015-01-15  7:14 ` [PATCH 1/2] mfd: rtsx_usb: Fix runtime PM deadlock Roger Tseng
  2015-01-15  7:14 ` [PATCH 2/2] mfd: rtsx_usb: Defer autosuspend while card exists Roger Tseng
  0 siblings, 2 replies; 9+ messages in thread
From: Roger Tseng @ 2015-01-15  7:14 UTC (permalink / raw)
  To: Samuel Ortiz, Lee Jones
  Cc: Greg Kroah-Hartman, linux-kernel, driverdev-devel, wei_wang,
	micky_ching, Roger Tseng

The patchset fixes a deadlock situation of runtime PM methods and minimize
card detection "deadtime" during runtime suspending.

Roger Tseng (2):
  mfd: rtsx_usb: Fix runtime PM deadlock
  mfd: rtsx_usb: Defer autosuspend while card exists

 drivers/mfd/rtsx_usb.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

-- 
2.1.3


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/2] mfd: rtsx_usb: Fix runtime PM deadlock
  2015-01-15  7:14 [PATCH 0/2] Fix PM deadlock and card detection problem Roger Tseng
@ 2015-01-15  7:14 ` Roger Tseng
  2015-01-19  9:45   ` Lee Jones
  2015-01-15  7:14 ` [PATCH 2/2] mfd: rtsx_usb: Defer autosuspend while card exists Roger Tseng
  1 sibling, 1 reply; 9+ messages in thread
From: Roger Tseng @ 2015-01-15  7:14 UTC (permalink / raw)
  To: Samuel Ortiz, Lee Jones
  Cc: Greg Kroah-Hartman, linux-kernel, driverdev-devel, wei_wang,
	micky_ching, Roger Tseng

sd_set_power_mode() in derived module drivers/mmc/host/rtsx_usb_sdmmc.c
acquires dev_mutex and then calls pm_runtime_get_sync() to make sure the
device is awake while initializing a newly inserted card. Once it is
called during suspending state and explicitly before rtsx_usb_suspend()
acquires the same dev_mutex, both routine deadlock and further hang the
driver because pm_runtime_get_sync() waits the pending PM operations.

Fix this by using an empty suspend method. mmc_core always turns the
LED off after a request is done and thus it is ok to remove the only
rtsx_usb_turn_off_led() here.

Cc: <stable@vger.kernel.org> # v3.16+
Fixes: 730876be2566 ("mfd: Add realtek USB card reader driver")
Signed-off-by: Roger Tseng <rogerable@realtek.com>
---
 drivers/mfd/rtsx_usb.c | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/drivers/mfd/rtsx_usb.c b/drivers/mfd/rtsx_usb.c
index dbdd0faeb6ce..076694126e5d 100644
--- a/drivers/mfd/rtsx_usb.c
+++ b/drivers/mfd/rtsx_usb.c
@@ -687,15 +687,6 @@ static int rtsx_usb_suspend(struct usb_interface *intf, pm_message_t message)
 	dev_dbg(&intf->dev, "%s called with pm message 0x%04x\n",
 			__func__, message.event);
 
-	/*
-	 * Call to make sure LED is off during suspend to save more power.
-	 * It is NOT a permanent state and could be turned on anytime later.
-	 * Thus no need to call turn_on when resunming.
-	 */
-	mutex_lock(&ucr->dev_mutex);
-	rtsx_usb_turn_off_led(ucr);
-	mutex_unlock(&ucr->dev_mutex);
-
 	return 0;
 }
 
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/2] mfd: rtsx_usb: Defer autosuspend while card exists
  2015-01-15  7:14 [PATCH 0/2] Fix PM deadlock and card detection problem Roger Tseng
  2015-01-15  7:14 ` [PATCH 1/2] mfd: rtsx_usb: Fix runtime PM deadlock Roger Tseng
@ 2015-01-15  7:14 ` Roger Tseng
  2015-01-19  9:47   ` Lee Jones
  1 sibling, 1 reply; 9+ messages in thread
From: Roger Tseng @ 2015-01-15  7:14 UTC (permalink / raw)
  To: Samuel Ortiz, Lee Jones
  Cc: Greg Kroah-Hartman, linux-kernel, driverdev-devel, wei_wang,
	micky_ching, Roger Tseng

A card insertion happens after the lastest polling before reader is
suspended may never have a chance to be detected. Under current 1-HZ
polling interval setting in mmc_core, the worst case of such
undetectablility is about 1 second.

To further reduce the undetectability, detect card slot again in suspend
method and defer the autosuspend if the slot is loaded. The default 2
second autosuspend delay of USB subsystem should let the next polling
detects the card.

Signed-off-by: Roger Tseng <rogerable@realtek.com>
---
 drivers/mfd/rtsx_usb.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/mfd/rtsx_usb.c b/drivers/mfd/rtsx_usb.c
index 076694126e5d..63883fd025c0 100644
--- a/drivers/mfd/rtsx_usb.c
+++ b/drivers/mfd/rtsx_usb.c
@@ -687,6 +687,20 @@ static int rtsx_usb_suspend(struct usb_interface *intf, pm_message_t message)
 	dev_dbg(&intf->dev, "%s called with pm message 0x%04x\n",
 			__func__, message.event);
 
+	if (PMSG_IS_AUTO(message)) {
+		if (mutex_trylock(&ucr->dev_mutex)) {
+			rtsx_usb_get_card_status(ucr, &val);
+			mutex_unlock(&ucr->dev_mutex);
+
+			/* Defer the autosuspend if card exists */
+			if (val & (SD_CD | MS_CD))
+				return -EAGAIN;
+		} else {
+			/* There is an ongoing operation*/
+			return -EAGAIN;
+		}
+	}
+
 	return 0;
 }
 
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] mfd: rtsx_usb: Fix runtime PM deadlock
  2015-01-15  7:14 ` [PATCH 1/2] mfd: rtsx_usb: Fix runtime PM deadlock Roger Tseng
@ 2015-01-19  9:45   ` Lee Jones
  2015-01-20 11:04     ` Roger Tseng
  0 siblings, 1 reply; 9+ messages in thread
From: Lee Jones @ 2015-01-19  9:45 UTC (permalink / raw)
  To: Roger Tseng
  Cc: Samuel Ortiz, Greg Kroah-Hartman, linux-kernel, driverdev-devel,
	wei_wang, micky_ching

On Thu, 15 Jan 2015, Roger Tseng wrote:

> sd_set_power_mode() in derived module drivers/mmc/host/rtsx_usb_sdmmc.c
> acquires dev_mutex and then calls pm_runtime_get_sync() to make sure the
> device is awake while initializing a newly inserted card. Once it is
> called during suspending state and explicitly before rtsx_usb_suspend()
> acquires the same dev_mutex, both routine deadlock and further hang the
> driver because pm_runtime_get_sync() waits the pending PM operations.
> 
> Fix this by using an empty suspend method. mmc_core always turns the
> LED off after a request is done and thus it is ok to remove the only
> rtsx_usb_turn_off_led() here.
> 
> Cc: <stable@vger.kernel.org> # v3.16+
> Fixes: 730876be2566 ("mfd: Add realtek USB card reader driver")
> Signed-off-by: Roger Tseng <rogerable@realtek.com>
> ---
>  drivers/mfd/rtsx_usb.c | 9 ---------
>  1 file changed, 9 deletions(-)

Applied, thanks.

> diff --git a/drivers/mfd/rtsx_usb.c b/drivers/mfd/rtsx_usb.c
> index dbdd0faeb6ce..076694126e5d 100644
> --- a/drivers/mfd/rtsx_usb.c
> +++ b/drivers/mfd/rtsx_usb.c
> @@ -687,15 +687,6 @@ static int rtsx_usb_suspend(struct usb_interface *intf, pm_message_t message)
>  	dev_dbg(&intf->dev, "%s called with pm message 0x%04x\n",
>  			__func__, message.event);
>  
> -	/*
> -	 * Call to make sure LED is off during suspend to save more power.
> -	 * It is NOT a permanent state and could be turned on anytime later.
> -	 * Thus no need to call turn_on when resunming.
> -	 */
> -	mutex_lock(&ucr->dev_mutex);
> -	rtsx_usb_turn_off_led(ucr);
> -	mutex_unlock(&ucr->dev_mutex);
> -
>  	return 0;
>  }
>  

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] mfd: rtsx_usb: Defer autosuspend while card exists
  2015-01-15  7:14 ` [PATCH 2/2] mfd: rtsx_usb: Defer autosuspend while card exists Roger Tseng
@ 2015-01-19  9:47   ` Lee Jones
  0 siblings, 0 replies; 9+ messages in thread
From: Lee Jones @ 2015-01-19  9:47 UTC (permalink / raw)
  To: Roger Tseng
  Cc: Samuel Ortiz, Greg Kroah-Hartman, linux-kernel, driverdev-devel,
	wei_wang, micky_ching

On Thu, 15 Jan 2015, Roger Tseng wrote:

> A card insertion happens after the lastest polling before reader is
> suspended may never have a chance to be detected. Under current 1-HZ
> polling interval setting in mmc_core, the worst case of such
> undetectablility is about 1 second.
> 
> To further reduce the undetectability, detect card slot again in suspend
> method and defer the autosuspend if the slot is loaded. The default 2
> second autosuspend delay of USB subsystem should let the next polling
> detects the card.
> 
> Signed-off-by: Roger Tseng <rogerable@realtek.com>
> ---
>  drivers/mfd/rtsx_usb.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)

Applied, thanks.

> diff --git a/drivers/mfd/rtsx_usb.c b/drivers/mfd/rtsx_usb.c
> index 076694126e5d..63883fd025c0 100644
> --- a/drivers/mfd/rtsx_usb.c
> +++ b/drivers/mfd/rtsx_usb.c
> @@ -687,6 +687,20 @@ static int rtsx_usb_suspend(struct usb_interface *intf, pm_message_t message)
>  	dev_dbg(&intf->dev, "%s called with pm message 0x%04x\n",
>  			__func__, message.event);
>  
> +	if (PMSG_IS_AUTO(message)) {
> +		if (mutex_trylock(&ucr->dev_mutex)) {
> +			rtsx_usb_get_card_status(ucr, &val);
> +			mutex_unlock(&ucr->dev_mutex);
> +
> +			/* Defer the autosuspend if card exists */
> +			if (val & (SD_CD | MS_CD))
> +				return -EAGAIN;
> +		} else {
> +			/* There is an ongoing operation*/
> +			return -EAGAIN;
> +		}
> +	}
> +
>  	return 0;
>  }
>  

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] mfd: rtsx_usb: Fix runtime PM deadlock
  2015-01-19  9:45   ` Lee Jones
@ 2015-01-20 11:04     ` Roger Tseng
  2015-01-20 16:07       ` Lee Jones
  0 siblings, 1 reply; 9+ messages in thread
From: Roger Tseng @ 2015-01-20 11:04 UTC (permalink / raw)
  To: Lee Jones
  Cc: Samuel Ortiz, Greg Kroah-Hartman, linux-kernel, driverdev-devel,
	Wei_wang, micky_ching

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 2116 bytes --]

On Mon, 2015-01-19 at 09:45 +0000, Lee Jones wrote:
> On Thu, 15 Jan 2015, Roger Tseng wrote:
> 
> > sd_set_power_mode() in derived module drivers/mmc/host/rtsx_usb_sdmmc.c
> > acquires dev_mutex and then calls pm_runtime_get_sync() to make sure the
> > device is awake while initializing a newly inserted card. Once it is
> > called during suspending state and explicitly before rtsx_usb_suspend()
> > acquires the same dev_mutex, both routine deadlock and further hang the
> > driver because pm_runtime_get_sync() waits the pending PM operations.
> > 
> > Fix this by using an empty suspend method. mmc_core always turns the
> > LED off after a request is done and thus it is ok to remove the only
> > rtsx_usb_turn_off_led() here.
> > 
> > Cc: <stable@vger.kernel.org> # v3.16+
> > Fixes: 730876be2566 ("mfd: Add realtek USB card reader driver")
> > Signed-off-by: Roger Tseng <rogerable@realtek.com>
> > ---
> >  drivers/mfd/rtsx_usb.c | 9 ---------
> >  1 file changed, 9 deletions(-)
> 
> Applied, thanks.
> 
I'm sorry but build bot from Intel just reported me that I forgot to
delete an unused variable "ucr" between two commits. My bad.

Do I have a chance to send v2?

> > diff --git a/drivers/mfd/rtsx_usb.c b/drivers/mfd/rtsx_usb.c
> > index dbdd0faeb6ce..076694126e5d 100644
> > --- a/drivers/mfd/rtsx_usb.c
> > +++ b/drivers/mfd/rtsx_usb.c
> > @@ -687,15 +687,6 @@ static int rtsx_usb_suspend(struct usb_interface *intf, pm_message_t message)
> >  	dev_dbg(&intf->dev, "%s called with pm message 0x%04x\n",
> >  			__func__, message.event);
> >  
> > -	/*
> > -	 * Call to make sure LED is off during suspend to save more power.
> > -	 * It is NOT a permanent state and could be turned on anytime later.
> > -	 * Thus no need to call turn_on when resunming.
> > -	 */
> > -	mutex_lock(&ucr->dev_mutex);
> > -	rtsx_usb_turn_off_led(ucr);
> > -	mutex_unlock(&ucr->dev_mutex);
> > -
> >  	return 0;
> >  }
> >  
> 

-- 
Best regards,
Roger Tseng
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] mfd: rtsx_usb: Fix runtime PM deadlock
  2015-01-20 11:04     ` Roger Tseng
@ 2015-01-20 16:07       ` Lee Jones
  2015-01-21  6:58         ` Roger Tseng
  0 siblings, 1 reply; 9+ messages in thread
From: Lee Jones @ 2015-01-20 16:07 UTC (permalink / raw)
  To: Roger Tseng
  Cc: Samuel Ortiz, Greg Kroah-Hartman, linux-kernel, driverdev-devel,
	Wei_wang, micky_ching

On Tue, 20 Jan 2015, Roger Tseng wrote:

> On Mon, 2015-01-19 at 09:45 +0000, Lee Jones wrote:
> > On Thu, 15 Jan 2015, Roger Tseng wrote:
> > 
> > > sd_set_power_mode() in derived module drivers/mmc/host/rtsx_usb_sdmmc.c
> > > acquires dev_mutex and then calls pm_runtime_get_sync() to make sure the
> > > device is awake while initializing a newly inserted card. Once it is
> > > called during suspending state and explicitly before rtsx_usb_suspend()
> > > acquires the same dev_mutex, both routine deadlock and further hang the
> > > driver because pm_runtime_get_sync() waits the pending PM operations.
> > > 
> > > Fix this by using an empty suspend method. mmc_core always turns the
> > > LED off after a request is done and thus it is ok to remove the only
> > > rtsx_usb_turn_off_led() here.
> > > 
> > > Cc: <stable@vger.kernel.org> # v3.16+
> > > Fixes: 730876be2566 ("mfd: Add realtek USB card reader driver")
> > > Signed-off-by: Roger Tseng <rogerable@realtek.com>
> > > ---
> > >  drivers/mfd/rtsx_usb.c | 9 ---------
> > >  1 file changed, 9 deletions(-)
> > 
> > Applied, thanks.
> > 
> I'm sorry but build bot from Intel just reported me that I forgot to
> delete an unused variable "ucr" between two commits. My bad.
> 
> Do I have a chance to send v2?

You're lucky I'm in a good mood. ;)

I fixed it already.

> > > diff --git a/drivers/mfd/rtsx_usb.c b/drivers/mfd/rtsx_usb.c
> > > index dbdd0faeb6ce..076694126e5d 100644
> > > --- a/drivers/mfd/rtsx_usb.c
> > > +++ b/drivers/mfd/rtsx_usb.c
> > > @@ -687,15 +687,6 @@ static int rtsx_usb_suspend(struct usb_interface *intf, pm_message_t message)
> > >  	dev_dbg(&intf->dev, "%s called with pm message 0x%04x\n",
> > >  			__func__, message.event);
> > >  
> > > -	/*
> > > -	 * Call to make sure LED is off during suspend to save more power.
> > > -	 * It is NOT a permanent state and could be turned on anytime later.
> > > -	 * Thus no need to call turn_on when resunming.
> > > -	 */
> > > -	mutex_lock(&ucr->dev_mutex);
> > > -	rtsx_usb_turn_off_led(ucr);
> > > -	mutex_unlock(&ucr->dev_mutex);
> > > -
> > >  	return 0;
> > >  }
> > >  
> > 
> 

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] mfd: rtsx_usb: Fix runtime PM deadlock
  2015-01-20 16:07       ` Lee Jones
@ 2015-01-21  6:58         ` Roger Tseng
  2015-01-21  7:38           ` Lee Jones
  0 siblings, 1 reply; 9+ messages in thread
From: Roger Tseng @ 2015-01-21  6:58 UTC (permalink / raw)
  To: Lee Jones
  Cc: Samuel Ortiz, Greg Kroah-Hartman, linux-kernel, driverdev-devel,
	Wei_wang, micky_ching

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 3666 bytes --]

On Tue, 2015-01-20 at 16:07 +0000, Lee Jones wrote:
> On Tue, 20 Jan 2015, Roger Tseng wrote:
> 
> > On Mon, 2015-01-19 at 09:45 +0000, Lee Jones wrote:
> > > On Thu, 15 Jan 2015, Roger Tseng wrote:
> > > 
> > > > sd_set_power_mode() in derived module drivers/mmc/host/rtsx_usb_sdmmc.c
> > > > acquires dev_mutex and then calls pm_runtime_get_sync() to make sure the
> > > > device is awake while initializing a newly inserted card. Once it is
> > > > called during suspending state and explicitly before rtsx_usb_suspend()
> > > > acquires the same dev_mutex, both routine deadlock and further hang the
> > > > driver because pm_runtime_get_sync() waits the pending PM operations.
> > > > 
> > > > Fix this by using an empty suspend method. mmc_core always turns the
> > > > LED off after a request is done and thus it is ok to remove the only
> > > > rtsx_usb_turn_off_led() here.
> > > > 
> > > > Cc: <stable@vger.kernel.org> # v3.16+
> > > > Fixes: 730876be2566 ("mfd: Add realtek USB card reader driver")
> > > > Signed-off-by: Roger Tseng <rogerable@realtek.com>
> > > > ---
> > > >  drivers/mfd/rtsx_usb.c | 9 ---------
> > > >  1 file changed, 9 deletions(-)
> > > 
> > > Applied, thanks.
> > > 
> > I'm sorry but build bot from Intel just reported me that I forgot to
> > delete an unused variable "ucr" between two commits. My bad.
> > 
> > Do I have a chance to send v2?
> 
> You're lucky I'm in a good mood. ;)
> 
> I fixed it already.
> 
That's great, thanks! And thus patch 2/2 also needs to be changed
accordingly.

By the way, the build bot reported again about an undefined variable
build error in 2/2(I'm sorry for this again). I put the overall updated
content of 2/2 here for you if you're going to fix it, or I can also
re-send it individually.

diff --git a/drivers/mfd/rtsx_usb.c b/drivers/mfd/rtsx_usb.c
index 210d1f85679e..ede50244f265 100644
--- a/drivers/mfd/rtsx_usb.c
+++ b/drivers/mfd/rtsx_usb.c
@@ -681,9 +681,27 @@ static void rtsx_usb_disconnect(struct
usb_interface *intf)
 #ifdef CONFIG_PM
 static int rtsx_usb_suspend(struct usb_interface *intf, pm_message_t
message)
 {
+	struct rtsx_ucr *ucr =
+		(struct rtsx_ucr *)usb_get_intfdata(intf);
+	u16 val = 0;
+
 	dev_dbg(&intf->dev, "%s called with pm message 0x%04x\n",
 			__func__, message.event);
 
+	if (PMSG_IS_AUTO(message)) {
+		if (mutex_trylock(&ucr->dev_mutex)) {
+			rtsx_usb_get_card_status(ucr, &val);
+			mutex_unlock(&ucr->dev_mutex);
+
+			/* Defer the autosuspend if card exists */
+			if (val & (SD_CD | MS_CD))
+				return -EAGAIN;
+		} else {
+			/* There is an ongoing operation*/
+			return -EAGAIN;
+		}
+	}
+
 	return 0;
 }



> > > > diff --git a/drivers/mfd/rtsx_usb.c b/drivers/mfd/rtsx_usb.c
> > > > index dbdd0faeb6ce..076694126e5d 100644
> > > > --- a/drivers/mfd/rtsx_usb.c
> > > > +++ b/drivers/mfd/rtsx_usb.c
> > > > @@ -687,15 +687,6 @@ static int rtsx_usb_suspend(struct usb_interface *intf, pm_message_t message)
> > > >  	dev_dbg(&intf->dev, "%s called with pm message 0x%04x\n",
> > > >  			__func__, message.event);
> > > >  
> > > > -	/*
> > > > -	 * Call to make sure LED is off during suspend to save more power.
> > > > -	 * It is NOT a permanent state and could be turned on anytime later.
> > > > -	 * Thus no need to call turn_on when resunming.
> > > > -	 */
> > > > -	mutex_lock(&ucr->dev_mutex);
> > > > -	rtsx_usb_turn_off_led(ucr);
> > > > -	mutex_unlock(&ucr->dev_mutex);
> > > > -
> > > >  	return 0;
> > > >  }
> > > >  
> > > 
> > 
> 

-- 
Best regards,
Roger Tseng
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] mfd: rtsx_usb: Fix runtime PM deadlock
  2015-01-21  6:58         ` Roger Tseng
@ 2015-01-21  7:38           ` Lee Jones
  0 siblings, 0 replies; 9+ messages in thread
From: Lee Jones @ 2015-01-21  7:38 UTC (permalink / raw)
  To: Roger Tseng
  Cc: Samuel Ortiz, Greg Kroah-Hartman, linux-kernel, driverdev-devel,
	Wei_wang, micky_ching

On Wed, 21 Jan 2015, Roger Tseng wrote:

> On Tue, 2015-01-20 at 16:07 +0000, Lee Jones wrote:
> > On Tue, 20 Jan 2015, Roger Tseng wrote:
> > 
> > > On Mon, 2015-01-19 at 09:45 +0000, Lee Jones wrote:
> > > > On Thu, 15 Jan 2015, Roger Tseng wrote:
> > > > 
> > > > > sd_set_power_mode() in derived module drivers/mmc/host/rtsx_usb_sdmmc.c
> > > > > acquires dev_mutex and then calls pm_runtime_get_sync() to make sure the
> > > > > device is awake while initializing a newly inserted card. Once it is
> > > > > called during suspending state and explicitly before rtsx_usb_suspend()
> > > > > acquires the same dev_mutex, both routine deadlock and further hang the
> > > > > driver because pm_runtime_get_sync() waits the pending PM operations.
> > > > > 
> > > > > Fix this by using an empty suspend method. mmc_core always turns the
> > > > > LED off after a request is done and thus it is ok to remove the only
> > > > > rtsx_usb_turn_off_led() here.
> > > > > 
> > > > > Cc: <stable@vger.kernel.org> # v3.16+
> > > > > Fixes: 730876be2566 ("mfd: Add realtek USB card reader driver")
> > > > > Signed-off-by: Roger Tseng <rogerable@realtek.com>
> > > > > ---
> > > > >  drivers/mfd/rtsx_usb.c | 9 ---------
> > > > >  1 file changed, 9 deletions(-)
> > > > 
> > > > Applied, thanks.
> > > > 
> > > I'm sorry but build bot from Intel just reported me that I forgot to
> > > delete an unused variable "ucr" between two commits. My bad.
> > > 
> > > Do I have a chance to send v2?
> > 
> > You're lucky I'm in a good mood. ;)
> > 
> > I fixed it already.
> > 
> That's great, thanks! And thus patch 2/2 also needs to be changed
> accordingly.
> 
> By the way, the build bot reported again about an undefined variable
> build error in 2/2(I'm sorry for this again). I put the overall updated
> content of 2/2 here for you if you're going to fix it, or I can also
> re-send it individually.

Please re-send this patch and prefix it with [OVERWRITE].

In future make sure you test your submission thoroughly prior to
sending, as my time is very limited and with all due respect I could
make better use of it than this.

> diff --git a/drivers/mfd/rtsx_usb.c b/drivers/mfd/rtsx_usb.c
> index 210d1f85679e..ede50244f265 100644
> --- a/drivers/mfd/rtsx_usb.c
> +++ b/drivers/mfd/rtsx_usb.c
> @@ -681,9 +681,27 @@ static void rtsx_usb_disconnect(struct
> usb_interface *intf)
>  #ifdef CONFIG_PM
>  static int rtsx_usb_suspend(struct usb_interface *intf, pm_message_t
> message)
>  {
> +	struct rtsx_ucr *ucr =
> +		(struct rtsx_ucr *)usb_get_intfdata(intf);
> +	u16 val = 0;
> +
>  	dev_dbg(&intf->dev, "%s called with pm message 0x%04x\n",
>  			__func__, message.event);
>  
> +	if (PMSG_IS_AUTO(message)) {
> +		if (mutex_trylock(&ucr->dev_mutex)) {
> +			rtsx_usb_get_card_status(ucr, &val);
> +			mutex_unlock(&ucr->dev_mutex);
> +
> +			/* Defer the autosuspend if card exists */
> +			if (val & (SD_CD | MS_CD))
> +				return -EAGAIN;
> +		} else {
> +			/* There is an ongoing operation*/
> +			return -EAGAIN;
> +		}
> +	}
> +
>  	return 0;
>  }
> 
> 
> 
> > > > > diff --git a/drivers/mfd/rtsx_usb.c b/drivers/mfd/rtsx_usb.c
> > > > > index dbdd0faeb6ce..076694126e5d 100644
> > > > > --- a/drivers/mfd/rtsx_usb.c
> > > > > +++ b/drivers/mfd/rtsx_usb.c
> > > > > @@ -687,15 +687,6 @@ static int rtsx_usb_suspend(struct usb_interface *intf, pm_message_t message)
> > > > >  	dev_dbg(&intf->dev, "%s called with pm message 0x%04x\n",
> > > > >  			__func__, message.event);
> > > > >  
> > > > > -	/*
> > > > > -	 * Call to make sure LED is off during suspend to save more power.
> > > > > -	 * It is NOT a permanent state and could be turned on anytime later.
> > > > > -	 * Thus no need to call turn_on when resunming.
> > > > > -	 */
> > > > > -	mutex_lock(&ucr->dev_mutex);
> > > > > -	rtsx_usb_turn_off_led(ucr);
> > > > > -	mutex_unlock(&ucr->dev_mutex);
> > > > > -
> > > > >  	return 0;
> > > > >  }
> > > > >  
> > > > 
> > > 
> > 
> 

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-01-21  7:38 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-15  7:14 [PATCH 0/2] Fix PM deadlock and card detection problem Roger Tseng
2015-01-15  7:14 ` [PATCH 1/2] mfd: rtsx_usb: Fix runtime PM deadlock Roger Tseng
2015-01-19  9:45   ` Lee Jones
2015-01-20 11:04     ` Roger Tseng
2015-01-20 16:07       ` Lee Jones
2015-01-21  6:58         ` Roger Tseng
2015-01-21  7:38           ` Lee Jones
2015-01-15  7:14 ` [PATCH 2/2] mfd: rtsx_usb: Defer autosuspend while card exists Roger Tseng
2015-01-19  9:47   ` Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).