media: i2c: Use pm_runtime_resume_and_get()
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Thu, 14 Sep 2023 17:20:54 +0000 (20:20 +0300)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Wed, 27 Sep 2023 07:39:57 +0000 (09:39 +0200)
Simplify error handling by using pm_runtime_resume_and_get() instead of
pm_runtime_get_sync() with a put call in the error path.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Benjamin Mugnier <benjamin.mugnier@foss.st.com> (st-vgxy61)
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/media/i2c/ccs/ccs-core.c
drivers/media/i2c/hi846.c
drivers/media/i2c/hi847.c
drivers/media/i2c/imx208.c
drivers/media/i2c/og01a1b.c
drivers/media/i2c/ov5693.c
drivers/media/i2c/ov7251.c
drivers/media/i2c/st-vgxy61.c

index 49e0d9a..569bf9b 100644 (file)
@@ -1893,9 +1893,9 @@ static int ccs_pm_get_init(struct ccs_sensor *sensor)
         * relies at the returned value to detect if the device was already
         * active or not.
         */
-       rval = pm_runtime_get_sync(&client->dev);
-       if (rval < 0)
-               goto error;
+       rval = pm_runtime_resume_and_get(&client->dev);
+       if (rval)
+               return rval;
 
        /* Device was already active, so don't set controls */
        if (rval == 1)
index fa00387..8a8ae89 100644 (file)
@@ -1613,11 +1613,9 @@ static int hi846_set_stream(struct v4l2_subdev *sd, int enable)
        mutex_lock(&hi846->mutex);
 
        if (enable) {
-               ret = pm_runtime_get_sync(&client->dev);
-               if (ret < 0) {
-                       pm_runtime_put_noidle(&client->dev);
+               ret = pm_runtime_resume_and_get(&client->dev);
+               if (ret)
                        goto out;
-               }
 
                ret = hi846_start_streaming(hi846);
        }
index 32547d7..47aa2cd 100644 (file)
@@ -2623,9 +2623,8 @@ static int hi847_set_stream(struct v4l2_subdev *sd, int enable)
 
        mutex_lock(&hi847->mutex);
        if (enable) {
-               ret = pm_runtime_get_sync(&client->dev);
-               if (ret < 0) {
-                       pm_runtime_put_noidle(&client->dev);
+               ret = pm_runtime_resume_and_get(&client->dev);
+               if (ret) {
                        mutex_unlock(&hi847->mutex);
                        return ret;
                }
index ee5a286..a6edcae 100644 (file)
@@ -720,9 +720,11 @@ static int imx208_set_stream(struct v4l2_subdev *sd, int enable)
        }
 
        if (enable) {
-               ret = pm_runtime_get_sync(&client->dev);
-               if (ret < 0)
-                       goto err_rpm_put;
+               ret = pm_runtime_resume_and_get(&client->dev);
+               if (ret) {
+                       mutex_unlock(&imx208->imx208_mx);
+                       return ret;
+               }
 
                /*
                 * Apply default & customized values
@@ -819,11 +821,9 @@ static int imx208_read_otp(struct imx208 *imx208)
        if (imx208->otp_read)
                goto out_unlock;
 
-       ret = pm_runtime_get_sync(&client->dev);
-       if (ret < 0) {
-               pm_runtime_put_noidle(&client->dev);
+       ret = pm_runtime_resume_and_get(&client->dev);
+       if (ret)
                goto out_unlock;
-       }
 
        ret = imx208_identify_module(imx208);
        if (ret)
index 365ce56..ccf6731 100644 (file)
@@ -737,9 +737,8 @@ static int og01a1b_set_stream(struct v4l2_subdev *sd, int enable)
 
        mutex_lock(&og01a1b->mutex);
        if (enable) {
-               ret = pm_runtime_get_sync(&client->dev);
-               if (ret < 0) {
-                       pm_runtime_put_noidle(&client->dev);
+               ret = pm_runtime_resume_and_get(&client->dev);
+               if (ret) {
                        mutex_unlock(&og01a1b->mutex);
                        return ret;
                }
index 488ee6d..033cf7f 100644 (file)
@@ -975,9 +975,9 @@ static int ov5693_s_stream(struct v4l2_subdev *sd, int enable)
        int ret;
 
        if (enable) {
-               ret = pm_runtime_get_sync(ov5693->dev);
-               if (ret < 0)
-                       goto err_power_down;
+               ret = pm_runtime_resume_and_get(ov5693->dev);
+               if (ret)
+                       return ret;
 
                mutex_lock(&ov5693->lock);
                ret = __v4l2_ctrl_handler_setup(&ov5693->ctrls.handler);
index 675fb37..6582cc0 100644 (file)
@@ -1340,9 +1340,11 @@ static int ov7251_s_stream(struct v4l2_subdev *subdev, int enable)
        mutex_lock(&ov7251->lock);
 
        if (enable) {
-               ret = pm_runtime_get_sync(ov7251->dev);
-               if (ret < 0)
-                       goto err_power_down;
+               ret = pm_runtime_resume_and_get(ov7251->dev);
+               if (ret) {
+                       mutex_unlock(&ov7251->lock);
+                       return ret;
+               }
 
                ret = ov7251_pll_configure(ov7251);
                if (ret) {
index 30f82ca..5dbfb04 100644 (file)
@@ -1170,14 +1170,9 @@ static int vgxy61_stream_enable(struct vgxy61_dev *sensor)
        if (ret)
                return ret;
 
-       ret = pm_runtime_get_sync(&client->dev);
-       if (ret < 0) {
-               pm_runtime_put_autosuspend(&client->dev);
+       ret = pm_runtime_resume_and_get(&client->dev);
+       if (ret)
                return ret;
-       }
-
-       /* pm_runtime_get_sync() can return 1 as a valid return code */
-       ret = 0;
 
        vgxy61_write_reg(sensor, VGXY61_REG_FORMAT_CTRL,
                         get_bpp_by_code(sensor->fmt.code), &ret);