Skip to content

Commit 197e299

Browse files
dlechjic23
authored andcommitted
iio: adc: ad7124: fix channel lookup in syscalib functions
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 <[email protected]> Reviewed-by: Nuno Sá <[email protected]> Link: https://patch.msgid.link/20250726-iio-adc-ad7124-fix-channel-lookup-in-syscalib-v1-1-b9d14bb684af@baylibre.com Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent ae5bc07 commit 197e299

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
@@ -849,7 +849,7 @@ enum {
849849
static int ad7124_syscalib_locked(struct ad7124_state *st, const struct iio_chan_spec *chan)
850850
{
851851
struct device *dev = &st->sd.spi->dev;
852-
struct ad7124_channel *ch = &st->channels[chan->channel];
852+
struct ad7124_channel *ch = &st->channels[chan->address];
853853
int ret;
854854

855855
if (ch->syscalib_mode == AD7124_SYSCALIB_ZERO_SCALE) {
@@ -865,8 +865,8 @@ static int ad7124_syscalib_locked(struct ad7124_state *st, const struct iio_chan
865865
if (ret < 0)
866866
return ret;
867867

868-
dev_dbg(dev, "offset for channel %d after zero-scale calibration: 0x%x\n",
869-
chan->channel, ch->cfg.calibration_offset);
868+
dev_dbg(dev, "offset for channel %lu after zero-scale calibration: 0x%x\n",
869+
chan->address, ch->cfg.calibration_offset);
870870
} else {
871871
ch->cfg.calibration_gain = st->gain_default;
872872

@@ -880,8 +880,8 @@ static int ad7124_syscalib_locked(struct ad7124_state *st, const struct iio_chan
880880
if (ret < 0)
881881
return ret;
882882

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

887887
return 0;
@@ -924,7 +924,7 @@ static int ad7124_set_syscalib_mode(struct iio_dev *indio_dev,
924924
{
925925
struct ad7124_state *st = iio_priv(indio_dev);
926926

927-
st->channels[chan->channel].syscalib_mode = mode;
927+
st->channels[chan->address].syscalib_mode = mode;
928928

929929
return 0;
930930
}
@@ -934,7 +934,7 @@ static int ad7124_get_syscalib_mode(struct iio_dev *indio_dev,
934934
{
935935
struct ad7124_state *st = iio_priv(indio_dev);
936936

937-
return st->channels[chan->channel].syscalib_mode;
937+
return st->channels[chan->address].syscalib_mode;
938938
}
939939

940940
static const struct iio_enum ad7124_syscalib_mode_enum = {

0 commit comments

Comments
 (0)