dmaengine.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] cleanup patches for PM reference leak
@ 2021-05-17  8:18 Yu Kuai
  2021-05-17  8:18 ` [PATCH 1/3] dmaengine: stm32-mdma: fix PM reference leak in stm32_mdma_alloc_chan_resourc() Yu Kuai
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Yu Kuai @ 2021-05-17  8:18 UTC (permalink / raw)
  To: vkoul, mcoquelin.stm32, alexandre.torgue, michal.simek
  Cc: dmaengine, linux-kernel, linux-stm32, linux-arm-kernel, yukuai3,
	yi.zhang

Yu Kuai (3):
  dmaengine: stm32-mdma: fix PM reference leak in
    stm32_mdma_alloc_chan_resourc()
  dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()
  dmaengine: zynqmp_dma: Fix PM reference leak in
    zynqmp_dma_alloc_chan_resourc()

 drivers/dma/sh/usb-dmac.c       | 2 +-
 drivers/dma/stm32-mdma.c        | 4 ++--
 drivers/dma/xilinx/zynqmp_dma.c | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

-- 
2.25.4


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

* [PATCH 1/3] dmaengine: stm32-mdma: fix PM reference leak in stm32_mdma_alloc_chan_resourc()
  2021-05-17  8:18 [PATCH 0/3] cleanup patches for PM reference leak Yu Kuai
@ 2021-05-17  8:18 ` Yu Kuai
  2021-05-31  4:03   ` Vinod Koul
  2021-05-17  8:18 ` [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe() Yu Kuai
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 16+ messages in thread
From: Yu Kuai @ 2021-05-17  8:18 UTC (permalink / raw)
  To: vkoul, mcoquelin.stm32, alexandre.torgue, michal.simek
  Cc: dmaengine, linux-kernel, linux-stm32, linux-arm-kernel, yukuai3,
	yi.zhang

pm_runtime_get_sync will increment pm usage counter even it failed.
Forgetting to putting operation will result in reference leak here.
Fix it by replacing it with pm_runtime_resume_and_get to keep usage
counter balanced.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 drivers/dma/stm32-mdma.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
index 36ba8b43e78d..18cbd1e43c2e 100644
--- a/drivers/dma/stm32-mdma.c
+++ b/drivers/dma/stm32-mdma.c
@@ -1452,7 +1452,7 @@ static int stm32_mdma_alloc_chan_resources(struct dma_chan *c)
 		return -ENOMEM;
 	}
 
-	ret = pm_runtime_get_sync(dmadev->ddev.dev);
+	ret = pm_runtime_resume_and_get(dmadev->ddev.dev);
 	if (ret < 0)
 		return ret;
 
@@ -1718,7 +1718,7 @@ static int stm32_mdma_pm_suspend(struct device *dev)
 	u32 ccr, id;
 	int ret;
 
-	ret = pm_runtime_get_sync(dev);
+	ret = pm_runtime_resume_and_get(dev);
 	if (ret < 0)
 		return ret;
 
-- 
2.25.4


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

* [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()
  2021-05-17  8:18 [PATCH 0/3] cleanup patches for PM reference leak Yu Kuai
  2021-05-17  8:18 ` [PATCH 1/3] dmaengine: stm32-mdma: fix PM reference leak in stm32_mdma_alloc_chan_resourc() Yu Kuai
@ 2021-05-17  8:18 ` Yu Kuai
  2021-05-31  4:00   ` Vinod Koul
  2021-05-17  8:18 ` [PATCH 3/3] dmaengine: zynqmp_dma: Fix PM reference leak in zynqmp_dma_alloc_chan_resourc() Yu Kuai
  2021-05-29  9:13 ` [PATCH 0/3] cleanup patches for PM reference leak yukuai (C)
  3 siblings, 1 reply; 16+ messages in thread
From: Yu Kuai @ 2021-05-17  8:18 UTC (permalink / raw)
  To: vkoul, mcoquelin.stm32, alexandre.torgue, michal.simek
  Cc: dmaengine, linux-kernel, linux-stm32, linux-arm-kernel, yukuai3,
	yi.zhang

pm_runtime_get_sync will increment pm usage counter even it failed.
Forgetting to putting operation will result in reference leak here.
Fix it by replacing it with pm_runtime_resume_and_get to keep usage
counter balanced.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 drivers/dma/sh/usb-dmac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/sh/usb-dmac.c b/drivers/dma/sh/usb-dmac.c
index 8f7ceb698226..2a6c8fd8854e 100644
--- a/drivers/dma/sh/usb-dmac.c
+++ b/drivers/dma/sh/usb-dmac.c
@@ -796,7 +796,7 @@ static int usb_dmac_probe(struct platform_device *pdev)
 
 	/* Enable runtime PM and initialize the device. */
 	pm_runtime_enable(&pdev->dev);
-	ret = pm_runtime_get_sync(&pdev->dev);
+	ret = pm_runtime_resume_and_get(&pdev->dev);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "runtime PM get sync failed (%d)\n", ret);
 		goto error_pm;
-- 
2.25.4


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

* [PATCH 3/3] dmaengine: zynqmp_dma: Fix PM reference leak in zynqmp_dma_alloc_chan_resourc()
  2021-05-17  8:18 [PATCH 0/3] cleanup patches for PM reference leak Yu Kuai
  2021-05-17  8:18 ` [PATCH 1/3] dmaengine: stm32-mdma: fix PM reference leak in stm32_mdma_alloc_chan_resourc() Yu Kuai
  2021-05-17  8:18 ` [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe() Yu Kuai
@ 2021-05-17  8:18 ` Yu Kuai
  2021-05-31  4:03   ` Vinod Koul
  2021-05-29  9:13 ` [PATCH 0/3] cleanup patches for PM reference leak yukuai (C)
  3 siblings, 1 reply; 16+ messages in thread
From: Yu Kuai @ 2021-05-17  8:18 UTC (permalink / raw)
  To: vkoul, mcoquelin.stm32, alexandre.torgue, michal.simek
  Cc: dmaengine, linux-kernel, linux-stm32, linux-arm-kernel, yukuai3,
	yi.zhang

pm_runtime_get_sync will increment pm usage counter even it failed.
Forgetting to putting operation will result in reference leak here.
Fix it by replacing it with pm_runtime_resume_and_get to keep usage
counter balanced.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 drivers/dma/xilinx/zynqmp_dma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/xilinx/zynqmp_dma.c b/drivers/dma/xilinx/zynqmp_dma.c
index d8419565b92c..5fecf5aa6e85 100644
--- a/drivers/dma/xilinx/zynqmp_dma.c
+++ b/drivers/dma/xilinx/zynqmp_dma.c
@@ -468,7 +468,7 @@ static int zynqmp_dma_alloc_chan_resources(struct dma_chan *dchan)
 	struct zynqmp_dma_desc_sw *desc;
 	int i, ret;
 
-	ret = pm_runtime_get_sync(chan->dev);
+	ret = pm_runtime_resume_and_get(chan->dev);
 	if (ret < 0)
 		return ret;
 
-- 
2.25.4


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

* Re: [PATCH 0/3] cleanup patches for PM reference leak
  2021-05-17  8:18 [PATCH 0/3] cleanup patches for PM reference leak Yu Kuai
                   ` (2 preceding siblings ...)
  2021-05-17  8:18 ` [PATCH 3/3] dmaengine: zynqmp_dma: Fix PM reference leak in zynqmp_dma_alloc_chan_resourc() Yu Kuai
@ 2021-05-29  9:13 ` yukuai (C)
  3 siblings, 0 replies; 16+ messages in thread
From: yukuai (C) @ 2021-05-29  9:13 UTC (permalink / raw)
  To: vkoul, mcoquelin.stm32, alexandre.torgue, michal.simek
  Cc: dmaengine, linux-kernel, linux-stm32, linux-arm-kernel, yi.zhang

ping ...

On 2021/05/17 16:18, Yu Kuai wrote:
> Yu Kuai (3):
>    dmaengine: stm32-mdma: fix PM reference leak in
>      stm32_mdma_alloc_chan_resourc()
>    dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()
>    dmaengine: zynqmp_dma: Fix PM reference leak in
>      zynqmp_dma_alloc_chan_resourc()
> 
>   drivers/dma/sh/usb-dmac.c       | 2 +-
>   drivers/dma/stm32-mdma.c        | 4 ++--
>   drivers/dma/xilinx/zynqmp_dma.c | 2 +-
>   3 files changed, 4 insertions(+), 4 deletions(-)
> 

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

* Re: [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()
  2021-05-17  8:18 ` [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe() Yu Kuai
@ 2021-05-31  4:00   ` Vinod Koul
  2021-05-31  6:11     ` yukuai (C)
  0 siblings, 1 reply; 16+ messages in thread
From: Vinod Koul @ 2021-05-31  4:00 UTC (permalink / raw)
  To: Yu Kuai
  Cc: mcoquelin.stm32, alexandre.torgue, michal.simek, dmaengine,
	linux-kernel, linux-stm32, linux-arm-kernel, yi.zhang

On 17-05-21, 16:18, Yu Kuai wrote:
> pm_runtime_get_sync will increment pm usage counter even it failed.
> Forgetting to putting operation will result in reference leak here.
> Fix it by replacing it with pm_runtime_resume_and_get to keep usage
> counter balanced.
> 
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
>  drivers/dma/sh/usb-dmac.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/sh/usb-dmac.c b/drivers/dma/sh/usb-dmac.c
> index 8f7ceb698226..2a6c8fd8854e 100644
> --- a/drivers/dma/sh/usb-dmac.c
> +++ b/drivers/dma/sh/usb-dmac.c
> @@ -796,7 +796,7 @@ static int usb_dmac_probe(struct platform_device *pdev)
>  
>  	/* Enable runtime PM and initialize the device. */
>  	pm_runtime_enable(&pdev->dev);
> -	ret = pm_runtime_get_sync(&pdev->dev);
> +	ret = pm_runtime_resume_and_get(&pdev->dev);

This does not seem to fix anything.. the below goto goes and disables
the runtime_pm for this device and thus there wont be any leak

>  	if (ret < 0) {
>  		dev_err(&pdev->dev, "runtime PM get sync failed (%d)\n", ret);
>  		goto error_pm;
> -- 
> 2.25.4

-- 
~Vinod

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

* Re: [PATCH 1/3] dmaengine: stm32-mdma: fix PM reference leak in stm32_mdma_alloc_chan_resourc()
  2021-05-17  8:18 ` [PATCH 1/3] dmaengine: stm32-mdma: fix PM reference leak in stm32_mdma_alloc_chan_resourc() Yu Kuai
@ 2021-05-31  4:03   ` Vinod Koul
  0 siblings, 0 replies; 16+ messages in thread
From: Vinod Koul @ 2021-05-31  4:03 UTC (permalink / raw)
  To: Yu Kuai
  Cc: mcoquelin.stm32, alexandre.torgue, michal.simek, dmaengine,
	linux-kernel, linux-stm32, linux-arm-kernel, yi.zhang

On 17-05-21, 16:18, Yu Kuai wrote:
> pm_runtime_get_sync will increment pm usage counter even it failed.
> Forgetting to putting operation will result in reference leak here.
> Fix it by replacing it with pm_runtime_resume_and_get to keep usage
> counter balanced.

Applied, thanks

-- 
~Vinod

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

* Re: [PATCH 3/3] dmaengine: zynqmp_dma: Fix PM reference leak in zynqmp_dma_alloc_chan_resourc()
  2021-05-17  8:18 ` [PATCH 3/3] dmaengine: zynqmp_dma: Fix PM reference leak in zynqmp_dma_alloc_chan_resourc() Yu Kuai
@ 2021-05-31  4:03   ` Vinod Koul
  0 siblings, 0 replies; 16+ messages in thread
From: Vinod Koul @ 2021-05-31  4:03 UTC (permalink / raw)
  To: Yu Kuai
  Cc: mcoquelin.stm32, alexandre.torgue, michal.simek, dmaengine,
	linux-kernel, linux-stm32, linux-arm-kernel, yi.zhang

On 17-05-21, 16:18, Yu Kuai wrote:
> pm_runtime_get_sync will increment pm usage counter even it failed.
> Forgetting to putting operation will result in reference leak here.
> Fix it by replacing it with pm_runtime_resume_and_get to keep usage
> counter balanced.

Applied, thanks

-- 
~Vinod

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

* Re: [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()
  2021-05-31  4:00   ` Vinod Koul
@ 2021-05-31  6:11     ` yukuai (C)
  2021-05-31  8:57       ` Vinod Koul
  0 siblings, 1 reply; 16+ messages in thread
From: yukuai (C) @ 2021-05-31  6:11 UTC (permalink / raw)
  To: Vinod Koul
  Cc: mcoquelin.stm32, alexandre.torgue, michal.simek, dmaengine,
	linux-kernel, linux-stm32, linux-arm-kernel, yi.zhang

On 2021/05/31 12:00, Vinod Koul wrote:
> On 17-05-21, 16:18, Yu Kuai wrote:
>> pm_runtime_get_sync will increment pm usage counter even it failed.
>> Forgetting to putting operation will result in reference leak here.
>> Fix it by replacing it with pm_runtime_resume_and_get to keep usage
>> counter balanced.
>>
>> Reported-by: Hulk Robot <hulkci@huawei.com>
>> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
>> ---
>>   drivers/dma/sh/usb-dmac.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/dma/sh/usb-dmac.c b/drivers/dma/sh/usb-dmac.c
>> index 8f7ceb698226..2a6c8fd8854e 100644
>> --- a/drivers/dma/sh/usb-dmac.c
>> +++ b/drivers/dma/sh/usb-dmac.c
>> @@ -796,7 +796,7 @@ static int usb_dmac_probe(struct platform_device *pdev)
>>   
>>   	/* Enable runtime PM and initialize the device. */
>>   	pm_runtime_enable(&pdev->dev);
>> -	ret = pm_runtime_get_sync(&pdev->dev);
>> +	ret = pm_runtime_resume_and_get(&pdev->dev);
> 
> This does not seem to fix anything.. the below goto goes and disables
> the runtime_pm for this device and thus there wont be any leak
Hi,

If pm_runtime_get_sync() fails and increments the pm.usage_count
variable, pm_runtime_disable() does not reset the counter, and
we still need to decrement the usage count when pm_runtime_get_sync()
fails. Do I miss anthing?

Thansk!
Yu Kuai
> 
>>   	if (ret < 0) {
>>   		dev_err(&pdev->dev, "runtime PM get sync failed (%d)\n", ret);
>>   		goto error_pm;
>> -- 
>> 2.25.4
> 

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

* Re: [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()
  2021-05-31  6:11     ` yukuai (C)
@ 2021-05-31  8:57       ` Vinod Koul
  2021-05-31  9:19         ` Johan Hovold
  0 siblings, 1 reply; 16+ messages in thread
From: Vinod Koul @ 2021-05-31  8:57 UTC (permalink / raw)
  To: yukuai (C)
  Cc: mcoquelin.stm32, alexandre.torgue, michal.simek, dmaengine,
	linux-kernel, linux-stm32, linux-arm-kernel, yi.zhang

On 31-05-21, 14:11, yukuai (C) wrote:
> On 2021/05/31 12:00, Vinod Koul wrote:
> > On 17-05-21, 16:18, Yu Kuai wrote:
> > > pm_runtime_get_sync will increment pm usage counter even it failed.
> > > Forgetting to putting operation will result in reference leak here.
> > > Fix it by replacing it with pm_runtime_resume_and_get to keep usage
> > > counter balanced.
> > > 
> > > Reported-by: Hulk Robot <hulkci@huawei.com>
> > > Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> > > ---
> > >   drivers/dma/sh/usb-dmac.c | 2 +-
> > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/dma/sh/usb-dmac.c b/drivers/dma/sh/usb-dmac.c
> > > index 8f7ceb698226..2a6c8fd8854e 100644
> > > --- a/drivers/dma/sh/usb-dmac.c
> > > +++ b/drivers/dma/sh/usb-dmac.c
> > > @@ -796,7 +796,7 @@ static int usb_dmac_probe(struct platform_device *pdev)
> > >   	/* Enable runtime PM and initialize the device. */
> > >   	pm_runtime_enable(&pdev->dev);
> > > -	ret = pm_runtime_get_sync(&pdev->dev);
> > > +	ret = pm_runtime_resume_and_get(&pdev->dev);
> > 
> > This does not seem to fix anything.. the below goto goes and disables
> > the runtime_pm for this device and thus there wont be any leak
> Hi,
> 
> If pm_runtime_get_sync() fails and increments the pm.usage_count
> variable, pm_runtime_disable() does not reset the counter, and
> we still need to decrement the usage count when pm_runtime_get_sync()
> fails. Do I miss anthing?

Yes the rumtime_pm is disabled on failure here and the count would have
no consequence...

-- 
~Vinod

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

* Re: [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()
  2021-05-31  8:57       ` Vinod Koul
@ 2021-05-31  9:19         ` Johan Hovold
  2021-06-03 11:09           ` Vinod Koul
  0 siblings, 1 reply; 16+ messages in thread
From: Johan Hovold @ 2021-05-31  9:19 UTC (permalink / raw)
  To: Vinod Koul
  Cc: yukuai (C),
	mcoquelin.stm32, alexandre.torgue, michal.simek, dmaengine,
	linux-kernel, linux-stm32, linux-arm-kernel, yi.zhang

On Mon, May 31, 2021 at 02:27:34PM +0530, Vinod Koul wrote:
> On 31-05-21, 14:11, yukuai (C) wrote:
> > On 2021/05/31 12:00, Vinod Koul wrote:
> > > On 17-05-21, 16:18, Yu Kuai wrote:
> > > > pm_runtime_get_sync will increment pm usage counter even it failed.
> > > > Forgetting to putting operation will result in reference leak here.
> > > > Fix it by replacing it with pm_runtime_resume_and_get to keep usage
> > > > counter balanced.
> > > > 
> > > > Reported-by: Hulk Robot <hulkci@huawei.com>
> > > > Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> > > > ---
> > > >   drivers/dma/sh/usb-dmac.c | 2 +-
> > > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > > > 
> > > > diff --git a/drivers/dma/sh/usb-dmac.c b/drivers/dma/sh/usb-dmac.c
> > > > index 8f7ceb698226..2a6c8fd8854e 100644
> > > > --- a/drivers/dma/sh/usb-dmac.c
> > > > +++ b/drivers/dma/sh/usb-dmac.c
> > > > @@ -796,7 +796,7 @@ static int usb_dmac_probe(struct platform_device *pdev)
> > > >   	/* Enable runtime PM and initialize the device. */
> > > >   	pm_runtime_enable(&pdev->dev);
> > > > -	ret = pm_runtime_get_sync(&pdev->dev);
> > > > +	ret = pm_runtime_resume_and_get(&pdev->dev);
> > > 
> > > This does not seem to fix anything.. the below goto goes and disables
> > > the runtime_pm for this device and thus there wont be any leak
> > Hi,
> > 
> > If pm_runtime_get_sync() fails and increments the pm.usage_count
> > variable, pm_runtime_disable() does not reset the counter, and
> > we still need to decrement the usage count when pm_runtime_get_sync()
> > fails. Do I miss anthing?
> 
> Yes the rumtime_pm is disabled on failure here and the count would have
> no consequence...

You should still balance the PM usage counter as it isn't reset for
example when reloading the driver.

Using pm_runtime_resume_and_get() is one way of handling this, but
alternatively you could also move the error_pm label above the
pm_runtime_put() in the error path.

Johan

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

* Re: [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()
  2021-05-31  9:19         ` Johan Hovold
@ 2021-06-03 11:09           ` Vinod Koul
  2021-06-07  8:06             ` Johan Hovold
  0 siblings, 1 reply; 16+ messages in thread
From: Vinod Koul @ 2021-06-03 11:09 UTC (permalink / raw)
  To: Johan Hovold
  Cc: yukuai (C),
	mcoquelin.stm32, alexandre.torgue, michal.simek, dmaengine,
	linux-kernel, linux-stm32, linux-arm-kernel, yi.zhang

On 31-05-21, 11:19, Johan Hovold wrote:
> On Mon, May 31, 2021 at 02:27:34PM +0530, Vinod Koul wrote:
> > On 31-05-21, 14:11, yukuai (C) wrote:
> > > On 2021/05/31 12:00, Vinod Koul wrote:
> > > > On 17-05-21, 16:18, Yu Kuai wrote:
> > > > > pm_runtime_get_sync will increment pm usage counter even it failed.
> > > > > Forgetting to putting operation will result in reference leak here.
> > > > > Fix it by replacing it with pm_runtime_resume_and_get to keep usage
> > > > > counter balanced.
> > > > > 
> > > > > Reported-by: Hulk Robot <hulkci@huawei.com>
> > > > > Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> > > > > ---
> > > > >   drivers/dma/sh/usb-dmac.c | 2 +-
> > > > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > > > > 
> > > > > diff --git a/drivers/dma/sh/usb-dmac.c b/drivers/dma/sh/usb-dmac.c
> > > > > index 8f7ceb698226..2a6c8fd8854e 100644
> > > > > --- a/drivers/dma/sh/usb-dmac.c
> > > > > +++ b/drivers/dma/sh/usb-dmac.c
> > > > > @@ -796,7 +796,7 @@ static int usb_dmac_probe(struct platform_device *pdev)
> > > > >   	/* Enable runtime PM and initialize the device. */
> > > > >   	pm_runtime_enable(&pdev->dev);
> > > > > -	ret = pm_runtime_get_sync(&pdev->dev);
> > > > > +	ret = pm_runtime_resume_and_get(&pdev->dev);
> > > > 
> > > > This does not seem to fix anything.. the below goto goes and disables
> > > > the runtime_pm for this device and thus there wont be any leak
> > > Hi,
> > > 
> > > If pm_runtime_get_sync() fails and increments the pm.usage_count
> > > variable, pm_runtime_disable() does not reset the counter, and
> > > we still need to decrement the usage count when pm_runtime_get_sync()
> > > fails. Do I miss anthing?
> > 
> > Yes the rumtime_pm is disabled on failure here and the count would have
> > no consequence...
> 
> You should still balance the PM usage counter as it isn't reset for
> example when reloading the driver.

Should I driver trust that on load PM usage counter is balanced and not
to be reset..?

> Using pm_runtime_resume_and_get() is one way of handling this, but
> alternatively you could also move the error_pm label above the
> pm_runtime_put() in the error path.

That would be a better way I think

-- 
~Vinod

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

* Re: [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()
  2021-06-03 11:09           ` Vinod Koul
@ 2021-06-07  8:06             ` Johan Hovold
  2021-06-07 10:19               ` Vinod Koul
  0 siblings, 1 reply; 16+ messages in thread
From: Johan Hovold @ 2021-06-07  8:06 UTC (permalink / raw)
  To: Vinod Koul
  Cc: yukuai (C),
	mcoquelin.stm32, alexandre.torgue, michal.simek, dmaengine,
	linux-kernel, linux-stm32, linux-arm-kernel, yi.zhang

On Thu, Jun 03, 2021 at 04:39:08PM +0530, Vinod Koul wrote:
> On 31-05-21, 11:19, Johan Hovold wrote:
> > On Mon, May 31, 2021 at 02:27:34PM +0530, Vinod Koul wrote:
> > > On 31-05-21, 14:11, yukuai (C) wrote:
> > > > On 2021/05/31 12:00, Vinod Koul wrote:
> > > > > On 17-05-21, 16:18, Yu Kuai wrote:
> > > > > > pm_runtime_get_sync will increment pm usage counter even it failed.
> > > > > > Forgetting to putting operation will result in reference leak here.
> > > > > > Fix it by replacing it with pm_runtime_resume_and_get to keep usage
> > > > > > counter balanced.

> > > Yes the rumtime_pm is disabled on failure here and the count would have
> > > no consequence...
> > 
> > You should still balance the PM usage counter as it isn't reset for
> > example when reloading the driver.
> 
> Should I driver trust that on load PM usage counter is balanced and not
> to be reset..?

Not sure what you're asking here. But a driver should never leave the PM
usage counter unbalanced.

> > Using pm_runtime_resume_and_get() is one way of handling this, but
> > alternatively you could also move the error_pm label above the
> > pm_runtime_put() in the error path.
> 
> That would be a better way I think

Johan

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

* Re: [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()
  2021-06-07  8:06             ` Johan Hovold
@ 2021-06-07 10:19               ` Vinod Koul
  2021-07-05  8:41                 ` yukuai (C)
  0 siblings, 1 reply; 16+ messages in thread
From: Vinod Koul @ 2021-06-07 10:19 UTC (permalink / raw)
  To: Johan Hovold
  Cc: yukuai (C),
	mcoquelin.stm32, alexandre.torgue, michal.simek, dmaengine,
	linux-kernel, linux-stm32, linux-arm-kernel, yi.zhang

On 07-06-21, 10:06, Johan Hovold wrote:
> On Thu, Jun 03, 2021 at 04:39:08PM +0530, Vinod Koul wrote:
> > On 31-05-21, 11:19, Johan Hovold wrote:
> > > On Mon, May 31, 2021 at 02:27:34PM +0530, Vinod Koul wrote:
> > > > On 31-05-21, 14:11, yukuai (C) wrote:
> > > > > On 2021/05/31 12:00, Vinod Koul wrote:
> > > > > > On 17-05-21, 16:18, Yu Kuai wrote:
> > > > > > > pm_runtime_get_sync will increment pm usage counter even it failed.
> > > > > > > Forgetting to putting operation will result in reference leak here.
> > > > > > > Fix it by replacing it with pm_runtime_resume_and_get to keep usage
> > > > > > > counter balanced.
> 
> > > > Yes the rumtime_pm is disabled on failure here and the count would have
> > > > no consequence...
> > > 
> > > You should still balance the PM usage counter as it isn't reset for
> > > example when reloading the driver.
> > 
> > Should I driver trust that on load PM usage counter is balanced and not
> > to be reset..?
> 
> Not sure what you're asking here. But a driver should never leave the PM
> usage counter unbalanced.

Thinking about again, yes we should safely assume the counter is
balanced when driver loads.. so unloading while balancing sounds better
behaviour

Thanks
-- 
~Vinod

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

* Re: [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()
  2021-06-07 10:19               ` Vinod Koul
@ 2021-07-05  8:41                 ` yukuai (C)
  2021-07-06 10:49                   ` Vinod Koul
  0 siblings, 1 reply; 16+ messages in thread
From: yukuai (C) @ 2021-07-05  8:41 UTC (permalink / raw)
  To: Vinod Koul, Johan Hovold
  Cc: mcoquelin.stm32, alexandre.torgue, michal.simek, dmaengine,
	linux-kernel, linux-stm32, linux-arm-kernel, yi.zhang

Hi, Vinod

Are you still intrested in accepting this patch?

Thanks,
Yu Kuai

On 2021/06/07 18:19, Vinod Koul wrote:
> On 07-06-21, 10:06, Johan Hovold wrote:
>> On Thu, Jun 03, 2021 at 04:39:08PM +0530, Vinod Koul wrote:
>>> On 31-05-21, 11:19, Johan Hovold wrote:
>>>> On Mon, May 31, 2021 at 02:27:34PM +0530, Vinod Koul wrote:
>>>>> On 31-05-21, 14:11, yukuai (C) wrote:
>>>>>> On 2021/05/31 12:00, Vinod Koul wrote:
>>>>>>> On 17-05-21, 16:18, Yu Kuai wrote:
>>>>>>>> pm_runtime_get_sync will increment pm usage counter even it failed.
>>>>>>>> Forgetting to putting operation will result in reference leak here.
>>>>>>>> Fix it by replacing it with pm_runtime_resume_and_get to keep usage
>>>>>>>> counter balanced.
>>
>>>>> Yes the rumtime_pm is disabled on failure here and the count would have
>>>>> no consequence...
>>>>
>>>> You should still balance the PM usage counter as it isn't reset for
>>>> example when reloading the driver.
>>>
>>> Should I driver trust that on load PM usage counter is balanced and not
>>> to be reset..?
>>
>> Not sure what you're asking here. But a driver should never leave the PM
>> usage counter unbalanced.
> 
> Thinking about again, yes we should safely assume the counter is
> balanced when driver loads.. so unloading while balancing sounds better
> behaviour
> 
> Thanks
> 

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

* Re: [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()
  2021-07-05  8:41                 ` yukuai (C)
@ 2021-07-06 10:49                   ` Vinod Koul
  0 siblings, 0 replies; 16+ messages in thread
From: Vinod Koul @ 2021-07-06 10:49 UTC (permalink / raw)
  To: yukuai (C)
  Cc: Johan Hovold, mcoquelin.stm32, alexandre.torgue, michal.simek,
	dmaengine, linux-kernel, linux-stm32, linux-arm-kernel, yi.zhang

On 05-07-21, 16:41, yukuai (C) wrote:
> Hi, Vinod
> 
> Are you still intrested in accepting this patch?

- Please do not top post

- yes, pls rebase and resend

> On 2021/06/07 18:19, Vinod Koul wrote:
> > On 07-06-21, 10:06, Johan Hovold wrote:
> > > On Thu, Jun 03, 2021 at 04:39:08PM +0530, Vinod Koul wrote:
> > > > On 31-05-21, 11:19, Johan Hovold wrote:
> > > > > On Mon, May 31, 2021 at 02:27:34PM +0530, Vinod Koul wrote:
> > > > > > On 31-05-21, 14:11, yukuai (C) wrote:
> > > > > > > On 2021/05/31 12:00, Vinod Koul wrote:
> > > > > > > > On 17-05-21, 16:18, Yu Kuai wrote:
> > > > > > > > > pm_runtime_get_sync will increment pm usage counter even it failed.
> > > > > > > > > Forgetting to putting operation will result in reference leak here.
> > > > > > > > > Fix it by replacing it with pm_runtime_resume_and_get to keep usage
> > > > > > > > > counter balanced.
> > > 
> > > > > > Yes the rumtime_pm is disabled on failure here and the count would have
> > > > > > no consequence...
> > > > > 
> > > > > You should still balance the PM usage counter as it isn't reset for
> > > > > example when reloading the driver.
> > > > 
> > > > Should I driver trust that on load PM usage counter is balanced and not
> > > > to be reset..?
> > > 
> > > Not sure what you're asking here. But a driver should never leave the PM
> > > usage counter unbalanced.
> > 
> > Thinking about again, yes we should safely assume the counter is
> > balanced when driver loads.. so unloading while balancing sounds better
> > behaviour
> > 
> > Thanks
> > 

-- 
~Vinod

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

end of thread, other threads:[~2021-07-06 10:49 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-17  8:18 [PATCH 0/3] cleanup patches for PM reference leak Yu Kuai
2021-05-17  8:18 ` [PATCH 1/3] dmaengine: stm32-mdma: fix PM reference leak in stm32_mdma_alloc_chan_resourc() Yu Kuai
2021-05-31  4:03   ` Vinod Koul
2021-05-17  8:18 ` [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe() Yu Kuai
2021-05-31  4:00   ` Vinod Koul
2021-05-31  6:11     ` yukuai (C)
2021-05-31  8:57       ` Vinod Koul
2021-05-31  9:19         ` Johan Hovold
2021-06-03 11:09           ` Vinod Koul
2021-06-07  8:06             ` Johan Hovold
2021-06-07 10:19               ` Vinod Koul
2021-07-05  8:41                 ` yukuai (C)
2021-07-06 10:49                   ` Vinod Koul
2021-05-17  8:18 ` [PATCH 3/3] dmaengine: zynqmp_dma: Fix PM reference leak in zynqmp_dma_alloc_chan_resourc() Yu Kuai
2021-05-31  4:03   ` Vinod Koul
2021-05-29  9:13 ` [PATCH 0/3] cleanup patches for PM reference leak yukuai (C)

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