Skip to content

Commit

Permalink
media: exynos4-is: fix pm_runtime_get_sync() usage count
Browse files Browse the repository at this point in the history
[ Upstream commit 59f9624 ]

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

On some places, this is ok, but on others the usage count
ended being unbalanced on failures.

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.

As a bonus, such function always return zero on success. So,
some code can be simplified.

Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.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 b769693 commit 81e32ae
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 30 deletions.
6 changes: 2 additions & 4 deletions drivers/media/platform/exynos4-is/fimc-capture.c
Expand Up @@ -478,11 +478,9 @@ static int fimc_capture_open(struct file *file)
goto unlock;

set_bit(ST_CAPT_BUSY, &fimc->state);
ret = pm_runtime_get_sync(&fimc->pdev->dev);
if (ret < 0) {
pm_runtime_put_sync(&fimc->pdev->dev);
ret = pm_runtime_resume_and_get(&fimc->pdev->dev);
if (ret < 0)
goto unlock;
}

ret = v4l2_fh_open(file);
if (ret) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/media/platform/exynos4-is/fimc-is.c
Expand Up @@ -828,9 +828,9 @@ static int fimc_is_probe(struct platform_device *pdev)
goto err_irq;
}

ret = pm_runtime_get_sync(dev);
ret = pm_runtime_resume_and_get(dev);
if (ret < 0)
goto err_pm;
goto err_irq;

vb2_dma_contig_set_max_seg_size(dev, DMA_BIT_MASK(32));

Expand Down
3 changes: 1 addition & 2 deletions drivers/media/platform/exynos4-is/fimc-isp-video.c
Expand Up @@ -275,7 +275,7 @@ static int isp_video_open(struct file *file)
if (ret < 0)
goto unlock;

ret = pm_runtime_get_sync(&isp->pdev->dev);
ret = pm_runtime_resume_and_get(&isp->pdev->dev);
if (ret < 0)
goto rel_fh;

Expand All @@ -293,7 +293,6 @@ static int isp_video_open(struct file *file)
if (!ret)
goto unlock;
rel_fh:
pm_runtime_put_noidle(&isp->pdev->dev);
v4l2_fh_release(file);
unlock:
mutex_unlock(&isp->video_lock);
Expand Down
7 changes: 3 additions & 4 deletions drivers/media/platform/exynos4-is/fimc-isp.c
Expand Up @@ -304,11 +304,10 @@ static int fimc_isp_subdev_s_power(struct v4l2_subdev *sd, int on)
pr_debug("on: %d\n", on);

if (on) {
ret = pm_runtime_get_sync(&is->pdev->dev);
if (ret < 0) {
pm_runtime_put(&is->pdev->dev);
ret = pm_runtime_resume_and_get(&is->pdev->dev);
if (ret < 0)
return ret;
}

set_bit(IS_ST_PWR_ON, &is->state);

ret = fimc_is_start_firmware(is);
Expand Down
5 changes: 3 additions & 2 deletions drivers/media/platform/exynos4-is/fimc-lite.c
Expand Up @@ -469,9 +469,9 @@ static int fimc_lite_open(struct file *file)
}

set_bit(ST_FLITE_IN_USE, &fimc->state);
ret = pm_runtime_get_sync(&fimc->pdev->dev);
ret = pm_runtime_resume_and_get(&fimc->pdev->dev);
if (ret < 0)
goto err_pm;
goto err_in_use;

ret = v4l2_fh_open(file);
if (ret < 0)
Expand Down Expand Up @@ -499,6 +499,7 @@ static int fimc_lite_open(struct file *file)
v4l2_fh_release(file);
err_pm:
pm_runtime_put_sync(&fimc->pdev->dev);
err_in_use:
clear_bit(ST_FLITE_IN_USE, &fimc->state);
unlock:
mutex_unlock(&fimc->lock);
Expand Down
5 changes: 1 addition & 4 deletions drivers/media/platform/exynos4-is/fimc-m2m.c
Expand Up @@ -73,17 +73,14 @@ static void fimc_m2m_shutdown(struct fimc_ctx *ctx)
static int start_streaming(struct vb2_queue *q, unsigned int count)
{
struct fimc_ctx *ctx = q->drv_priv;
int ret;

ret = pm_runtime_get_sync(&ctx->fimc_dev->pdev->dev);
return ret > 0 ? 0 : ret;
return pm_runtime_resume_and_get(&ctx->fimc_dev->pdev->dev);
}

static void stop_streaming(struct vb2_queue *q)
{
struct fimc_ctx *ctx = q->drv_priv;


fimc_m2m_shutdown(ctx);
fimc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR);
pm_runtime_put(&ctx->fimc_dev->pdev->dev);
Expand Down
9 changes: 3 additions & 6 deletions drivers/media/platform/exynos4-is/media-dev.c
Expand Up @@ -510,11 +510,9 @@ static int fimc_md_register_sensor_entities(struct fimc_md *fmd)
if (!fmd->pmf)
return -ENXIO;

ret = pm_runtime_get_sync(fmd->pmf);
if (ret < 0) {
pm_runtime_put(fmd->pmf);
ret = pm_runtime_resume_and_get(fmd->pmf);
if (ret < 0)
return ret;
}

fmd->num_sensors = 0;

Expand Down Expand Up @@ -1289,8 +1287,7 @@ static int cam_clk_prepare(struct clk_hw *hw)
if (camclk->fmd->pmf == NULL)
return -ENODEV;

ret = pm_runtime_get_sync(camclk->fmd->pmf);
return ret < 0 ? ret : 0;
return pm_runtime_resume_and_get(camclk->fmd->pmf);
}

static void cam_clk_unprepare(struct clk_hw *hw)
Expand Down
10 changes: 4 additions & 6 deletions drivers/media/platform/exynos4-is/mipi-csis.c
Expand Up @@ -494,7 +494,7 @@ static int s5pcsis_s_power(struct v4l2_subdev *sd, int on)
struct device *dev = &state->pdev->dev;

if (on)
return pm_runtime_get_sync(dev);
return pm_runtime_resume_and_get(dev);

return pm_runtime_put_sync(dev);
}
Expand All @@ -509,11 +509,9 @@ static int s5pcsis_s_stream(struct v4l2_subdev *sd, int enable)

if (enable) {
s5pcsis_clear_counters(state);
ret = pm_runtime_get_sync(&state->pdev->dev);
if (ret && ret != 1) {
pm_runtime_put_noidle(&state->pdev->dev);
ret = pm_runtime_resume_and_get(&state->pdev->dev);
if (ret < 0)
return ret;
}
}

mutex_lock(&state->lock);
Expand All @@ -535,7 +533,7 @@ static int s5pcsis_s_stream(struct v4l2_subdev *sd, int enable)
if (!enable)
pm_runtime_put(&state->pdev->dev);

return ret == 1 ? 0 : ret;
return ret;
}

static int s5pcsis_enum_mbus_code(struct v4l2_subdev *sd,
Expand Down

0 comments on commit 81e32ae

Please sign in to comment.