media: tw686x: Fix memory leak in tw686x_video_init
authorMiaoqian Lin <linmq006@gmail.com>
Tue, 21 Jun 2022 05:30:30 +0000 (06:30 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Aug 2022 12:23:24 +0000 (14:23 +0200)
[ Upstream commit e0b212ec9d8177d6f7c404315293f6a085d6ee42 ]

video_device_alloc() allocates memory for vdev,
when video_register_device() fails, it doesn't release the memory and
leads to memory leak, call video_device_release() to fix this.

Fixes: 704a84ccdbf1 ("[media] media: Support Intersil/Techwell TW686x-based video capture cards")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/media/pci/tw686x/tw686x-video.c

index b227e9e78ebd0970ad9b53ae8b83bb8054e210b3..37a20fe24241f5a7ef47a1b71be74ba908b777b0 100644 (file)
@@ -1282,8 +1282,10 @@ int tw686x_video_init(struct tw686x_dev *dev)
                video_set_drvdata(vdev, vc);
 
                err = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
-               if (err < 0)
+               if (err < 0) {
+                       video_device_release(vdev);
                        goto error;
+               }
                vc->num = vdev->num;
        }