Skip to content

Commit

Permalink
media: i2c: imx334: fix the pm runtime get logic
Browse files Browse the repository at this point in the history
[ Upstream commit 62c9044 ]

The PM runtime get logic is currently broken, as it checks if
ret is zero instead of checking if it is an error code,
as reported by Dan Carpenter.

While here, use the pm_runtime_resume_and_get() as added by:
commit dd8088d ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter")
added pm_runtime_resume_and_get() in order to automatically handle
dev->power.usage_count decrement on errors. As a bonus, such function
always return zero on success.

It should also be noticed that a fail of pm_runtime_get_sync() would
potentially result in a spurious runtime_suspend(), instead of
using pm_runtime_put_noidle().

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Daniele Alessandrelli <daniele.alessandrelli@intel.com>
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 58bc5e4 commit 59378a8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions drivers/media/i2c/imx334.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,9 +717,9 @@ static int imx334_set_stream(struct v4l2_subdev *sd, int enable)
}

if (enable) {
ret = pm_runtime_get_sync(imx334->dev);
if (ret)
goto error_power_off;
ret = pm_runtime_resume_and_get(imx334->dev);
if (ret < 0)
goto error_unlock;

ret = imx334_start_streaming(imx334);
if (ret)
Expand All @@ -737,6 +737,7 @@ static int imx334_set_stream(struct v4l2_subdev *sd, int enable)

error_power_off:
pm_runtime_put(imx334->dev);
error_unlock:
mutex_unlock(&imx334->mutex);

return ret;
Expand Down

0 comments on commit 59378a8

Please sign in to comment.