diff mbox series

[03/28] media: atomisp: ov2680: Error handling fixes

Message ID 20230401145926.596216-4-hdegoede@redhat.com (mailing list archive)
State New, archived
Headers show
Series media: atomisp: Further sensor rework + exotic features removal | expand

Commit Message

Hans de Goede April 1, 2023, 2:59 p.m. UTC
Fix s_stream error handling

Fix 3 error handling issues:

1. In ov2680_s_stream(), when pm_runtime_get_sync() fails it will still
   have incremented the pm-runtime reference count so we need to call
   pm_runtime_put()

2. In ov2680_s_stream() sensor->is_streaming should always be set to false
   when the sensor is powered-off even on i2c-communication errors.

3. In ov2680_probe(), call ov2680_remove() on ov2680_s_config() errors,
   so that pm_runtime_disable() is properly called to disable the
   runtime-pm which has been enabled before the ov2680_s_config() call.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/staging/media/atomisp/i2c/atomisp-ov2680.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Andy Shevchenko April 2, 2023, 7:21 a.m. UTC | #1
On Sat, Apr 1, 2023 at 4:59 PM Hans de Goede <hdegoede@redhat.com> wrote:
>
> Fix s_stream error handling

This looks like it should be part of the Subject (missing period).

>
> Fix 3 error handling issues:
>
> 1. In ov2680_s_stream(), when pm_runtime_get_sync() fails it will still
>    have incremented the pm-runtime reference count so we need to call
>    pm_runtime_put()
>
> 2. In ov2680_s_stream() sensor->is_streaming should always be set to false
>    when the sensor is powered-off even on i2c-communication errors.
>
> 3. In ov2680_probe(), call ov2680_remove() on ov2680_s_config() errors,
>    so that pm_runtime_disable() is properly called to disable the
>    runtime-pm which has been enabled before the ov2680_s_config() call.
>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/staging/media/atomisp/i2c/atomisp-ov2680.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c b/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c
> index 3181276ed027..63de214916f5 100644
> --- a/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c
> +++ b/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c
> @@ -419,7 +419,7 @@ static int ov2680_s_stream(struct v4l2_subdev *sd, int enable)
>         if (enable) {
>                 ret = pm_runtime_get_sync(sensor->sd.dev);
>                 if (ret < 0)
> -                       goto error_unlock;
> +                       goto error_power_down;
>
>                 ret = ov2680_set_mode(sensor);
>                 if (ret)
> @@ -447,6 +447,7 @@ static int ov2680_s_stream(struct v4l2_subdev *sd, int enable)
>
>  error_power_down:
>         pm_runtime_put(sensor->sd.dev);
> +       sensor->is_streaming = false;
>  error_unlock:
>         mutex_unlock(&sensor->input_lock);
>         return ret;
> @@ -644,8 +645,10 @@ static int ov2680_probe(struct i2c_client *client)
>         pm_runtime_use_autosuspend(dev);
>
>         ret = ov2680_s_config(&sensor->sd);
> -       if (ret)
> +       if (ret) {
> +               ov2680_remove(client);
>                 return ret;
> +       }
>
>         sensor->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
>         sensor->pad.flags = MEDIA_PAD_FL_SOURCE;
> --
> 2.39.1
>
diff mbox series

Patch

diff --git a/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c b/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c
index 3181276ed027..63de214916f5 100644
--- a/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c
+++ b/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c
@@ -419,7 +419,7 @@  static int ov2680_s_stream(struct v4l2_subdev *sd, int enable)
 	if (enable) {
 		ret = pm_runtime_get_sync(sensor->sd.dev);
 		if (ret < 0)
-			goto error_unlock;
+			goto error_power_down;
 
 		ret = ov2680_set_mode(sensor);
 		if (ret)
@@ -447,6 +447,7 @@  static int ov2680_s_stream(struct v4l2_subdev *sd, int enable)
 
 error_power_down:
 	pm_runtime_put(sensor->sd.dev);
+	sensor->is_streaming = false;
 error_unlock:
 	mutex_unlock(&sensor->input_lock);
 	return ret;
@@ -644,8 +645,10 @@  static int ov2680_probe(struct i2c_client *client)
 	pm_runtime_use_autosuspend(dev);
 
 	ret = ov2680_s_config(&sensor->sd);
-	if (ret)
+	if (ret) {
+		ov2680_remove(client);
 		return ret;
+	}
 
 	sensor->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
 	sensor->pad.flags = MEDIA_PAD_FL_SOURCE;