Skip to contentSkip to conversation

xhci: dbc: Fix memory leak in xhci_alloc_dbc()

PATCH In review Rafael Mendonca 2 participants 2 messages Sep 14, 2022

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

PATCH 1/1 xhci: dbc: Fix memory leak in xhci_alloc_dbc()

If DbC is already in use, then the allocated memory for the xhci_dbc struct doesn't get freed before returning NULL, which leads to a memleak.

Fixes 534675942e90 ("xhci: dbc: refactor xhci_dbc_init()")
---
 drivers/usb/host/xhci-dbgcap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/xhci-dbgcap.c +1 -1
index e61155fa6379..f1367b53b260 100644
@@ -988,7 +988,7 @@ xhci_alloc_dbc(struct device *dev, void __iomem *base, const struct dbc_driver *
 	dbc->driver = driver;
 
 	if (readl(&dbc->regs->control) & DBC_CTRL_DBC_ENABLE)
-		return NULL;
+		goto err;
 
 	INIT_DELAYED_WORK(&dbc->event_work, xhci_dbc_handle_events);
 	spin_lock_init(&dbc->lock);
Signature · 1 line
2.34.1
#1 lore raw
Quoted 5 lines · Rafael Mendonca

If DbC is already in use, then the allocated memory for the xhci_dbc struct doesn't get freed before returning NULL, which leads to a memleak.

Fixes 534675942e90 ("xhci: dbc: refactor xhci_dbc_init()")

Thanks, nice catch

Adding to queue

-Mathias