]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
iio: adc: ad7124: Don't create more channels than the driver can handle
authorUwe Kleine-König <u.kleine-koenig@baylibre.com>
Fri, 6 Dec 2024 17:28:33 +0000 (18:28 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Wed, 11 Dec 2024 19:20:47 +0000 (19:20 +0000)
The ad7124-4 and ad7124-8 both support 16 channel registers and assigns
each channel defined in dt statically such a register. While the driver
could be a bit more clever about this, it currently isn't and specifying
more than 16 channels yields broken behaviour. So just refuse to bind in
this situation.

Fixes: b3af341bbd96 ("iio: adc: Add ad7124 support")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Link: https://patch.msgid.link/1b9a5a1d334e5501294f7f9f9d5893f1cdf1b0ec.1733504533.git.u.kleine-koenig@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ad7124.c

index 7314fb32bdecb407f234d6553c54117133c981f7..7b749df9eeed8aa795ad74ac6cafb160e4e4b87e 100644 (file)
@@ -821,6 +821,16 @@ static int ad7124_parse_channel_config(struct iio_dev *indio_dev,
        if (!st->num_channels)
                return dev_err_probe(dev, -ENODEV, "no channel children\n");
 
+       /*
+        * The driver assigns each logical channel defined in the device tree
+        * statically one channel register. So only accept 16 such logical
+        * channels to not treat CONFIG_0 (i.e. the register following
+        * CHANNEL_15) as an additional channel register. The driver could be
+        * improved to lift this limitation.
+        */
+       if (st->num_channels > AD7124_MAX_CHANNELS)
+               return dev_err_probe(dev, -EINVAL, "Too many channels defined\n");
+
        chan = devm_kcalloc(indio_dev->dev.parent, st->num_channels,
                            sizeof(*chan), GFP_KERNEL);
        if (!chan)