[PATCH] media: tw686x: Fix potential use-after-free on video registration failure

From: Guangshuo Li

Date: Thu Nov 12 2026 - 09:18:06 EST


Failed video registration releases vdev but leaves it in vc->device.
The common cleanup then passes the freed object to
video_unregister_device().

Clear the channel slot after releasing the unregistered device.

This issue was found by our static analysis tool under development.

Fixes: e0b212ec9d81 ("media: tw686x: Fix memory leak in tw686x_video_init")
Signed-off-by: Guangshuo Li <liguangshuo@xxxxxxxxxxxxxxx>
---
drivers/media/pci/tw686x/tw686x-video.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/media/pci/tw686x/tw686x-video.c b/drivers/media/pci/tw686x/tw686x-video.c
index 785dd797d921..3ffbf462d353 100644
--- a/drivers/media/pci/tw686x/tw686x-video.c
+++ b/drivers/media/pci/tw686x/tw686x-video.c
@@ -1281,6 +1281,7 @@ int tw686x_video_init(struct tw686x_dev *dev)
err = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
if (err < 0) {
video_device_release(vdev);
+ vc->device = NULL;
goto error;
}
vc->num = vdev->num;

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4