linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: dwc3: qcom: Add of_node_put() before return in register function
@ 2019-08-19  7:25 Nishka Dasgupta
  0 siblings, 0 replies; only message in thread
From: Nishka Dasgupta @ 2019-08-19  7:25 UTC (permalink / raw)
  To: agross, balbi, gregkh, linux-arm-kernel, linux-usb; +Cc: Nishka Dasgupta

The variable dwc3_np in the function dwc3_qcom_of_register_core takes the
value returned by of_get_child_by_name, which gets a node but does not
put it. This may cause a memory leak. Hence create a new label,
err_node_put, that puts dwc3_np and returns the required value, and
modify two return statements to instead save the required return value
in existing variable ret and then point to this label.
Issue found with Coccinelle.

Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
---
 drivers/usb/dwc3/dwc3-qcom.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index 261af9e38ddd..227f4fee184a 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -528,16 +528,19 @@ static int dwc3_qcom_of_register_core(struct platform_device *pdev)
 	ret = of_platform_populate(np, NULL, NULL, dev);
 	if (ret) {
 		dev_err(dev, "failed to register dwc3 core - %d\n", ret);
-		return ret;
+		goto err_node_put;
 	}
 
 	qcom->dwc3 = of_find_device_by_node(dwc3_np);
 	if (!qcom->dwc3) {
 		dev_err(dev, "failed to get dwc3 platform device\n");
-		return -ENODEV;
+		ret = -ENODEV;
+		goto err_node_put;
 	}
 
-	return 0;
+err_node_put:
+	of_node_put(dwc3_np);
+	return ret;
 }
 
 static const struct dwc3_acpi_pdata sdm845_acpi_pdata = {
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-08-19  7:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-19  7:25 [PATCH] usb: dwc3: qcom: Add of_node_put() before return in register function Nishka Dasgupta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).