Skip to content

Commit 2def1a8

Browse files
dlechgregkh
authored andcommitted
iio: adc: ad7173: fix channels index for syscalib_mode
commit 0eb8d7b upstream. Fix the index used to look up the channel when accessing the syscalib_mode attribute. The address field is a 0-based index (same as scan_index) that it used to access the channel in the ad7173_channels array throughout the driver. The channels field, on the other hand, may not match the address field depending on the channel configuration specified in the device tree and could result in an out-of-bounds access. Fixes: 031bdc8 ("iio: adc: ad7173: add calibration support") Signed-off-by: David Lechner <dlechner@baylibre.com> Link: https://patch.msgid.link/20250703-iio-adc-ad7173-fix-channels-index-for-syscalib_mode-v1-1-7fdaedb9cac0@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 4c6cc6d commit 2def1a8

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/iio/adc/ad7173.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static int ad7173_set_syscalib_mode(struct iio_dev *indio_dev,
319319
{
320320
struct ad7173_state *st = iio_priv(indio_dev);
321321

322-
st->channels[chan->channel].syscalib_mode = mode;
322+
st->channels[chan->address].syscalib_mode = mode;
323323

324324
return 0;
325325
}
@@ -329,7 +329,7 @@ static int ad7173_get_syscalib_mode(struct iio_dev *indio_dev,
329329
{
330330
struct ad7173_state *st = iio_priv(indio_dev);
331331

332-
return st->channels[chan->channel].syscalib_mode;
332+
return st->channels[chan->address].syscalib_mode;
333333
}
334334

335335
static ssize_t ad7173_write_syscalib(struct iio_dev *indio_dev,
@@ -348,7 +348,7 @@ static ssize_t ad7173_write_syscalib(struct iio_dev *indio_dev,
348348
if (!iio_device_claim_direct(indio_dev))
349349
return -EBUSY;
350350

351-
mode = st->channels[chan->channel].syscalib_mode;
351+
mode = st->channels[chan->address].syscalib_mode;
352352
if (sys_calib) {
353353
if (mode == AD7173_SYSCALIB_ZERO_SCALE)
354354
ret = ad_sd_calibrate(&st->sd, AD7173_MODE_CAL_SYS_ZERO,

0 commit comments

Comments
 (0)