[PATCH v2] media: davinci: vpif: Fix memory leaks in probe error path

From: Dmitry Nikiforov
Date: Tue Apr 15 2025 - 18:39:37 EST


If `of_graph_get_endpoint_by_regs()` fails, the probe function currently
returns 0, skipping cleanup.

Also, 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 leaks.

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

Fixes: 43acb728bbc4 ("media: davinci: vpif: fix use-after-free on driver unbind")
Signed-off-by: Dmitry Nikiforov <Dm1tryNk@xxxxxxxxx>
---
v2: also fix of_graph_get_endpoint_by_regs() error path (Johan Hovold).
drivers/media/platform/ti/davinci/vpif.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/ti/davinci/vpif.c b/drivers/media/platform/ti/davinci/vpif.c
index a81719702a22..4839e34e5d29 100644
--- a/drivers/media/platform/ti/davinci/vpif.c
+++ b/drivers/media/platform/ti/davinci/vpif.c
@@ -467,7 +467,8 @@ static int vpif_probe(struct platform_device *pdev)
*/
endpoint = of_graph_get_endpoint_by_regs(pdev->dev.of_node, 0, -1);
if (!endpoint)
- return 0;
+ ret = -ENODEV;
+ goto err_put_rpm;
of_node_put(endpoint);

/*
@@ -527,6 +528,7 @@ static int vpif_probe(struct platform_device *pdev)

err_put_pdev_display:
platform_device_put(pdev_display);
+ platform_device_del(pdev_capture);
err_put_pdev_capture:
platform_device_put(pdev_capture);
err_put_rpm:
--
2.49.0