Skip to content

Commit f219687

Browse files
author
Marius Cristea
committed
iio: adc: PAC1934: fix accessing out of bounds array index
Fix accessing out of bounds array index for average current and voltage measurements. The device itself has only 4 channels, but in sysfs there are "fake" channels for the average voltages and currents too. Fixes: ae2bc5c: "iio: adc: adding support for PAC193x" Reported-by: Conor Dooley <conor.dooley@microchip.com> Signed-off-by: Marius Cristea <marius.cristea@microchip.com>
1 parent ae2bc5c commit f219687

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

drivers/iio/adc/pac1934.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,15 @@ static int pac1934_read_raw(struct iio_dev *indio_dev,
787787
s64 curr_energy;
788788
int ret, channel = chan->channel - 1;
789789

790+
/*
791+
* For AVG the index should be between 5 to 8.
792+
* To calculate PAC1934_CH_VOLTAGE_AVERAGE,
793+
* respectively PAC1934_CH_CURRENT real index, we need
794+
* to remove the added offset (PAC1934_MAX_NUM_CHANNELS).
795+
*/
796+
if (channel >= PAC1934_MAX_NUM_CHANNELS)
797+
channel = channel - PAC1934_MAX_NUM_CHANNELS;
798+
790799
ret = pac1934_retrieve_data(info, PAC1934_MIN_UPDATE_WAIT_TIME_US);
791800
if (ret < 0)
792801
return ret;

0 commit comments

Comments
 (0)