diff mbox series

[v2,7/7] media: imx219: Put usage_count correctly in s_ctrl callback

Message ID 20231117111433.1561669-8-sakari.ailus@linux.intel.com (mailing list archive)
State Changes Requested, archived
Headers show
Series Small Runtime PM API changes | expand

Commit Message

Sakari Ailus Nov. 17, 2023, 11:14 a.m. UTC
pm_runtime_get_if_in_use() returns an error if Runtime PM is disabled for
the device, in which case it won't increment the use count.
pm_runtime_put() does that unconditionally however. Only call
pm_runtime_put() in case pm_runtime_get_if_in_use() has returned a value >
0.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/i2c/imx219.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Dave Stevenson Nov. 17, 2023, 2:20 p.m. UTC | #1
On Fri, 17 Nov 2023 at 11:15, Sakari Ailus <sakari.ailus@linux.intel.com> wrote:
>
> pm_runtime_get_if_in_use() returns an error if Runtime PM is disabled for
> the device, in which case it won't increment the use count.
> pm_runtime_put() does that unconditionally however. Only call
> pm_runtime_put() in case pm_runtime_get_if_in_use() has returned a value >
> 0.
>
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>

Reviewed-by: Dave Stevenson <dave.stevenson@raspberrypi.com>

> ---
>  drivers/media/i2c/imx219.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
> index 8436880dcf7a..9865d0b41244 100644
> --- a/drivers/media/i2c/imx219.c
> +++ b/drivers/media/i2c/imx219.c
> @@ -371,7 +371,7 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl)
>         struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd);
>         const struct v4l2_mbus_framefmt *format;
>         struct v4l2_subdev_state *state;
> -       int ret = 0;
> +       int ret = 0, pm_status;
>
>         state = v4l2_subdev_get_locked_active_state(&imx219->sd);
>         format = v4l2_subdev_get_pad_format(&imx219->sd, state, 0);
> @@ -393,7 +393,8 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl)
>          * Applying V4L2 control value only happens
>          * when power is up for streaming
>          */
> -       if (pm_runtime_get_if_in_use(&client->dev) == 0)
> +       pm_status = pm_runtime_get_if_in_use(&client->dev);
> +       if (!pm_status)
>                 return 0;
>
>         switch (ctrl->id) {
> @@ -446,7 +447,8 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl)
>                 break;
>         }
>
> -       pm_runtime_put(&client->dev);
> +       if (pm_status > 0)
> +               pm_runtime_put(&client->dev);
>
>         return ret;
>  }
> --
> 2.39.2
>
>
diff mbox series

Patch

diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
index 8436880dcf7a..9865d0b41244 100644
--- a/drivers/media/i2c/imx219.c
+++ b/drivers/media/i2c/imx219.c
@@ -371,7 +371,7 @@  static int imx219_set_ctrl(struct v4l2_ctrl *ctrl)
 	struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd);
 	const struct v4l2_mbus_framefmt *format;
 	struct v4l2_subdev_state *state;
-	int ret = 0;
+	int ret = 0, pm_status;
 
 	state = v4l2_subdev_get_locked_active_state(&imx219->sd);
 	format = v4l2_subdev_get_pad_format(&imx219->sd, state, 0);
@@ -393,7 +393,8 @@  static int imx219_set_ctrl(struct v4l2_ctrl *ctrl)
 	 * Applying V4L2 control value only happens
 	 * when power is up for streaming
 	 */
-	if (pm_runtime_get_if_in_use(&client->dev) == 0)
+	pm_status = pm_runtime_get_if_in_use(&client->dev);
+	if (!pm_status)
 		return 0;
 
 	switch (ctrl->id) {
@@ -446,7 +447,8 @@  static int imx219_set_ctrl(struct v4l2_ctrl *ctrl)
 		break;
 	}
 
-	pm_runtime_put(&client->dev);
+	if (pm_status > 0)
+		pm_runtime_put(&client->dev);
 
 	return ret;
 }