[PATCH] usb: dwc2: Fix memory leak in probe error path

Jules Maselbas jmaselbas at kalray.eu
Fri Mar 3 05:43:21 PST 2023


The dwc2 driver private structure wasn't freed in the error path.

Signed-off-by: Jules Maselbas <jmaselbas at kalray.eu>
---
 drivers/usb/dwc2/dwc2.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/dwc2/dwc2.c b/drivers/usb/dwc2/dwc2.c
index ef957534c9..ff4842ce62 100644
--- a/drivers/usb/dwc2/dwc2.c
+++ b/drivers/usb/dwc2/dwc2.c
@@ -92,11 +92,10 @@ static int dwc2_probe(struct device *dev)
 	set_params_cb set_params;
 	int ret;
 
-	dwc2 = xzalloc(sizeof(*dwc2));
-
 	iores = dev_request_mem_resource(dev, 0);
 	if (IS_ERR(iores))
 		return PTR_ERR(iores);
+	dwc2 = xzalloc(sizeof(*dwc2));
 	dwc2->regs = IOMEM(iores->start);
 	dwc2->dev = dev;
 
@@ -177,6 +176,8 @@ clk_put:
 release_region:
 	release_region(iores);
 
+	free(dwc2);
+
 	return ret;
 }
 
-- 
2.17.1




More information about the barebox mailing list