2021-05-17 13:25:20

by Robert Foss

[permalink] [raw]
Subject: Re: [PATCH] drm: bridge: cdns-mhdp8546: Fix PM reference leak in cdns_mhdp_probe()

Hey Yu,

On Mon, 17 May 2021 at 10:08, Yu Kuai <[email protected]> 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/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c
> index 0cd8f40fb690..305489d48c16 100644
> --- a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c
> +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c
> @@ -2478,7 +2478,7 @@ static int cdns_mhdp_probe(struct platform_device *pdev)
> clk_prepare_enable(clk);
>
> pm_runtime_enable(dev);
> - ret = pm_runtime_get_sync(dev);
> + ret = pm_runtime_resume_and_get(dev);
> if (ret < 0) {
> dev_err(dev, "pm_runtime_get_sync failed\n");
> pm_runtime_disable(dev);

The code is correct as it is. If pm_runtime_get_sync() fails and
increments[1] the pm.usage_count variable, that isn't a problem since
pm_runtime_disable() disables pm, and resets pm.usage_count variable
to zero[2].

[1] https://elixir.bootlin.com/linux/latest/source/include/linux/pm_runtime.h#L384
[2] https://elixir.bootlin.com/linux/latest/source/drivers/base/power/runtime.c#L1383


2021-05-17 18:19:26

by Yu Kuai

[permalink] [raw]
Subject: Re: [PATCH] drm: bridge: cdns-mhdp8546: Fix PM reference leak in cdns_mhdp_probe()

On 2021/05/17 17:27, Robert Foss wrote:
> Hey Yu,
>
> On Mon, 17 May 2021 at 10:08, Yu Kuai <[email protected]> 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/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c
>> index 0cd8f40fb690..305489d48c16 100644
>> --- a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c
>> +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c
>> @@ -2478,7 +2478,7 @@ static int cdns_mhdp_probe(struct platform_device *pdev)
>> clk_prepare_enable(clk);
>>
>> pm_runtime_enable(dev);
>> - ret = pm_runtime_get_sync(dev);
>> + ret = pm_runtime_resume_and_get(dev);
>> if (ret < 0) {
>> dev_err(dev, "pm_runtime_get_sync failed\n");
>> pm_runtime_disable(dev);
>
> The code is correct as it is. If pm_runtime_get_sync() fails and
> increments[1] the pm.usage_count variable, that isn't a problem since
> pm_runtime_disable() disables pm, and resets pm.usage_count variable
> to zero[2].
>
> [1] https://elixir.bootlin.com/linux/latest/source/include/linux/pm_runtime.h#L384
> [2] https://elixir.bootlin.com/linux/latest/source/drivers/base/power/runtime.c#L1383
> .
>
Hi,

Thank you very much for your explanation

Yu Kuai

2021-05-19 16:22:53

by Johan Hovold

[permalink] [raw]
Subject: Re: [PATCH] drm: bridge: cdns-mhdp8546: Fix PM reference leak in cdns_mhdp_probe()

On Mon, May 17, 2021 at 11:27:38AM +0200, Robert Foss wrote:
> Hey Yu,
>
> On Mon, 17 May 2021 at 10:08, Yu Kuai <[email protected]> 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/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c
> > index 0cd8f40fb690..305489d48c16 100644
> > --- a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c
> > +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c
> > @@ -2478,7 +2478,7 @@ static int cdns_mhdp_probe(struct platform_device *pdev)
> > clk_prepare_enable(clk);
> >
> > pm_runtime_enable(dev);
> > - ret = pm_runtime_get_sync(dev);
> > + ret = pm_runtime_resume_and_get(dev);
> > if (ret < 0) {
> > dev_err(dev, "pm_runtime_get_sync failed\n");
> > pm_runtime_disable(dev);
>
> The code is correct as it is. If pm_runtime_get_sync() fails and
> increments[1] the pm.usage_count variable, that isn't a problem since
> pm_runtime_disable() disables pm, and resets pm.usage_count variable
> to zero[2].

No it doesn't; pm_runtime_disable() does not reset the counter and you
still need to decrement the usage count when pm_runtime_get_sync()
fails.

> [1] https://elixir.bootlin.com/linux/latest/source/include/linux/pm_runtime.h#L384
> [2] https://elixir.bootlin.com/linux/latest/source/drivers/base/power/runtime.c#L1383

Johan

2021-05-19 18:08:54

by Robert Foss

[permalink] [raw]
Subject: Re: [PATCH] drm: bridge: cdns-mhdp8546: Fix PM reference leak in cdns_mhdp_probe()

On Tue, 18 May 2021 at 09:42, Johan Hovold <[email protected]> wrote:
>
> On Mon, May 17, 2021 at 11:27:38AM +0200, Robert Foss wrote:
> > Hey Yu,
> >
> > On Mon, 17 May 2021 at 10:08, Yu Kuai <[email protected]> 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/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c
> > > index 0cd8f40fb690..305489d48c16 100644
> > > --- a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c
> > > +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c
> > > @@ -2478,7 +2478,7 @@ static int cdns_mhdp_probe(struct platform_device *pdev)
> > > clk_prepare_enable(clk);
> > >
> > > pm_runtime_enable(dev);
> > > - ret = pm_runtime_get_sync(dev);
> > > + ret = pm_runtime_resume_and_get(dev);
> > > if (ret < 0) {
> > > dev_err(dev, "pm_runtime_get_sync failed\n");

This error message is a bit confusing now, could you update it.

> > > pm_runtime_disable(dev);
> >
> > The code is correct as it is. If pm_runtime_get_sync() fails and
> > increments[1] the pm.usage_count variable, that isn't a problem since
> > pm_runtime_disable() disables pm, and resets pm.usage_count variable
> > to zero[2].
>
> No it doesn't; pm_runtime_disable() does not reset the counter and you
> still need to decrement the usage count when pm_runtime_get_sync()
> fails.

Thanks for chiming in Johan, you're absolutely right and I must have
misread something.

With the above fix, feel free to add my r-b.

Reviewed-by: Robert Foss <[email protected]>

2021-05-29 09:18:30

by Yu Kuai

[permalink] [raw]
Subject: Re: [PATCH] drm: bridge: cdns-mhdp8546: Fix PM reference leak in cdns_mhdp_probe()

ping ...

On 2021/05/18 20:58, Robert Foss wrote:
> On Tue, 18 May 2021 at 09:42, Johan Hovold <[email protected]> wrote:
>>
>> On Mon, May 17, 2021 at 11:27:38AM +0200, Robert Foss wrote:
>>> Hey Yu,
>>>
>>> On Mon, 17 May 2021 at 10:08, Yu Kuai <[email protected]> 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/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c | 2 +-
>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c
>>>> index 0cd8f40fb690..305489d48c16 100644
>>>> --- a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c
>>>> +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c
>>>> @@ -2478,7 +2478,7 @@ static int cdns_mhdp_probe(struct platform_device *pdev)
>>>> clk_prepare_enable(clk);
>>>>
>>>> pm_runtime_enable(dev);
>>>> - ret = pm_runtime_get_sync(dev);
>>>> + ret = pm_runtime_resume_and_get(dev);
>>>> if (ret < 0) {
>>>> dev_err(dev, "pm_runtime_get_sync failed\n");
>
> This error message is a bit confusing now, could you update it.
>
>>>> pm_runtime_disable(dev);
>>>
>>> The code is correct as it is. If pm_runtime_get_sync() fails and
>>> increments[1] the pm.usage_count variable, that isn't a problem since
>>> pm_runtime_disable() disables pm, and resets pm.usage_count variable
>>> to zero[2].
>>
>> No it doesn't; pm_runtime_disable() does not reset the counter and you
>> still need to decrement the usage count when pm_runtime_get_sync()
>> fails.
>
> Thanks for chiming in Johan, you're absolutely right and I must have
> misread something.
>
> With the above fix, feel free to add my r-b.
>
> Reviewed-by: Robert Foss <[email protected]>
> .
>