linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] soc: ti: Fix reference imbalance in knav_dma_probe
@ 2020-11-19 14:13 Zhang Qilong
  2020-11-19 19:55 ` Grygorii Strashko
  0 siblings, 1 reply; 2+ messages in thread
From: Zhang Qilong @ 2020-11-19 14:13 UTC (permalink / raw)
  To: ssantosh; +Cc: sandeep_n, linux-arm-kernel

The patch fix two reference leak.

  1) pm_runtime_get_sync will increment pm usage counter even it
     failed. Forgetting to call put operation will result in
     reference leak.

  2) The pm_runtime_enable will increase power disable depth. Thus
     a pairing decrement is needed on the error handling path to
     keep it balanced.

We fix it by: 1) adding call pm_runtime_put_noidle or
pm_runtime_put_sync in error handling. 2) adding pm_runtime_disable
in error handling, to keep usage counter and disable depth balanced.

Fixes: 88139ed030583 ("soc: ti: add Keystone Navigator DMA support")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
---
 drivers/soc/ti/knav_dma.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/soc/ti/knav_dma.c b/drivers/soc/ti/knav_dma.c
index 8c863ecb1c60..56597f6ea666 100644
--- a/drivers/soc/ti/knav_dma.c
+++ b/drivers/soc/ti/knav_dma.c
@@ -749,8 +749,9 @@ static int knav_dma_probe(struct platform_device *pdev)
 	pm_runtime_enable(kdev->dev);
 	ret = pm_runtime_get_sync(kdev->dev);
 	if (ret < 0) {
+		pm_runtime_put_noidle(kdev->dev);
 		dev_err(kdev->dev, "unable to enable pktdma, err %d\n", ret);
-		return ret;
+		goto err_pm_disable;
 	}
 
 	/* Initialise all packet dmas */
@@ -764,7 +765,8 @@ static int knav_dma_probe(struct platform_device *pdev)
 
 	if (list_empty(&kdev->list)) {
 		dev_err(dev, "no valid dma instance\n");
-		return -ENODEV;
+		ret = -ENODEV;
+		goto err_put_sync;
 	}
 
 	debugfs_create_file("knav_dma", S_IFREG | S_IRUGO, NULL, NULL,
@@ -772,6 +774,13 @@ static int knav_dma_probe(struct platform_device *pdev)
 
 	device_ready = true;
 	return ret;
+
+err_put_sync:
+	pm_runtime_put_sync(kdev->dev);
+err_pm_disable:
+	pm_runtime_disable(kdev->dev);
+
+	return ret;
 }
 
 static int knav_dma_remove(struct platform_device *pdev)
-- 
2.25.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] soc: ti: Fix reference imbalance in knav_dma_probe
  2020-11-19 14:13 [PATCH] soc: ti: Fix reference imbalance in knav_dma_probe Zhang Qilong
@ 2020-11-19 19:55 ` Grygorii Strashko
  0 siblings, 0 replies; 2+ messages in thread
From: Grygorii Strashko @ 2020-11-19 19:55 UTC (permalink / raw)
  To: Zhang Qilong, ssantosh; +Cc: linux-arm-kernel



On 19/11/2020 16:13, Zhang Qilong wrote:
> The patch fix two reference leak.
> 
>    1) pm_runtime_get_sync will increment pm usage counter even it
>       failed. Forgetting to call put operation will result in
>       reference leak.
> 
>    2) The pm_runtime_enable will increase power disable depth. Thus
>       a pairing decrement is needed on the error handling path to
>       keep it balanced.
> 
> We fix it by: 1) adding call pm_runtime_put_noidle or
> pm_runtime_put_sync in error handling. 2) adding pm_runtime_disable
> in error handling, to keep usage counter and disable depth balanced.
> 
> Fixes: 88139ed030583 ("soc: ti: add Keystone Navigator DMA support")
> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> ---
>   drivers/soc/ti/knav_dma.c | 13 +++++++++++--
>   1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/soc/ti/knav_dma.c b/drivers/soc/ti/knav_dma.c
> index 8c863ecb1c60..56597f6ea666 100644
> --- a/drivers/soc/ti/knav_dma.c
> +++ b/drivers/soc/ti/knav_dma.c
> @@ -749,8 +749,9 @@ static int knav_dma_probe(struct platform_device *pdev)
>   	pm_runtime_enable(kdev->dev);
>   	ret = pm_runtime_get_sync(kdev->dev);
>   	if (ret < 0) {
> +		pm_runtime_put_noidle(kdev->dev);
>   		dev_err(kdev->dev, "unable to enable pktdma, err %d\n", ret);
> -		return ret;
> +		goto err_pm_disable;
>   	}
>   
>   	/* Initialise all packet dmas */
> @@ -764,7 +765,8 @@ static int knav_dma_probe(struct platform_device *pdev)
>   
>   	if (list_empty(&kdev->list)) {
>   		dev_err(dev, "no valid dma instance\n");
> -		return -ENODEV;
> +		ret = -ENODEV;
> +		goto err_put_sync;
>   	}
>   
>   	debugfs_create_file("knav_dma", S_IFREG | S_IRUGO, NULL, NULL,
> @@ -772,6 +774,13 @@ static int knav_dma_probe(struct platform_device *pdev)
>   
>   	device_ready = true;
>   	return ret;
> +
> +err_put_sync:
> +	pm_runtime_put_sync(kdev->dev);
> +err_pm_disable:
> +	pm_runtime_disable(kdev->dev);
> +
> +	return ret;
>   }
>   
>   static int knav_dma_remove(struct platform_device *pdev)
> 

Thank you.
Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com>
-- 
Best regards,
grygorii

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2020-11-19 19:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-19 14:13 [PATCH] soc: ti: Fix reference imbalance in knav_dma_probe Zhang Qilong
2020-11-19 19:55 ` Grygorii Strashko

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).