Skip to content

Commit e36721b

Browse files
gaurijhangianiFelipe Balbi
authored and
Felipe Balbi
committed
usb: dwc3: st: Add of_node_put() before return in probe function
The local variable child in the function st_dwc3_probe takes the return value of of_get_child_by_name, which gets a node and does not put it. If the function returns without releasing child, this could cause a memory error. Hence put child as soon as there is no more use for it. Also create a new label, err_node_put, just before label undo_softreset; so that err_node_put puts child. In between initialisation of child and its first put, modify all statements that go to undo_softreset to now go to err_node_put instead, from where they can fall through to undo_softreset. Issue found with Coccinelle. Reviewed-by: Patrice Chotard <[email protected]> Signed-off-by: Nishka Dasgupta <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
1 parent c09b73c commit e36721b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/usb/dwc3/dwc3-st.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,24 +255,25 @@ static int st_dwc3_probe(struct platform_device *pdev)
255255
if (!child) {
256256
dev_err(&pdev->dev, "failed to find dwc3 core node\n");
257257
ret = -ENODEV;
258-
goto undo_softreset;
258+
goto err_node_put;
259259
}
260260

261261
/* Allocate and initialize the core */
262262
ret = of_platform_populate(node, NULL, NULL, dev);
263263
if (ret) {
264264
dev_err(dev, "failed to add dwc3 core\n");
265-
goto undo_softreset;
265+
goto err_node_put;
266266
}
267267

268268
child_pdev = of_find_device_by_node(child);
269269
if (!child_pdev) {
270270
dev_err(dev, "failed to find dwc3 core device\n");
271271
ret = -ENODEV;
272-
goto undo_softreset;
272+
goto err_node_put;
273273
}
274274

275275
dwc3_data->dr_mode = usb_get_dr_mode(&child_pdev->dev);
276+
of_node_put(child);
276277

277278
/*
278279
* Configure the USB port as device or host according to the static
@@ -292,6 +293,8 @@ static int st_dwc3_probe(struct platform_device *pdev)
292293
platform_set_drvdata(pdev, dwc3_data);
293294
return 0;
294295

296+
err_node_put:
297+
of_node_put(child);
295298
undo_softreset:
296299
reset_control_assert(dwc3_data->rstc_rst);
297300
undo_powerdown:

0 commit comments

Comments
 (0)