diff options
author | Nuno Sá <nuno.sa@analog.com> | 2021-08-25 10:41:49 +0200 |
---|---|---|
committer | Jonathan Cameron <Jonathan.Cameron@huawei.com> | 2021-09-14 12:00:32 +0100 |
commit | 25d4abbf3ddcccb022d890ad1dc0d87262783b03 (patch) | |
tree | 8b130a6ba3cc01454fb16471dfadddb9e3a6c977 /drivers/iio/temperature | |
parent | 919726c9e0efc6dd6476095d37b3ba8e79566c75 (diff) | |
download | linux-25d4abbf3ddcccb022d890ad1dc0d87262783b03.tar.gz |
iio: ltc2983: fail probe if no channels are given
If there are no channels defined in the devicetree, there's no point in
probing the device. We were actually requesting a zero sized 'kmalloc'
array but since we were not touching the ZERO_SIZE_PTR afterwards,
nothing bad was actually happening. Hence this is not really a fix but
rather an improvement.
Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20210825084149.11587-2-nuno.sa@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio/temperature')
-rw-r--r-- | drivers/iio/temperature/ltc2983.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/drivers/iio/temperature/ltc2983.c b/drivers/iio/temperature/ltc2983.c index 22e6a26ce6b1..301c3f13fb26 100644 --- a/drivers/iio/temperature/ltc2983.c +++ b/drivers/iio/temperature/ltc2983.c @@ -1275,6 +1275,11 @@ static int ltc2983_parse_dt(struct ltc2983_data *st) &st->filter_notch_freq); st->num_channels = of_get_available_child_count(dev->of_node); + if (!st->num_channels) { + dev_err(&st->spi->dev, "At least one channel must be given!"); + return -EINVAL; + } + st->sensors = devm_kcalloc(dev, st->num_channels, sizeof(*st->sensors), GFP_KERNEL); if (!st->sensors) |