Skip to contentSkip to conversation

media: ti: vpe: fix double free after video device registration failure

PATCH In review Thomas Fourier 2 participants 2 messages Nov 3 – Nov 21

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: ti: vpe: fix double free after video device registration failure

vpe_fw_cb() is called asynchronously by vpe_probe().
If video_register_device() fails there, all the cleanup functions are called. The driver stays bound, so vpe_remove() later does all of this again, freeing dev->m2m_dev a second time.

Leave the cleanup to vpe_remove().

This bug was found statically and is theoretical.

Fixes b2c9472f0559 ("[media] v4l: ti-vpe: register video device only when firmware is loaded")
---
 drivers/media/platform/ti/vpe/vpe.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/media/platform/ti/vpe/vpe.c +0 -6
index 81bd1f9cee30..761aa40a066e 100644
@@ -2496,12 +2496,6 @@ static void vpe_fw_cb(struct platform_device *pdev)
 	if (ret) {
 		vpe_err(dev, "Failed to register video device\n");
 
-		vpe_set_clock_enable(dev, 0);
-		vpe_runtime_put(pdev);
-		pm_runtime_disable(&pdev->dev);
-		v4l2_m2m_release(dev->m2m_dev);
-		v4l2_device_unregister(&dev->v4l2_dev);
-
 		return;
 	}
 
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

Hi Thomas,
Thanks for the patch.

Quoted 27 lines · Thomas Fourier

vpe_fw_cb() is called asynchronously by vpe_probe().
If video_register_device() fails there, all the cleanup functions are called. The driver stays bound, so vpe_remove() later does all of this
again, freeing dev->m2m_dev a second time.

Leave the cleanup to vpe_remove().

This bug was found statically and is theoretical.

Fixes b2c9472f0559 ("[media] v4l: ti-vpe: register video device only

when firmware is loaded")
---
 drivers/media/platform/ti/vpe/vpe.c | 6 ------

 1 file changed, 6 deletions(-)
drivers/media/platform/ti/vpe/vpe.c +0 -0
index 81bd1f9cee30..761aa40a066e 100644
@@ -2496,12 +2496,6 @@ static void vpe_fw_cb(struct platform_device
 *pdev)
         if (ret) {
                 vpe_err(dev, "Failed to register video device\n");

Quoted 9 lines

-               vpe_set_clock_enable(dev, 0); -               vpe_runtime_put(pdev);
-               pm_runtime_disable(&pdev->dev); -               v4l2_m2m_release(dev->m2m_dev); -               v4l2_device_unregister(&dev->v4l2_dev); -
                return;
        }

I analysed the driver, and the fix seems correct. Hence,

Thanks and Regards,
Yemike Abhilash Chandra