Re: [PATCH v4 18/79] media: sti/delta: fix pm_runtime_get_sync() usage count

From: Jonathan Cameron
Date: Fri Apr 30 2021 - 12:49:07 EST


On Wed, 28 Apr 2021 16:51:39 +0200
Mauro Carvalho Chehab <mchehab+huawei@xxxxxxxxxx> wrote:

> The pm_runtime_get_sync() internally increments the
> dev->power.usage_count without decrementing it, even on errors.
> Replace it by the new pm_runtime_resume_and_get(), introduced by:
> commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter")
> in order to properly decrement the usage counter and avoid memory
> leaks.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@xxxxxxxxxx>
This looks wrong. The caller of this calls delta_put_autosuspend()
on error which calls pm_runtime_put_autosuspend() on something where
we never incremented the count after your change.

> ---
> drivers/media/platform/sti/delta/delta-v4l2.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/platform/sti/delta/delta-v4l2.c b/drivers/media/platform/sti/delta/delta-v4l2.c
> index c691b3d81549..9928b7c46a41 100644
> --- a/drivers/media/platform/sti/delta/delta-v4l2.c
> +++ b/drivers/media/platform/sti/delta/delta-v4l2.c
> @@ -1277,9 +1277,9 @@ int delta_get_sync(struct delta_ctx *ctx)
> int ret = 0;
>
> /* enable the hardware */
> - ret = pm_runtime_get_sync(delta->dev);
> + ret = pm_runtime_resume_and_get(delta->dev);
> if (ret < 0) {
> - dev_err(delta->dev, "%s pm_runtime_get_sync failed (%d)\n",
> + dev_err(delta->dev, "%s pm_runtime_resume_and_get failed (%d)\n",
> __func__, ret);
> return ret;
> }