Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Nuno Sá and committed by
Jonathan Cameron
25d4abbf 919726c9

+5
+5
drivers/iio/temperature/ltc2983.c
··· 1275 1275 &st->filter_notch_freq); 1276 1276 1277 1277 st->num_channels = of_get_available_child_count(dev->of_node); 1278 + if (!st->num_channels) { 1279 + dev_err(&st->spi->dev, "At least one channel must be given!"); 1280 + return -EINVAL; 1281 + } 1282 + 1278 1283 st->sensors = devm_kcalloc(dev, st->num_channels, sizeof(*st->sensors), 1279 1284 GFP_KERNEL); 1280 1285 if (!st->sensors)