[PATCH 15/18] iio: adc: ad4170-4: Fix channel count with 15 external channels

From: Janani Sunil

Date: Thu Dec 03 2026 - 10:21:10 EST


ad4170_parse_channels() decides whether to append the temperature
channel from the child count already incremented for it. With 15
channel nodes the count reaches the 16 channel limit, so the
temperature channel is skipped while num_channels still accounts for
it. The timestamp lands in slot 15 and the advertised slot 16 is left
zeroed, which duplicates scan index 0 and makes probe fail.

Decide on the temperature channel from the number of channels actually
populated and derive num_channels from it.

Fixes: 03223844b8f2 ("iio: adc: ad4170-4: Add support for internal temperature sensor")
Signed-off-by: Janani Sunil <janani.sunil@xxxxxxxxxx>
---
drivers/iio/adc/ad4170-4.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
index 424be6fb851e..7062ef306f58 100644
--- a/drivers/iio/adc/ad4170-4.c
+++ b/drivers/iio/adc/ad4170-4.c
@@ -2383,9 +2383,6 @@ static int ad4170_parse_channels(struct iio_dev *indio_dev)
if (num_channels > AD4170_MAX_ADC_CHANNELS)
return dev_err_probe(dev, -EINVAL, "Too many channels\n");

- /* Add one for temperature */
- num_channels = min(num_channels + 1, AD4170_MAX_ADC_CHANNELS);
-
chan_num = 0;
device_for_each_child_node_scoped(dev, child) {
ret = ad4170_parse_channel_node(indio_dev, child, chan_num++);
@@ -2397,7 +2394,7 @@ static int ad4170_parse_channels(struct iio_dev *indio_dev)
* Add internal temperature sensor channel if the maximum number of
* channels has not been reached.
*/
- if (num_channels < AD4170_MAX_ADC_CHANNELS) {
+ if (chan_num < AD4170_MAX_ADC_CHANNELS) {
struct ad4170_setup *setup = &st->chan_infos[chan_num].setup;

st->chans[chan_num] = ad4170_temp_channel_template;
@@ -2423,9 +2420,8 @@ static int ad4170_parse_channels(struct iio_dev *indio_dev)
struct iio_chan_spec ts_chan = IIO_CHAN_SOFT_TIMESTAMP(chan_num);

st->chans[chan_num] = ts_chan;
- num_channels = num_channels + 1;

- indio_dev->num_channels = num_channels;
+ indio_dev->num_channels = chan_num + 1;
indio_dev->channels = st->chans;

return 0;

--
2.43.0