Skip to content

Commit

Permalink
media: sti/bdisp: fix pm_runtime_get_sync() usage count
Browse files Browse the repository at this point in the history
[ Upstream commit c44eac5 ]

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.

The bdisp_start_streaming() doesn't take it into account, which
would unbalance PM usage counter at bdisp_stop_streaming().

The logic at bdisp_probe() is correct, but the best is to use
the same call along the driver.

So, replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter")
in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
mchehab authored and gregkh committed Jul 14, 2021
1 parent abdc897 commit 29fd79b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions drivers/media/platform/sti/bdisp/bdisp-v4l2.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ static int bdisp_start_streaming(struct vb2_queue *q, unsigned int count)
{
struct bdisp_ctx *ctx = q->drv_priv;
struct vb2_v4l2_buffer *buf;
int ret = pm_runtime_get_sync(ctx->bdisp_dev->dev);
int ret = pm_runtime_resume_and_get(ctx->bdisp_dev->dev);

if (ret < 0) {
dev_err(ctx->bdisp_dev->dev, "failed to set runtime PM\n");
Expand Down Expand Up @@ -1364,10 +1364,10 @@ static int bdisp_probe(struct platform_device *pdev)

/* Power management */
pm_runtime_enable(dev);
ret = pm_runtime_get_sync(dev);
ret = pm_runtime_resume_and_get(dev);
if (ret < 0) {
dev_err(dev, "failed to set PM\n");
goto err_pm;
goto err_remove;
}

/* Filters */
Expand Down Expand Up @@ -1395,6 +1395,7 @@ static int bdisp_probe(struct platform_device *pdev)
bdisp_hw_free_filters(bdisp->dev);
err_pm:
pm_runtime_put(dev);
err_remove:
bdisp_debugfs_remove(bdisp);
v4l2_device_unregister(&bdisp->v4l2_dev);
err_clk:
Expand Down

0 comments on commit 29fd79b

Please sign in to comment.