[PATCH] usb-serial: fix port device refcount leak when device_add() fails
From: Guangshuo Li
Date: Sun Apr 12 2026 - 12:55:07 EST
usb_serial_probe() initializes each port device with
device_initialize() before registering it with device_add().
If device_add() fails, the current code only logs an error and
continues, but does not drop the reference acquired by
device_initialize(). This leaves the failed port device referenced
until a later teardown path, if any.
Fix it by calling put_device() when device_add() fails. Also clear
serial->port[i] after put_device() so destroy_serial() will not try
to put the same device again.
Fixes: 41bd34ddd7aa ("usb-serial: change referencing of port and serial structures")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
---
drivers/usb/serial/usb-serial.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index c78ff40b1e5f..78e3eaf2874b 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -1148,8 +1148,11 @@ static int usb_serial_probe(struct usb_interface *interface,
device_enable_async_suspend(&port->dev);
retval = device_add(&port->dev);
- if (retval)
+ if (retval) {
dev_err(ddev, "Error registering port device, continuing\n");
+ put_device(&port->dev);
+ serial->port[i] = NULL;
+ }
}
if (num_ports > 0)
--
2.43.0