Re: [PATCH] media: ov5640: Initialize mutex before probe cleanup

From: Frank Li

Date: Fri Sep 11 2026 - 16:08:16 EST


On Thu, Sep 10, 2026 at 04:16:08PM +0800, Runyu Xiao wrote:
> 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);
> +

Please use devm_mutex_init(); mutex need do tear down work if enable lock
debug.

Frank

> 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
>