Re: [PATCH] media: qcom: iris: avoid double free on video register failure

From: Dmitry Baryshkov

Date: Mon May 18 2026 - 13:13:19 EST


On Mon, May 18, 2026 at 06:57:55PM +0800, Guangshuo Li wrote:
> iris_register_video_device() allocates a video_device with
> video_device_alloc() and releases it from the err_vdev_release 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)
>
> iris_register_video_device()
> -> err_vdev_release
> -> video_device_release(vdev)
>
> Use video_device_release_empty() while registering the device so that
> registration failure paths do not free vdev through vdev->release().
> iris_register_video_device() then releases vdev exactly once from
> err_vdev_release. Restore video_device_release() after successful
> registration so the registered device keeps its normal lifetime handling.

This is definitely not the correct way to handle the issue. Fix the
error path instead.

>
> Clear the cached decoder or encoder video_device pointer on failure since
> it is assigned before video_register_device().
>
> This issue was found by a static analysis tool I am developing.
>
> Fixes: 38506cb7e8d2 ("media: iris: add platform driver for iris video device")
> Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
> ---
> drivers/media/platform/qcom/iris/iris_probe.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>

--
With best wishes
Dmitry