Skip to content

Commit

Permalink
iio: ltc2983: Fix of_node refcounting
Browse files Browse the repository at this point in the history
commit b07c47b upstream.

When returning or breaking early from a
`for_each_available_child_of_node()` loop, we need to explicitly call
`of_node_put()` on the child node to possibly release the node.

Fixes: f110f31 ("iio: temperature: Add support for LTC2983")
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20200925091045.302-1-nuno.sa@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
nunojsa authored and gregkh committed Nov 5, 2020
1 parent 4655afc commit 3990c50
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions drivers/iio/temperature/ltc2983.c
Expand Up @@ -1285,26 +1285,28 @@ 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");
return ret;
goto put_child;
}

/* check if we have a valid channel */
if (sensor.chan < LTC2983_MIN_CHANNELS_NR ||
sensor.chan > LTC2983_MAX_CHANNELS_NR) {
ret = -EINVAL;
dev_err(dev,
"chan:%d must be from 1 to 20\n", sensor.chan);
return -EINVAL;
goto put_child;
} else if (channel_avail_mask & BIT(sensor.chan)) {
ret = -EINVAL;
dev_err(dev, "chan:%d already in use\n", sensor.chan);
return -EINVAL;
goto put_child;
}

ret = of_property_read_u32(child, "adi,sensor-type",
&sensor.type);
if (ret) {
dev_err(dev,
"adi,sensor-type property must given for child nodes\n");
return ret;
goto put_child;
}

dev_dbg(dev, "Create new sensor, type %u, chann %u",
Expand Down Expand Up @@ -1334,13 +1336,15 @@ 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);
return -EINVAL;
ret = -EINVAL;
goto put_child;
}

if (IS_ERR(st->sensors[chan])) {
dev_err(dev, "Failed to create sensor %ld",
PTR_ERR(st->sensors[chan]));
return PTR_ERR(st->sensors[chan]);
ret = PTR_ERR(st->sensors[chan]);
goto put_child;
}
/* set generic sensor parameters */
st->sensors[chan]->chan = sensor.chan;
Expand All @@ -1351,6 +1355,9 @@ static int ltc2983_parse_dt(struct ltc2983_data *st)
}

return 0;
put_child:
of_node_put(child);
return ret;
}

static int ltc2983_setup(struct ltc2983_data *st, bool assign_iio)
Expand Down

0 comments on commit 3990c50

Please sign in to comment.