Skip to contentSkip to conversation

iio: temperature: ltc2983: fix leak of device node iterator

PATCH Superseded Tobias Jordan 2 participants 2 messages Sep 26, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: temperature: ltc2983: fix leak of device node iterator

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")
---
 drivers/iio/temperature/ltc2983.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/iio/temperature/ltc2983.c +6 -0
index 55ff28a0f1c7..438e0ee29025 100644
@@ -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 */
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 9 lines · On Sat, 26 Sep 2020 12:45:54 +0200 Tobias Jordan <[email protected]> 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")

Nuno Sá sent a fix for this yesterday which I've just applied.

Unlucky timing on this one!

Thanks,

Jonathan

Quoted 51 lines
---
 drivers/iio/temperature/ltc2983.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/iio/temperature/ltc2983.c +6 -0
index 55ff28a0f1c7..438e0ee29025 100644
@@ -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 */