[PATCH] media: visl: fix reference leak on failed device registration

From: Guangshuo Li

Date: Wed Apr 15 2026 - 12:11:58 EST


When platform_device_register() fails in visl_init(), the embedded
struct device in visl_pdev has already been initialized by
device_initialize(), but the failure path returns the error without
dropping the device reference for the current platform device:

visl_init()
-> platform_device_register(&visl_pdev)
-> device_initialize(&visl_pdev.dev)
-> setup_pdev_dma_masks(&visl_pdev)
-> platform_device_add(&visl_pdev)

This leads to a reference leak when platform_device_register() fails.
Fix this by calling platform_device_put() before returning the error.

The issue was identified by a static analysis tool I developed and
confirmed by manual review.

Fixes: 0c078e310b6d1 ("media: visl: add virtual stateless decoder driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
---
drivers/media/test-drivers/visl/visl-core.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/media/test-drivers/visl/visl-core.c b/drivers/media/test-drivers/visl/visl-core.c
index 127ab18bce99..15e4f05d5ec9 100644
--- a/drivers/media/test-drivers/visl/visl-core.c
+++ b/drivers/media/test-drivers/visl/visl-core.c
@@ -558,8 +558,11 @@ static int __init visl_init(void)
int ret;

ret = platform_device_register(&visl_pdev);
- if (ret)
+ if (ret) {
+ platform_device_put(&visl_pdev);
return ret;
+ }
+

ret = platform_driver_register(&visl_pdrv);
if (ret)
--
2.43.0