[PATCH] media: rockchip: rga: avoid double free on video register failure
Guangshuo Li
lgs201920130244 at gmail.com
Sun May 17 04:34:49 PDT 2026
rga_probe() allocates a video_device with video_device_alloc() and
releases it from the rel_vdev error path if video_register_device()
fails.
This can double free the video_device when __video_register_device()
reaches device_register() and that call fails:
video_register_device()
-> __video_register_device()
-> device_register() fails
-> put_device(&vdev->dev)
-> v4l2_device_release()
-> vdev->release(vdev)
-> video_device_release(vdev)
rga_probe()
-> rel_vdev
-> video_device_release(vfd)
Use video_device_release_empty() while registering the device so that
registration failure paths do not free vfd through vdev->release().
rga_probe() then releases vfd exactly once from rel_vdev. Restore
video_device_release() after successful registration so the registered
device keeps its normal lifetime handling.
This issue was found by a static analysis tool I am developing.
Fixes: f7e7b48e6d79 ("[media] rockchip/rga: v4l2 m2m support")
Signed-off-by: Guangshuo Li <lgs201920130244 at gmail.com>
---
drivers/media/platform/rockchip/rga/rga.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/platform/rockchip/rga/rga.c
index fea63b94c5f3..90ae01de3216 100644
--- a/drivers/media/platform/rockchip/rga/rga.c
+++ b/drivers/media/platform/rockchip/rga/rga.c
@@ -851,6 +851,7 @@ static int rga_probe(struct platform_device *pdev)
goto unreg_v4l2_dev;
}
*vfd = rga_videodev;
+ vfd->release = video_device_release_empty;
vfd->lock = &rga->mutex;
vfd->v4l2_dev = &rga->v4l2_dev;
@@ -895,6 +896,8 @@ static int rga_probe(struct platform_device *pdev)
goto free_dma;
}
+ vfd->release = video_device_release;
+
v4l2_info(&rga->v4l2_dev, "Registered %s as /dev/%s\n",
vfd->name, video_device_node_name(vfd));
--
2.43.0
More information about the Linux-rockchip
mailing list