diff mbox series

[v5,5/5] media: i2c: ov5693: Fix lockdep error

Message ID 20211101232144.134590-6-djrscally@gmail.com (mailing list archive)
State New, archived
Headers show
Series Add support for OV5693 sensor | expand

Commit Message

Daniel Scally Nov. 1, 2021, 11:21 p.m. UTC
From: Hans de Goede <hdegoede@redhat.com>

ov5693_s_stream() was calling __v4l2_ctrl_handler_setup() without first
locking ov5693->lock, triggering the "lockdep_assert_held(hdl->lock);"
check in __v4l2_ctrl_handler_setup() leading to a kernel backtrace.

ov5693_s_stream() does already take the ov5693->lock, move the
mutex_lock call up (in the enable path) so that it also protects the
__v4l2_ctrl_handler_setup() call.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/media/i2c/ov5693.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
index 2613bad49f78..e3cd7eeba9ed 100644
--- a/drivers/media/i2c/ov5693.c
+++ b/drivers/media/i2c/ov5693.c
@@ -1113,17 +1113,23 @@  static int ov5693_s_stream(struct v4l2_subdev *sd, int enable)
 		if (ret < 0)
 			goto err_power_down;
 
+		mutex_lock(&ov5693->lock);
 		ret = __v4l2_ctrl_handler_setup(&ov5693->ctrls.handler);
-		if (ret)
+		if (ret) {
+			mutex_unlock(&ov5693->lock);
 			goto err_power_down;
-	}
-
-	mutex_lock(&ov5693->lock);
-	ret = ov5693_enable_streaming(ov5693, enable);
-	mutex_unlock(&ov5693->lock);
+		}
 
+		ret = ov5693_enable_streaming(ov5693, true);
+		mutex_unlock(&ov5693->lock);
+	} else {
+		mutex_lock(&ov5693->lock);
+		ret = ov5693_enable_streaming(ov5693, false);
+		mutex_unlock(&ov5693->lock);
+	}
 	if (ret)
 		goto err_power_down;
+
 	ov5693->streaming = !!enable;
 
 	if (!enable)