diff mbox series

[v4,16/16] media: i2c: ov8865: Fix lockdep error

Message ID 20211101001119.46056-17-djrscally@gmail.com (mailing list archive)
State New, archived
Headers show
Series Extensions to ov8865 driver | expand

Commit Message

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

ov8865_state_init() calls ov8865_state_mipi_configure() which uses
__v4l2_ctrl_s_ctrl[_int64](). This means that sensor->mutex (which
is also sensor->ctrls.handler.lock) must be locked before calling
ov8865_state_init().

Note ov8865_state_mipi_configure() is also used in other places where
the lock is already held so it cannot be changed itself.

This fixes the following lockdep kernel WARN:

[   13.233413] ------------[ cut here ]------------
[   13.233421] WARNING: CPU: 0 PID: 8 at drivers/media/v4l2-core/v4l2-ctrls-api.c:833 __v4l2_ctrl_s_ctrl+0x4d/0x60 [videodev]
...
[   13.234063] Call Trace:
[   13.234074]  ov8865_state_configure+0x98b/0xc00 [ov8865]
[   13.234095]  ov8865_probe+0x4b1/0x54c [ov8865]
[   13.234117]  i2c_device_probe+0x13c/0x2d0

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

Comments

Andy Shevchenko Nov. 1, 2021, 11:31 a.m. UTC | #1
On Mon, Nov 01, 2021 at 12:11:19AM +0000, Daniel Scally wrote:
> From: Hans de Goede <hdegoede@redhat.com>
> 
> ov8865_state_init() calls ov8865_state_mipi_configure() which uses
> __v4l2_ctrl_s_ctrl[_int64](). This means that sensor->mutex (which
> is also sensor->ctrls.handler.lock) must be locked before calling
> ov8865_state_init().
> 
> Note ov8865_state_mipi_configure() is also used in other places where
> the lock is already held so it cannot be changed itself.
> 
> This fixes the following lockdep kernel WARN:

> [   13.233413] ------------[ cut here ]------------

You may drop this noisy line.

> [   13.233421] WARNING: CPU: 0 PID: 8 at drivers/media/v4l2-core/v4l2-ctrls-api.c:833 __v4l2_ctrl_s_ctrl+0x4d/0x60 [videodev]
> ...
> [   13.234063] Call Trace:
> [   13.234074]  ov8865_state_configure+0x98b/0xc00 [ov8865]
> [   13.234095]  ov8865_probe+0x4b1/0x54c [ov8865]
> [   13.234117]  i2c_device_probe+0x13c/0x2d0

Seems to me that this should be moved to the head of the series with Fixes tag
added.
diff mbox series

Patch

diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
index ab225fb616b9..c5fe290317e8 100644
--- a/drivers/media/i2c/ov8865.c
+++ b/drivers/media/i2c/ov8865.c
@@ -3073,7 +3073,9 @@  static int ov8865_probe(struct i2c_client *client)
 	if (ret)
 		goto error_mutex;
 
+	mutex_lock(&sensor->mutex);
 	ret = ov8865_state_init(sensor);
+	mutex_unlock(&sensor->mutex);
 	if (ret)
 		goto error_ctrls;