[PATCH] media: ov5640: Initialize mutex before probe cleanup
From: Runyu Xiao
Date: Thu Sep 10 2026 - 04:38:25 EST
ov5640_probe() can jump to entity_cleanup when regulator setup fails,
before sensor->lock is initialized. The cleanup path unconditionally
destroys the mutex, so this error path passes an uninitialized mutex to
mutex_destroy().
Initialize the mutex after media_entity_pads_init() succeeds and before
ov5640_get_regulators(). This keeps earlier direct-return paths outside the
mutex lifetime while ensuring that every path reaching mutex_destroy() has
initialized the mutex.
Fixes: 19a81c1426c1 ("[media] add Omnivision OV5640 sensor driver")
Cc: stable@xxxxxxxxxxxxxxx
Found by PatchProof Module 4 candidates
PILOT-4c6b03072e508260 and PILOT-4f9a36d855eb7c54.
No runtime reproducer was available; the failure path was verified by
inspection and the affected object was built successfully.
Tested-by: Runyu Xiao <runyu.xiao@xxxxxxxxxx>
Assisted-by: LLM Codex
Signed-off-by: Runyu Xiao <runyu.xiao@xxxxxxxxxx>
---
drivers/media/i2c/ov5640.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
index 8deb5f550..36c8bb345 100644
--- a/drivers/media/i2c/ov5640.c
+++ b/drivers/media/i2c/ov5640.c
@@ -3930,12 +3930,12 @@ static int ov5640_probe(struct i2c_client *client)
if (ret)
return ret;
+ mutex_init(&sensor->lock);
+
ret = ov5640_get_regulators(sensor);
if (ret)
goto entity_cleanup;
- mutex_init(&sensor->lock);
-
ret = ov5640_init_controls(sensor);
if (ret)
goto entity_cleanup;
--
2.34.1