]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: ov2659: Fix memory leaks in ov2659_probe()
authorZhang Shurong <zhang_shurong@foxmail.com>
Sat, 5 Jul 2025 16:31:09 +0000 (00:31 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Aug 2025 14:21:32 +0000 (16:21 +0200)
commit 76142b137b968d47b35cdd8d1dc924677d319c8b upstream.

ov2659_probe() doesn't properly free control handler resources in failure
paths, causing memory leaks. Add v4l2_ctrl_handler_free() to prevent these
memory leaks and reorder the ctrl_handler assignment for better code flow.

Fixes: c4c0283ab3cd ("[media] media: i2c: add support for omnivision's ov2659 sensor")
Cc: stable@vger.kernel.org
Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/media/i2c/ov2659.c

index e1ff38009cf07cb129d87c910e4a36a6d7c22531..2d1f132a4a87a7708fe598e694a7ec6bab2527e8 100644 (file)
@@ -1432,14 +1432,15 @@ static int ov2659_probe(struct i2c_client *client)
                                     V4L2_CID_TEST_PATTERN,
                                     ARRAY_SIZE(ov2659_test_pattern_menu) - 1,
                                     0, 0, ov2659_test_pattern_menu);
-       ov2659->sd.ctrl_handler = &ov2659->ctrls;
 
        if (ov2659->ctrls.error) {
                dev_err(&client->dev, "%s: control initialization error %d\n",
                        __func__, ov2659->ctrls.error);
+               v4l2_ctrl_handler_free(&ov2659->ctrls);
                return  ov2659->ctrls.error;
        }
 
+       ov2659->sd.ctrl_handler = &ov2659->ctrls;
        sd = &ov2659->sd;
        client->flags |= I2C_CLIENT_SCCB;
 #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API