Skip to content

Commit 23c0d44

Browse files
dlechgregkh
authored andcommitted
iio: adc: ad7124: fix channel lookup in syscalib functions
commit 197e299 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: 47036a0 ("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>
1 parent 600b6ac commit 23c0d44

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drivers/iio/adc/ad7124.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ enum {
855855
static int ad7124_syscalib_locked(struct ad7124_state *st, const struct iio_chan_spec *chan)
856856
{
857857
struct device *dev = &st->sd.spi->dev;
858-
struct ad7124_channel *ch = &st->channels[chan->channel];
858+
struct ad7124_channel *ch = &st->channels[chan->address];
859859
int ret;
860860

861861
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
871871
if (ret < 0)
872872
return ret;
873873

874-
dev_dbg(dev, "offset for channel %d after zero-scale calibration: 0x%x\n",
875-
chan->channel, ch->cfg.calibration_offset);
874+
dev_dbg(dev, "offset for channel %lu after zero-scale calibration: 0x%x\n",
875+
chan->address, ch->cfg.calibration_offset);
876876
} else {
877877
ch->cfg.calibration_gain = st->gain_default;
878878

@@ -886,8 +886,8 @@ static int ad7124_syscalib_locked(struct ad7124_state *st, const struct iio_chan
886886
if (ret < 0)
887887
return ret;
888888

889-
dev_dbg(dev, "gain for channel %d after full-scale calibration: 0x%x\n",
890-
chan->channel, ch->cfg.calibration_gain);
889+
dev_dbg(dev, "gain for channel %lu after full-scale calibration: 0x%x\n",
890+
chan->address, ch->cfg.calibration_gain);
891891
}
892892

893893
return 0;
@@ -930,7 +930,7 @@ static int ad7124_set_syscalib_mode(struct iio_dev *indio_dev,
930930
{
931931
struct ad7124_state *st = iio_priv(indio_dev);
932932

933-
st->channels[chan->channel].syscalib_mode = mode;
933+
st->channels[chan->address].syscalib_mode = mode;
934934

935935
return 0;
936936
}
@@ -940,7 +940,7 @@ static int ad7124_get_syscalib_mode(struct iio_dev *indio_dev,
940940
{
941941
struct ad7124_state *st = iio_priv(indio_dev);
942942

943-
return st->channels[chan->channel].syscalib_mode;
943+
return st->channels[chan->address].syscalib_mode;
944944
}
945945

946946
static const struct iio_enum ad7124_syscalib_mode_enum = {

0 commit comments

Comments
 (0)