]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
iio: adc: ad7124: fix channel lookup in syscalib functions
authorDavid Lechner <dlechner@baylibre.com>
Sat, 26 Jul 2025 16:28:48 +0000 (11:28 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Aug 2025 14:34:39 +0000 (16:34 +0200)
commit 197e299aae42ffa19028eaea92b2f30dd9fb8445 upstream.

Fix possible incorrect channel lookup in the syscalib functions by using
the correct channel address instead of the channel number.

In the ad7124 driver, the channel field of struct iio_chan_spec is the
input pin number of the positive input of the channel. This can be, but
is not always the same as the index in the channels array. The correct
index in the channels array is stored in the address field (and also
scan_index). We use the address field to perform the correct lookup.

Fixes: 47036a03a303 ("iio: adc: ad7124: Implement internal calibration at probe time")
Signed-off-by: David Lechner <dlechner@baylibre.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Link: https://patch.msgid.link/20250726-iio-adc-ad7124-fix-channel-lookup-in-syscalib-v1-1-b9d14bb684af@baylibre.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/iio/adc/ad7124.c

index 92596f15e797378329d2072bff71e392664c69db..bdd2b2b5bac1ae17998033e56c29323690e07e11 100644 (file)
@@ -855,7 +855,7 @@ enum {
 static int ad7124_syscalib_locked(struct ad7124_state *st, const struct iio_chan_spec *chan)
 {
        struct device *dev = &st->sd.spi->dev;
-       struct ad7124_channel *ch = &st->channels[chan->channel];
+       struct ad7124_channel *ch = &st->channels[chan->address];
        int ret;
 
        if (ch->syscalib_mode == AD7124_SYSCALIB_ZERO_SCALE) {
@@ -871,8 +871,8 @@ static int ad7124_syscalib_locked(struct ad7124_state *st, const struct iio_chan
                if (ret < 0)
                        return ret;
 
-               dev_dbg(dev, "offset for channel %d after zero-scale calibration: 0x%x\n",
-                       chan->channel, ch->cfg.calibration_offset);
+               dev_dbg(dev, "offset for channel %lu after zero-scale calibration: 0x%x\n",
+                       chan->address, ch->cfg.calibration_offset);
        } else {
                ch->cfg.calibration_gain = st->gain_default;
 
@@ -886,8 +886,8 @@ static int ad7124_syscalib_locked(struct ad7124_state *st, const struct iio_chan
                if (ret < 0)
                        return ret;
 
-               dev_dbg(dev, "gain for channel %d after full-scale calibration: 0x%x\n",
-                       chan->channel, ch->cfg.calibration_gain);
+               dev_dbg(dev, "gain for channel %lu after full-scale calibration: 0x%x\n",
+                       chan->address, ch->cfg.calibration_gain);
        }
 
        return 0;
@@ -930,7 +930,7 @@ static int ad7124_set_syscalib_mode(struct iio_dev *indio_dev,
 {
        struct ad7124_state *st = iio_priv(indio_dev);
 
-       st->channels[chan->channel].syscalib_mode = mode;
+       st->channels[chan->address].syscalib_mode = mode;
 
        return 0;
 }
@@ -940,7 +940,7 @@ static int ad7124_get_syscalib_mode(struct iio_dev *indio_dev,
 {
        struct ad7124_state *st = iio_priv(indio_dev);
 
-       return st->channels[chan->channel].syscalib_mode;
+       return st->channels[chan->address].syscalib_mode;
 }
 
 static const struct iio_enum ad7124_syscalib_mode_enum = {