diff mbox series

[2/2] iio: ltc2983: fail probe if no channels are given

Message ID 20210820065535.6994-2-nuno.sa@analog.com (mailing list archive)
State Superseded
Headers show
Series [1/2] iio: ltc2983: add support for optional reset gpio | expand

Commit Message

Nuno Sa Aug. 20, 2021, 6:55 a.m. UTC
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.

Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
 drivers/iio/temperature/ltc2983.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Alexandru Ardelean Aug. 20, 2021, 8:22 a.m. UTC | #1
On Fri, Aug 20, 2021 at 9:53 AM Nuno Sá <nuno.sa@analog.com> wrote:
>
> 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>
> ---
>  drivers/iio/temperature/ltc2983.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/iio/temperature/ltc2983.c b/drivers/iio/temperature/ltc2983.c
> index 37903e9fb90f..7dd2f1dd3685 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)
> --
> 2.33.0
>
diff mbox series

Patch

diff --git a/drivers/iio/temperature/ltc2983.c b/drivers/iio/temperature/ltc2983.c
index 37903e9fb90f..7dd2f1dd3685 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)