Skip to content

Commit 0eb8d7b

Browse files
dlechjic23
authored andcommitted
iio: adc: ad7173: fix channels index for syscalib_mode
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 <[email protected]> Link: https://patch.msgid.link/20250703-iio-adc-ad7173-fix-channels-index-for-syscalib_mode-v1-1-7fdaedb9cac0@baylibre.com Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 66d4374 commit 0eb8d7b

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
@@ -318,7 +318,7 @@ static int ad7173_set_syscalib_mode(struct iio_dev *indio_dev,
318318
{
319319
struct ad7173_state *st = iio_priv(indio_dev);
320320

321-
st->channels[chan->channel].syscalib_mode = mode;
321+
st->channels[chan->address].syscalib_mode = mode;
322322

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

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

334334
static ssize_t ad7173_write_syscalib(struct iio_dev *indio_dev,
@@ -347,7 +347,7 @@ static ssize_t ad7173_write_syscalib(struct iio_dev *indio_dev,
347347
if (!iio_device_claim_direct(indio_dev))
348348
return -EBUSY;
349349

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

0 commit comments

Comments
 (0)