Re: [PATCH] media: staging: tegra-vde: fix runtime pm imbalance on error
From: Rafael J. Wysocki
Date: Thu May 21 2020 - 13:02:29 EST
On Wednesday, May 20, 2020 5:02:30 PM CEST Dan Carpenter wrote:
> On Wed, May 20, 2020 at 01:15:44PM +0300, Dmitry Osipenko wrote:
> > 20.05.2020 12:51, Dinghao Liu ÐÐÑÐÑ:
> > > pm_runtime_get_sync() increments the runtime PM usage counter even
> > > it returns an error code. Thus a pairing decrement is needed on
> > > the error handling path to keep the counter balanced.
> > >
> > > Signed-off-by: Dinghao Liu <dinghao.liu@xxxxxxxxxx>
> > > ---
> > > drivers/staging/media/tegra-vde/vde.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/staging/media/tegra-vde/vde.c b/drivers/staging/media/tegra-vde/vde.c
> > > index d3e63512a765..dd134a3a15c7 100644
> > > --- a/drivers/staging/media/tegra-vde/vde.c
> > > +++ b/drivers/staging/media/tegra-vde/vde.c
> > > @@ -777,7 +777,7 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde,
> > >
> > > ret = pm_runtime_get_sync(dev);
> > > if (ret < 0)
> > > - goto unlock;
> > > + goto put_runtime_pm;
> > >
> > > /*
> > > * We rely on the VDE registers reset value, otherwise VDE
> > >
> >
> > Hello Dinghao,
> >
> > Thank you for the patch. I sent out a similar patch a week ago [1].
> >
> > [1]
> > https://patchwork.ozlabs.org/project/linux-tegra/patch/20200514210847.9269-2-digetx@xxxxxxxxx/
> >
> > The pm_runtime_put_noidle() should have the same effect as yours
> > variant, although my variant won't change the last_busy RPM time, which
> > I think is a bit more appropriate behavior.
>
> I don't think either patch is correct. The right thing to do is to fix
> __pm_runtime_resume() so it doesn't leak a reference count on error.
>
> The problem is that a lot of functions don't check the return so
> possibly we are relying on that behavior.
Actually, the function was written with this case in mind.
In retrospect, that has been a mistake and there should be a void variant
to cover this case, but it's been like that for several years and the
documentation doesn't really say that the reference counter will be
decremented on errors.
> We may need to introduce a
> new function which cleans up properly instead of leaking reference
> counts?
Well, even with that, all of the broken callers of pm_runtime_get_sync()
would need to be changed to use the new function instead?
Is that what you mean?