2021-05-17 08:12:48

by Yu Kuai

[permalink] [raw]
Subject: [PATCH 0/3] cleanup patches for PM reference leak

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



2021-05-17 13:09:06

by Yu Kuai

[permalink] [raw]
Subject: [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()

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 <[email protected]>
Signed-off-by: Yu Kuai <[email protected]>
---
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


2021-05-17 13:09:58

by Yu Kuai

[permalink] [raw]
Subject: [PATCH 1/3] dmaengine: stm32-mdma: fix PM reference leak in stm32_mdma_alloc_chan_resourc()

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 <[email protected]>
Signed-off-by: Yu Kuai <[email protected]>
---
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


2021-05-17 13:43:14

by Yu Kuai

[permalink] [raw]
Subject: [PATCH 3/3] dmaengine: zynqmp_dma: Fix PM reference leak in zynqmp_dma_alloc_chan_resourc()

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 <[email protected]>
Signed-off-by: Yu Kuai <[email protected]>
---
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


2021-05-29 09:16:04

by Yu Kuai

[permalink] [raw]
Subject: Re: [PATCH 0/3] cleanup patches for PM reference leak

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

2021-05-31 04:02:46

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()

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 <[email protected]>
> Signed-off-by: Yu Kuai <[email protected]>
> ---
> 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

2021-05-31 04:05:36

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH 3/3] dmaengine: zynqmp_dma: Fix PM reference leak in zynqmp_dma_alloc_chan_resourc()

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

2021-05-31 04:07:25

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH 1/3] dmaengine: stm32-mdma: fix PM reference leak in stm32_mdma_alloc_chan_resourc()

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

2021-05-31 06:12:46

by Yu Kuai

[permalink] [raw]
Subject: Re: [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()

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 <[email protected]>
>> Signed-off-by: Yu Kuai <[email protected]>
>> ---
>> 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
>

2021-05-31 09:02:01

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()

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 <[email protected]>
> > > Signed-off-by: Yu Kuai <[email protected]>
> > > ---
> > > 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

2021-05-31 09:20:13

by Johan Hovold

[permalink] [raw]
Subject: Re: [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()

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 <[email protected]>
> > > > Signed-off-by: Yu Kuai <[email protected]>
> > > > ---
> > > > 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

2021-06-03 11:12:30

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()

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 <[email protected]>
> > > > > Signed-off-by: Yu Kuai <[email protected]>
> > > > > ---
> > > > > 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

2021-06-07 08:08:45

by Johan Hovold

[permalink] [raw]
Subject: Re: [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()

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

2021-06-07 10:21:10

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()

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

2021-07-05 08:42:25

by Yu Kuai

[permalink] [raw]
Subject: Re: [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()

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
>

2021-07-06 10:53:35

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH 2/3] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()

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