]> Git Repo - J-linux.git/commitdiff
iio: adc: PAC1934: fix accessing out of bounds array index
authorMarius Cristea <[email protected]>
Thu, 25 Apr 2024 11:42:32 +0000 (14:42 +0300)
committerJonathan Cameron <[email protected]>
Fri, 3 May 2024 10:48:56 +0000 (11:48 +0100)
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: 0fb528c8255b ("iio: adc: adding support for PAC193x")
Reported-by: Conor Dooley <[email protected]>
Signed-off-by: Marius Cristea <[email protected]>
Closes: https://lore.kernel.org/linux-iio/20240405-embellish-bonnet-ab5f10560d93@wendy/
Tested-by: Conor Dooley <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jonathan Cameron <[email protected]>
drivers/iio/adc/pac1934.c

index f751260605e4e107e209fa42656df4e9079b40f6..456f12faa348074c6f0c7c4e4d1ba11ed3c66337 100644 (file)
@@ -787,6 +787,15 @@ static int pac1934_read_raw(struct iio_dev *indio_dev,
        s64 curr_energy;
        int ret, channel = chan->channel - 1;
 
+       /*
+        * For AVG the index should be between 5 to 8.
+        * To calculate PAC1934_CH_VOLTAGE_AVERAGE,
+        * respectively PAC1934_CH_CURRENT real index, we need
+        * to remove the added offset (PAC1934_MAX_NUM_CHANNELS).
+        */
+       if (channel >= PAC1934_MAX_NUM_CHANNELS)
+               channel = channel - PAC1934_MAX_NUM_CHANNELS;
+
        ret = pac1934_retrieve_data(info, PAC1934_MIN_UPDATE_WAIT_TIME_US);
        if (ret < 0)
                return ret;
This page took 0.053748 seconds and 4 git commands to generate.