Skip to content

Commit a0ddebb

Browse files
ukleineknunojsa
authored andcommitted
iio: adc: ad7124: Don't create more channels than the driver can handle
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: b3af341 ("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> Origin: next-20241216~37^2~25, commit:cc597af18092d0e84ccb108c8e4aa0beea26634d
1 parent d565bac commit a0ddebb

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

drivers/iio/adc/ad7124.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,16 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
831831
return -ENODEV;
832832
}
833833

834+
/*
835+
* The driver assigns each logical channel defined in the device tree
836+
* statically one channel register. So only accept 16 such logical
837+
* channels to not treat CONFIG_0 (i.e. the register following
838+
* CHANNEL_15) as an additional channel register. The driver could be
839+
* improved to lift this limitation.
840+
*/
841+
if (st->num_channels > AD7124_MAX_CHANNELS)
842+
return dev_err_probe(indio_dev->dev.parent, -EINVAL, "Too many channels defined\n");
843+
834844
chan = devm_kcalloc(indio_dev->dev.parent, st->num_channels,
835845
sizeof(*chan), GFP_KERNEL);
836846
if (!chan)

0 commit comments

Comments
 (0)