diff mbox

crypto: omap-des - handle error of pm_runtime_get_sync

Message ID 1397575982-24866-1-git-send-email-nm@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

Nishanth Menon April 15, 2014, 3:33 p.m. UTC
pm_runtime_get_sync may not always succeed depending on SoC involved. So
handle the error appropriately.

Reported-by: Joachim Eastwood <manabian@gmail.com>
Signed-off-by: Nishanth Menon <nm@ti.com>
---

based on v3.15-rc1

Report-thread: http://marc.info/?t=139750330400002&r=1&w=2

omap2plus_defconfig + CONFIG_CRYPTO_DEV_OMAP_DES=y

pandaboard-es-before: http://slexy.org/raw/s21rGPFnKl
pandaboard-es-after:  http://slexy.org/raw/s2A4UFQVna

 drivers/crypto/omap-des.c |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

Comments

Felipe Balbi April 15, 2014, 3:50 p.m. UTC | #1
Hi,

On Tue, Apr 15, 2014 at 10:33:02AM -0500, Nishanth Menon wrote:
> pm_runtime_get_sync may not always succeed depending on SoC involved. So
> handle the error appropriately.
> 
> Reported-by: Joachim Eastwood <manabian@gmail.com>
> Signed-off-by: Nishanth Menon <nm@ti.com>
> ---
> 
> based on v3.15-rc1
> 
> Report-thread: http://marc.info/?t=139750330400002&r=1&w=2
> 
> omap2plus_defconfig + CONFIG_CRYPTO_DEV_OMAP_DES=y
> 
> pandaboard-es-before: http://slexy.org/raw/s21rGPFnKl
> pandaboard-es-after:  http://slexy.org/raw/s2A4UFQVna
> 
>  drivers/crypto/omap-des.c |   18 ++++++++++++++----
>  1 file changed, 14 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/crypto/omap-des.c b/drivers/crypto/omap-des.c
> index ec5f131..c2d362f 100644
> --- a/drivers/crypto/omap-des.c
> +++ b/drivers/crypto/omap-des.c
> @@ -223,12 +223,18 @@ static void omap_des_write_n(struct omap_des_dev *dd, u32 offset,
>  
>  static int omap_des_hw_init(struct omap_des_dev *dd)
>  {
> +	int err;
> +
>  	/*
>  	 * clocks are enabled when request starts and disabled when finished.
>  	 * It may be long delays between requests.
>  	 * Device might go to off mode to save power.
>  	 */
> -	pm_runtime_get_sync(dd->dev);
> +	err = pm_runtime_get_sync(dd->dev);
> +	if (err < 0) {
> +		dev_err(dd->dev, "failed to get_sync(%d)\n", err);
> +		return err;

even when get() fails, you must put().

> +	}
>  
>  	if (!(dd->flags & FLAGS_INIT)) {
>  		dd->flags |= FLAGS_INIT;
> @@ -1083,7 +1089,11 @@ static int omap_des_probe(struct platform_device *pdev)
>  	dd->phys_base = res->start;
>  
>  	pm_runtime_enable(dev);
> -	pm_runtime_get_sync(dev);
> +	err = pm_runtime_get_sync(dev);
> +	if (err < 0) {
> +		dev_err(dd->dev, "failed to get_sync(%d)\n", err);
> +		goto err_get;

this leaves usage_count incremented, needs a put() here too.
Nishanth Menon April 15, 2014, 4:44 p.m. UTC | #2
On 04/15/2014 10:50 AM, Felipe Balbi wrote:
> Hi,
> 
> On Tue, Apr 15, 2014 at 10:33:02AM -0500, Nishanth Menon wrote:
>> pm_runtime_get_sync may not always succeed depending on SoC involved. So
>> handle the error appropriately.
>>
>> Reported-by: Joachim Eastwood <manabian@gmail.com>
>> Signed-off-by: Nishanth Menon <nm@ti.com>
>> ---
>>
>> based on v3.15-rc1
>>
>> Report-thread: http://marc.info/?t=139750330400002&r=1&w=2
>>
>> omap2plus_defconfig + CONFIG_CRYPTO_DEV_OMAP_DES=y
>>
>> pandaboard-es-before: http://slexy.org/raw/s21rGPFnKl
>> pandaboard-es-after:  http://slexy.org/raw/s2A4UFQVna
>>
>>  drivers/crypto/omap-des.c |   18 ++++++++++++++----
>>  1 file changed, 14 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/crypto/omap-des.c b/drivers/crypto/omap-des.c
>> index ec5f131..c2d362f 100644
>> --- a/drivers/crypto/omap-des.c
>> +++ b/drivers/crypto/omap-des.c
>> @@ -223,12 +223,18 @@ static void omap_des_write_n(struct omap_des_dev *dd, u32 offset,
>>  
>>  static int omap_des_hw_init(struct omap_des_dev *dd)
>>  {
>> +	int err;
>> +
>>  	/*
>>  	 * clocks are enabled when request starts and disabled when finished.
>>  	 * It may be long delays between requests.
>>  	 * Device might go to off mode to save power.
>>  	 */
>> -	pm_runtime_get_sync(dd->dev);
>> +	err = pm_runtime_get_sync(dd->dev);
>> +	if (err < 0) {
>> +		dev_err(dd->dev, "failed to get_sync(%d)\n", err);
>> +		return err;
> 
> even when get() fails, you must put().

> 
>> +	}
>>  
>>  	if (!(dd->flags & FLAGS_INIT)) {
>>  		dd->flags |= FLAGS_INIT;
>> @@ -1083,7 +1089,11 @@ static int omap_des_probe(struct platform_device *pdev)
>>  	dd->phys_base = res->start;
>>  
>>  	pm_runtime_enable(dev);
>> -	pm_runtime_get_sync(dev);
>> +	err = pm_runtime_get_sync(dev);
>> +	if (err < 0) {
>> +		dev_err(dd->dev, "failed to get_sync(%d)\n", err);
>> +		goto err_get;
> 
> this leaves usage_count incremented, needs a put() here too.
> 

Yeah, I see the code in runtime.c, and pm_runtime_put_noidle is the
right invocation in the case of error.

Wish we had a coccinelle script for this.
diff mbox

Patch

diff --git a/drivers/crypto/omap-des.c b/drivers/crypto/omap-des.c
index ec5f131..c2d362f 100644
--- a/drivers/crypto/omap-des.c
+++ b/drivers/crypto/omap-des.c
@@ -223,12 +223,18 @@  static void omap_des_write_n(struct omap_des_dev *dd, u32 offset,
 
 static int omap_des_hw_init(struct omap_des_dev *dd)
 {
+	int err;
+
 	/*
 	 * clocks are enabled when request starts and disabled when finished.
 	 * It may be long delays between requests.
 	 * Device might go to off mode to save power.
 	 */
-	pm_runtime_get_sync(dd->dev);
+	err = pm_runtime_get_sync(dd->dev);
+	if (err < 0) {
+		dev_err(dd->dev, "failed to get_sync(%d)\n", err);
+		return err;
+	}
 
 	if (!(dd->flags & FLAGS_INIT)) {
 		dd->flags |= FLAGS_INIT;
@@ -1083,7 +1089,11 @@  static int omap_des_probe(struct platform_device *pdev)
 	dd->phys_base = res->start;
 
 	pm_runtime_enable(dev);
-	pm_runtime_get_sync(dev);
+	err = pm_runtime_get_sync(dev);
+	if (err < 0) {
+		dev_err(dd->dev, "failed to get_sync(%d)\n", err);
+		goto err_get;
+	}
 
 	omap_des_dma_stop(dd);
 
@@ -1148,6 +1158,7 @@  err_algs:
 err_irq:
 	tasklet_kill(&dd->done_task);
 	tasklet_kill(&dd->queue_task);
+err_get:
 	pm_runtime_disable(dev);
 err_res:
 	dd = NULL;
@@ -1191,8 +1202,7 @@  static int omap_des_suspend(struct device *dev)
 
 static int omap_des_resume(struct device *dev)
 {
-	pm_runtime_get_sync(dev);
-	return 0;
+	return pm_runtime_get_sync(dev);
 }
 #endif