All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nishka Dasgupta <nishkadg.linux@gmail.com>
To: lgirdwood@gmail.com, broonie@kernel.org, linux-kernel@vger.kernel.org
Cc: Nishka Dasgupta <nishkadg.linux@gmail.com>
Subject: [PATCH v2] regulator: core: Add of_node_put() before return
Date: Thu,  8 Aug 2019 12:35:53 +0530	[thread overview]
Message-ID: <20190808070553.13097-1-nishkadg.linux@gmail.com> (raw)

In function of_get_child_regulator(), the loop for_each_child_of_node()
contains two mid-loop return statements. Ordinarily the loop gets the
node child at the beginning of every iteration and automatically puts
child after the main body has been executed. However in the case of a
mid-loop return child is not put, which may cause a memory leak.
Hence create a new label, err_node_put, that puts child and then returns
the required value; edit the mid-loop return statements to instead go to
this new label.
Issue found with Coccinelle.

Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
---
Changes in v2:
- Create a new label to put the node and return regnode.

 drivers/regulator/core.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index e0c0cf462004..4a27a46ec6e7 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -381,12 +381,16 @@ static struct device_node *of_get_child_regulator(struct device_node *parent,
 		if (!regnode) {
 			regnode = of_get_child_regulator(child, prop_name);
 			if (regnode)
-				return regnode;
+				goto err_node_put;
 		} else {
-			return regnode;
+			goto err_node_put;
 		}
 	}
 	return NULL;
+
+err_node_put:
+	of_node_put(child);
+	return regnode;
 }
 
 /**
-- 
2.19.1


             reply	other threads:[~2019-08-08  7:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-08  7:05 Nishka Dasgupta [this message]
2019-08-08 12:27 ` [PATCH v2] regulator: core: Add of_node_put() before return Mark Brown
2019-08-13  4:27   ` Nishka Dasgupta
2019-08-13 11:21     ` Mark Brown
2019-08-15  5:37       ` [PATCH v2] regulator: core: Add label to collate of_node_put() statements Nishka Dasgupta
2019-08-15 17:14         ` Applied "regulator: core: Add label to collate of_node_put() statements" to the regulator tree Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190808070553.13097-1-nishkadg.linux@gmail.com \
    --to=nishkadg.linux@gmail.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.