Linux-USB Archive on
 help / color / 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 <>
 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;
+	of_node_put(dwc3_np);
+	return ret;
 static const struct dwc3_acpi_pdata sdm845_acpi_pdata = {

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

only message in thread, back to index

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

Linux-USB Archive on

Archives are clonable:
	git clone --mirror linux-usb/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-usb linux-usb/ \
	public-inbox-index linux-usb

Newsgroup available over NNTP:

AGPL code for this site: git clone public-inbox