Skip to contentSkip to conversation

media: i2c: ov5648: Fix lockdep error

PATCH Superseded Hans de Goede 2 participants 3 messages Nov 25, 2021 – Nov 26, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: i2c: ov5648: Fix lockdep error

ov5648_state_init() calls ov5648_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 ov5648_state_init().

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

Note this is based on an identical (tested) fix for the ov8865 driver, this has only been compile-tested.

Cc Paul Kocialkowski <[email protected]>
---
 drivers/media/i2c/ov5648.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/i2c/ov5648.c +2 -0
index 947d437ed0ef..9f24bdccf50f 100644
@@ -2546,7 +2546,9 @@ static int ov5648_probe(struct i2c_client *client)
 	if (ret)
 		goto error_mutex;
 
+	mutex_lock(&sensor->mutex);
 	ret = ov5648_state_init(sensor);
+	mutex_unlock(&sensor->mutex);
 	if (ret)
 		goto error_ctrls;
 
Signature · 1 line
2.33.1
#1 lore raw

Hi Hans,

Quoted 10 lines · Hans de Goede

ov5648_state_init() calls ov5648_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 ov5648_state_init().

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

Note this is based on an identical (tested) fix for the ov8865 driver, this has only been compile-tested.

Good catch, thanks!

Though I think it would look slightly better to have the lock in the ov5648_state_init function itself rather than in the probe. I guess the same applies to the ov8865 fix, if it's not too late.

Cheers,

Paul

Quoted 23 lines
Cc Paul Kocialkowski <[email protected]>
---
 drivers/media/i2c/ov5648.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/i2c/ov5648.c +2 -0
index 947d437ed0ef..9f24bdccf50f 100644
@@ -2546,7 +2546,9 @@ static int ov5648_probe(struct i2c_client *client)
 	if (ret)
 		goto error_mutex;
 
+	mutex_lock(&sensor->mutex);
 	ret = ov5648_state_init(sensor);
+	mutex_unlock(&sensor->mutex);
 	if (ret)
 		goto error_ctrls;
 
Signature · 1 line
2.33.1
Signature · 3 lines
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
#2 lore raw

Hi,

Quoted 11 lines · Paul Kocialkowski

Hi Hans,

Quoted 8 lines · Hans de Goede

ov5648_state_init() calls ov5648_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 ov5648_state_init().

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

Quoted 7 lines
Quoted 2 lines

Note this is based on an identical (tested) fix for the ov8865 driver, this has only been compile-tested.

Good catch, thanks!

Though I think it would look slightly better to have the lock in the ov5648_state_init function itself rather than in the probe.

Ack, that makes sense. I will send a v2 with this change.

Regards,

Hans

Quoted 24 lines
Quoted 23 lines
Cc Paul Kocialkowski <[email protected]>
---
 drivers/media/i2c/ov5648.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/i2c/ov5648.c +2 -0
index 947d437ed0ef..9f24bdccf50f 100644
@@ -2546,7 +2546,9 @@ static int ov5648_probe(struct i2c_client *client)
 	if (ret)
 		goto error_mutex;
 
+	mutex_lock(&sensor->mutex);
 	ret = ov5648_state_init(sensor);
+	mutex_unlock(&sensor->mutex);
 	if (ret)
 		goto error_ctrls;
 
Signature · 1 line
2.33.1