From 5ec7749803e9f5c47188c5c8bdc883734f2c538d Mon Sep 17 00:00:00 2001 From: Yuriy Pasichnyk Date: Tue, 18 Feb 2025 16:20:31 +0200 Subject: [PATCH] media: i2c: arducam-pivariety: Fix mutex init and NULL pointer The mutex used in arducam-pivariety was not properly initialized, which could lead to undefined behavior. This also caused a NULL pointer dereference under certain conditions. This patch ensures the mutex is correctly initialized during probe and prevents NULL pointer dereferences. Signed-off-by: Yuriy Pasichnyk --- drivers/media/i2c/arducam-pivariety.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/media/i2c/arducam-pivariety.c +++ b/drivers/media/i2c/arducam-pivariety.c @@ -1208,6 +1208,8 @@ static int pivariety_enum_controls(struc if (ret) return ret; + mutex_init(&pivariety->mutex); + index = 0; while (1) { ret = pivariety_write(pivariety, CTRL_INDEX_REG, index); @@ -1295,6 +1297,7 @@ static int pivariety_enum_controls(struc v4l2_ctrl_handler_setup(ctrl_hdlr); return 0; err: + mutex_destroy(&pivariety->mutex); return -ENODEV; }