[PATCH] media: mx2-emmaprp: avoid double free on video register failure

From: Guangshuo Li

Date: Sun May 17 2026 - 07:50:46 EST


emmaprp_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)

emmaprp_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().
emmaprp_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: 8091cb7d9ce6 ("[media] MEM2MEM: Add support for eMMa-PrP mem2mem operations")
Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
---
drivers/media/platform/nxp/mx2_emmaprp.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/media/platform/nxp/mx2_emmaprp.c b/drivers/media/platform/nxp/mx2_emmaprp.c
index d51a62100778..a27809b7730e 100644
--- a/drivers/media/platform/nxp/mx2_emmaprp.c
+++ b/drivers/media/platform/nxp/mx2_emmaprp.c
@@ -834,6 +834,7 @@ static int emmaprp_probe(struct platform_device *pdev)
}

*vfd = emmaprp_videodev;
+ vfd->release = video_device_release_empty;
vfd->lock = &pcdev->dev_mutex;
vfd->v4l2_dev = &pcdev->v4l2_dev;

@@ -867,6 +868,7 @@ static int emmaprp_probe(struct platform_device *pdev)
v4l2_err(&pcdev->v4l2_dev, "Failed to register video device\n");
goto rel_m2m;
}
+ vfd->release = video_device_release;

return 0;

--
2.43.0