All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tobias Jordan <kernel@cdqe.de>
To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Nuno Sá" <nuno.sa@analog.com>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Peter Meerwald-Stadler" <pmeerw@pmeerw.net>
Subject: [PATCH] iio: temperature: ltc2983: fix leak of device node iterator
Date: Sat, 26 Sep 2020 12:45:54 +0200	[thread overview]
Message-ID: <20200926104554.GA14752@agrajag.zerfleddert.de> (raw)

Add missing of_node_put calls for the error paths of the
for_each_available_child_of_node loop in ltc2983_parse_dt.

Thought about adding an "goto err_of_node_put" instead, but as the error
paths are quite divergent, I'm not sure if that wouldn't complicate
things.

Fixes: f110f3188e56 ("iio: temperature: Add support for LTC2983")
Signed-off-by: Tobias Jordan <kernel@cdqe.de>
---
 drivers/iio/temperature/ltc2983.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/iio/temperature/ltc2983.c b/drivers/iio/temperature/ltc2983.c
index 55ff28a0f1c7..438e0ee29025 100644
--- a/drivers/iio/temperature/ltc2983.c
+++ b/drivers/iio/temperature/ltc2983.c
@@ -1285,6 +1285,7 @@ static int ltc2983_parse_dt(struct ltc2983_data *st)
 		ret = of_property_read_u32(child, "reg", &sensor.chan);
 		if (ret) {
 			dev_err(dev, "reg property must given for child nodes\n");
+			of_node_put(child);
 			return ret;
 		}
 
@@ -1293,9 +1294,11 @@ static int ltc2983_parse_dt(struct ltc2983_data *st)
 		    sensor.chan > LTC2983_MAX_CHANNELS_NR) {
 			dev_err(dev,
 				"chan:%d must be from 1 to 20\n", sensor.chan);
+			of_node_put(child);
 			return -EINVAL;
 		} else if (channel_avail_mask & BIT(sensor.chan)) {
 			dev_err(dev, "chan:%d already in use\n", sensor.chan);
+			of_node_put(child);
 			return -EINVAL;
 		}
 
@@ -1304,6 +1307,7 @@ static int ltc2983_parse_dt(struct ltc2983_data *st)
 		if (ret) {
 			dev_err(dev,
 				"adi,sensor-type property must given for child nodes\n");
+			of_node_put(child);
 			return ret;
 		}
 
@@ -1334,12 +1338,14 @@ static int ltc2983_parse_dt(struct ltc2983_data *st)
 			st->sensors[chan] = ltc2983_adc_new(child, st, &sensor);
 		} else {
 			dev_err(dev, "Unknown sensor type %d\n", sensor.type);
+			of_node_put(child);
 			return -EINVAL;
 		}
 
 		if (IS_ERR(st->sensors[chan])) {
 			dev_err(dev, "Failed to create sensor %ld",
 				PTR_ERR(st->sensors[chan]));
+			of_node_put(child);
 			return PTR_ERR(st->sensors[chan]);
 		}
 		/* set generic sensor parameters */
-- 
2.20.1


             reply	other threads:[~2020-09-26 10:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-26 10:45 Tobias Jordan [this message]
2020-09-26 14:44 ` [PATCH] iio: temperature: ltc2983: fix leak of device node iterator Jonathan Cameron
     [not found] <b5eca237-b7ea-e4ca-3936-8c32892e49b5@web.de>
2020-09-26 14:55 ` Jonathan Cameron
2020-09-26 14:55   ` Jonathan Cameron

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=20200926104554.GA14752@agrajag.zerfleddert.de \
    --to=kernel@cdqe.de \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=pmeerw@pmeerw.net \
    /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.