]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: adc: ad7124: fix DT configuration parsing
authorDumitru Ceclan <mitrutzceclan@gmail.com>
Tue, 6 Aug 2024 08:51:33 +0000 (11:51 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Tue, 6 Aug 2024 16:03:22 +0000 (17:03 +0100)
The cfg pointer is set before reading the channel number that the
configuration should point to. This causes configurations to be shifted
by one channel.
For example setting bipolar to the first channel defined in the DT will
cause bipolar mode to be active on the second defined channel.

Fix by moving the cfg pointer setting after reading the channel number.

Fixes: 7b8d045e497a ("iio: adc: ad7124: allow more than 8 channels")
Signed-off-by: Dumitru Ceclan <dumitru.ceclan@analog.com>
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Link: https://patch.msgid.link/20240806085133.114547-1-dumitru.ceclan@analog.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ad7124.c

index afb5f4d741e6788cc1bce82ad3fbea7d76747268..108e9ccab1ef066b82053f1072ca4ffbd764cdda 100644 (file)
@@ -844,8 +844,6 @@ static int ad7124_parse_channel_config(struct iio_dev *indio_dev,
        st->channels = channels;
 
        device_for_each_child_node_scoped(dev, child) {
-               cfg = &st->channels[channel].cfg;
-
                ret = fwnode_property_read_u32(child, "reg", &channel);
                if (ret)
                        return ret;
@@ -863,6 +861,7 @@ static int ad7124_parse_channel_config(struct iio_dev *indio_dev,
                st->channels[channel].ain = AD7124_CHANNEL_AINP(ain[0]) |
                                                  AD7124_CHANNEL_AINM(ain[1]);
 
+               cfg = &st->channels[channel].cfg;
                cfg->bipolar = fwnode_property_read_bool(child, "bipolar");
 
                ret = fwnode_property_read_u32(child, "adi,reference-select", &tmp);