diff mbox series

xhci: dbc: Fix memory leak in xhci_alloc_dbc()

Message ID 20220914023609.695296-1-rafaelmendsr@gmail.com (mailing list archive)
State Accepted
Commit d591b32e519603524a35b172156db71df9116902
Headers show
Series xhci: dbc: Fix memory leak in xhci_alloc_dbc() | expand

Commit Message

Rafael Mendonca Sept. 14, 2022, 2:36 a.m. UTC
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()")
Signed-off-by: Rafael Mendonca <rafaelmendsr@gmail.com>
---
 drivers/usb/host/xhci-dbgcap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Mathias Nyman Sept. 14, 2022, 12:27 p.m. UTC | #1
On 14.9.2022 5.36, Rafael Mendonca wrote:
> 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()")
> Signed-off-by: Rafael Mendonca <rafaelmendsr@gmail.com>

Thanks, nice catch

Adding to queue

-Mathias
diff mbox series

Patch

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index e61155fa6379..f1367b53b260 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -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);