Patch "iio: adc: PAC1934: fix accessing out of bounds array index" has been added to the 6.9-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    iio: adc: PAC1934: fix accessing out of bounds array index

to the 6.9-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     iio-adc-pac1934-fix-accessing-out-of-bounds-array-in.patch
and it can be found in the queue-6.9 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 7742b8cfee2d42dfd2f1c7f147d40e1c858e9845
Author: Marius Cristea <marius.cristea@xxxxxxxxxxxxx>
Date:   Thu Apr 25 14:42:32 2024 +0300

    iio: adc: PAC1934: fix accessing out of bounds array index
    
    [ Upstream commit 51fafb3cd7fcf4f4682693b4d2883e2a5bfffe33 ]
    
    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 <conor.dooley@xxxxxxxxxxxxx>
    Signed-off-by: Marius Cristea <marius.cristea@xxxxxxxxxxxxx>
    Closes: https://lore.kernel.org/linux-iio/20240405-embellish-bonnet-ab5f10560d93@wendy/
    Tested-by: Conor Dooley <conor.dooley@xxxxxxxxxxxxx>
    Link: https://lore.kernel.org/r/20240425114232.81390-1-marius.cristea@xxxxxxxxxxxxx
    Signed-off-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/iio/adc/pac1934.c b/drivers/iio/adc/pac1934.c
index e0c2742da5236..8a0c357422121 100644
--- a/drivers/iio/adc/pac1934.c
+++ b/drivers/iio/adc/pac1934.c
@@ -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;




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux