Skip to contentSkip to conversation

media: davinci: vpif: Fix memory leak in probe error path

PATCH In review Dmitry Nikiforov 2 participants 2 messages Apr 16, 2025 – Apr 17, 2025

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

PATCH v3 1/1 media: davinci: vpif: Fix memory leak in probe error path

If an error occurs during the initialization of pdev_display, the allocated platform device pdev_capture is not released properly, leading to a memory leak.

Adjust error path handling to fix the leak.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes 43acb728bbc4 ("media: davinci: vpif: fix use-after-free on driver unbind")

---
v2: also fix of_graph_get_endpoint_by_regs() error path.
v3: Rework incorrect error handling added in v2.
Also fix missing platform_device_del() in another error path (Johan Hovold).

 drivers/media/platform/ti/davinci/vpif.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/platform/ti/davinci/vpif.c +3 -1
index a81719702a22..969d623fc842 100644
@@ -504,7 +504,7 @@ static int vpif_probe(struct platform_device *pdev)
 	pdev_display = kzalloc(sizeof(*pdev_display), GFP_KERNEL);
 	if (!pdev_display) {
 		ret = -ENOMEM;
-		goto err_put_pdev_capture;
+		goto err_del_pdev_capture;
 	}
 
 	pdev_display->name = "vpif_display";
@@ -527,6 +527,8 @@ static int vpif_probe(struct platform_device *pdev)
 
 err_put_pdev_display:
 	platform_device_put(pdev_display);
+err_del_pdev_capture:
+	platform_device_del(pdev_capture);
 err_put_pdev_capture:
 	platform_device_put(pdev_capture);
 err_put_rpm:
Signature · 1 line
2.49.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 6 lines · Dmitry Nikiforov

If an error occurs during the initialization of pdev_display, the allocated platform device pdev_capture is not released properly, leading to a memory leak.

Adjust error path handling to fix the leak.

Quoted 8 lines

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes 43acb728bbc4 ("media: davinci: vpif: fix use-after-free on driver unbind")

---
v2: also fix of_graph_get_endpoint_by_regs() error path.
v3: Rework incorrect error handling added in v2.
Also fix missing platform_device_del() in another error path (Johan Hovold).

Thanks for the update. Looks good: