Skip to contentSkip to conversation

usb: dwc3: imx8mp: fix memory leak on probe failure path

PATCH In review Xiaolei Wang 2 participants 2 messages Apr 1

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

PATCH 1/1 usb: dwc3: imx8mp: fix memory leak on probe failure path

When platform_get_drvdata() returns NULL and probe defers, the error path jumps to the 'depopulate' label, skipping put_device() for the reference acquired by of_find_device_by_node(). This extra reference prevents the child platform device from being freed when of_platform_depopulate() is called, resulting in memory leaks reported by kmemleak:

unreferenced object 0xffff0000c92c1480 (size 64):

    comm "kworker/u16:2", pid 50, jiffies 4294895789
    backtrace (crc 49d507d0):
      kmemleak_alloc+0x34/0x40
      __kmalloc_noprof+0x430/0x670
      of_device_alloc+0xec/0x26c
      of_platform_device_create_pdata+0x60/0x1f0
      of_platform_bus_create+0x290/0x610
      of_platform_populate+0x74/0x118
      dwc3_imx8mp_probe+0x228/0x734
Fixes 86767625f525 ("usb: dwc3: imx8mp: disable auto suspend for host role")
---
 drivers/usb/dwc3/dwc3-imx8mp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/dwc3/dwc3-imx8mp.c +1 -1
index b3d7252bd910..1cf96540b66e 100644
@@ -263,7 +263,7 @@ static int dwc3_imx8mp_probe(struct platform_device *pdev)
 	dwc3 = platform_get_drvdata(dwc3_imx->dwc3_pdev);
 	if (!dwc3) {
 		err = dev_err_probe(dev, -EPROBE_DEFER, "failed to get dwc3 platform data\n");
-		goto depopulate;
+		goto put_dwc3;
 	}
 
 	dwc3->glue_ops = &dwc3_imx_glue_ops;
Signature · 1 line
2.43.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 40 lines · Xiaolei Wang

When platform_get_drvdata() returns NULL and probe defers, the error path jumps to the 'depopulate' label, skipping put_device() for the reference acquired by of_find_device_by_node(). This extra reference prevents the child platform device from being freed when of_platform_depopulate() is called, resulting in memory leaks reported by kmemleak:

unreferenced object 0xffff0000c92c1480 (size 64):

    comm "kworker/u16:2", pid 50, jiffies 4294895789
    backtrace (crc 49d507d0):
      kmemleak_alloc+0x34/0x40
      __kmalloc_noprof+0x430/0x670
      of_device_alloc+0xec/0x26c
      of_platform_device_create_pdata+0x60/0x1f0
      of_platform_bus_create+0x290/0x610
      of_platform_populate+0x74/0x118
      dwc3_imx8mp_probe+0x228/0x734
Fixes 86767625f525 ("usb: dwc3: imx8mp: disable auto suspend for host role")
---
 drivers/usb/dwc3/dwc3-imx8mp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/dwc3/dwc3-imx8mp.c +1 -1
index b3d7252bd910..1cf96540b66e 100644
@@ -263,7 +263,7 @@ static int dwc3_imx8mp_probe(struct platform_device *pdev)
 	dwc3 = platform_get_drvdata(dwc3_imx->dwc3_pdev);
 	if (!dwc3) {
 		err = dev_err_probe(dev, -EPROBE_DEFER, "failed to get dwc3 platform data\n");
-		goto depopulate;
+		goto put_dwc3;
 	}
 
 	dwc3->glue_ops = &dwc3_imx_glue_ops;
Signature · 1 line
2.43.0

Thanks for the catch.

Thanks,
Thinh