* Re: [PATCH] iio: temperature: ltc2983: fix leak of device node iterator
[not found] <b5eca237-b7ea-e4ca-3936-8c32892e49b5@web.de>
@ 2020-09-26 14:55 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2020-09-26 14:55 UTC (permalink / raw)
To: Markus Elfring
Cc: Tobias Jordan, linux-iio, linux-kernel, kernel-janitors,
Lars-Peter Clausen, Nuno Sa, Peter Meerwald-Stadler
On Sat, 26 Sep 2020 16:45:56 +0200
Markus Elfring <Markus.Elfring@web.de> wrote:
> > 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.
>
> Please add jump targets like “e_inval” and “put_node” so that a bit of
> common exception handling code can be better reused for this function implementation.
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?id=7c7ec3226f5f33f9c050d85ec20f18419c622ad6#n475
On this one I think readability would perhaps be hurt a little by
doing so, particular as we need to do the of_put_node in some but
not all non error paths.
It is a close run thing between the two options however.
I considered another option of suggesting factoring out this whole
per node block, but to do that we would have to do something a bit
odd with the return value as we have 3 options.
* error
* do not parse any more children.
* continue to parse children.
So I think in this case Tobias' solution is the best one available.
Thanks,
Jonathan
>
> Regards,
> Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: temperature: ltc2983: fix leak of device node iterator
2020-09-26 10:45 Tobias Jordan
@ 2020-09-26 14:44 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2020-09-26 14:44 UTC (permalink / raw)
To: Tobias Jordan
Cc: linux-iio, linux-kernel, Nuno Sá,
Lars-Peter Clausen, Peter Meerwald-Stadler
On Sat, 26 Sep 2020 12:45:54 +0200
Tobias Jordan <kernel@cdqe.de> wrote:
> 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>
Nuno Sá sent a fix for this yesterday which I've just applied.
Unlucky timing on this one!
Thanks,
Jonathan
> ---
> 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 */
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] iio: temperature: ltc2983: fix leak of device node iterator
@ 2020-09-26 10:45 Tobias Jordan
2020-09-26 14:44 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Tobias Jordan @ 2020-09-26 10:45 UTC (permalink / raw)
To: linux-iio, linux-kernel
Cc: Nuno Sá,
Jonathan Cameron, Lars-Peter Clausen, Peter Meerwald-Stadler
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-09-26 14:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <b5eca237-b7ea-e4ca-3936-8c32892e49b5@web.de>
2020-09-26 14:55 ` [PATCH] iio: temperature: ltc2983: fix leak of device node iterator Jonathan Cameron
2020-09-26 10:45 Tobias Jordan
2020-09-26 14:44 ` Jonathan Cameron
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).