Skip to content

Commit

Permalink
media: mtk-vcodec: fix PM runtime get logic
Browse files Browse the repository at this point in the history
[ Upstream commit 908711f ]

Currently, the driver just assumes that PM runtime logic
succeded resuming the device.

That may not be the case, as pm_runtime_get_sync()
can fail (but keeping the usage count incremented).

Replace the code to use pm_runtime_resume_and_get(),
and letting it return the error code.

This way, if mtk_vcodec_dec_pw_on() fails, the logic
under fops_vcodec_open() will do the right thing and
return an error, instead of just assuming that the
device is ready to be used.

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 ae522a7 commit 04c04a9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ static int fops_vcodec_open(struct file *file)
mtk_vcodec_dec_set_default_params(ctx);

if (v4l2_fh_is_singular(&ctx->fh)) {
mtk_vcodec_dec_pw_on(&dev->pm);
ret = mtk_vcodec_dec_pw_on(&dev->pm);
if (ret < 0)
goto err_load_fw;
/*
* Does nothing if firmware was already loaded.
*/
Expand Down
8 changes: 5 additions & 3 deletions drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@ void mtk_vcodec_release_dec_pm(struct mtk_vcodec_dev *dev)
put_device(dev->pm.larbvdec);
}

void mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm)
int mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm)
{
int ret;

ret = pm_runtime_get_sync(pm->dev);
ret = pm_runtime_resume_and_get(pm->dev);
if (ret)
mtk_v4l2_err("pm_runtime_get_sync fail %d", ret);
mtk_v4l2_err("pm_runtime_resume_and_get fail %d", ret);

return ret;
}

void mtk_vcodec_dec_pw_off(struct mtk_vcodec_pm *pm)
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
int mtk_vcodec_init_dec_pm(struct mtk_vcodec_dev *dev);
void mtk_vcodec_release_dec_pm(struct mtk_vcodec_dev *dev);

void mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm);
int mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm);
void mtk_vcodec_dec_pw_off(struct mtk_vcodec_pm *pm);
void mtk_vcodec_dec_clock_on(struct mtk_vcodec_pm *pm);
void mtk_vcodec_dec_clock_off(struct mtk_vcodec_pm *pm);
Expand Down

0 comments on commit 04c04a9

Please sign in to comment.