[PATCH] serial: 8250_hub6: fix reference leak on failed device registration

From: Guangshuo Li

Date: Wed Apr 15 2026 - 14:53:58 EST


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

hub6_init()
-> platform_device_register(&hub6_device)
-> device_initialize(&hub6_device.dev)
-> setup_pdev_dma_masks(&hub6_device)
-> platform_device_add(&hub6_device)

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: ec9f47cd6a14c ("[PATCH] Serial: Split 8250 port table")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
---
drivers/tty/serial/8250/8250_hub6.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_hub6.c b/drivers/tty/serial/8250/8250_hub6.c
index 273f59b9bca5..005dd6bec3da 100644
--- a/drivers/tty/serial/8250/8250_hub6.c
+++ b/drivers/tty/serial/8250/8250_hub6.c
@@ -43,9 +43,14 @@ static struct platform_device hub6_device = {

static int __init hub6_init(void)
{
- return platform_device_register(&hub6_device);
-}
+ int ret;
+
+ ret = platform_device_register(&hub6_device);
+ if (ret)
+ platform_device_put(&hub6_device);

+ return ret;
+}
module_init(hub6_init);

MODULE_AUTHOR("Russell King");
--
2.43.0