iio: adc: PAC1934: fix accessing out of bounds array index
Subsystems (2)
[email protected]
maintainerPATCH 1/1 iio: adc: PAC1934: fix accessing out of bounds array index
From: Marius Cristea <[email protected]>
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.
--- drivers/iio/adc/pac1934.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/iio/adc/pac1934.c +9 -0
@@ -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;
base-commit: b80ad8e3cd2712b78b98804d1f59199680d8ed91
Signature · 1 line
2.34.1
Quoted 39 lines · On Thu, Apr 25, 2024 at 02:42:32PM +0300, [email protected] wrote:
From: Marius Cristea <[email protected]>
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]>--- drivers/iio/adc/pac1934.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/iio/adc/pac1934.c +9
-0@@ -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;base-commit:
b80ad8e3cd2712b78b98804d1f59199680d8ed91Signature · 1 line
2.34.1
Conor Dooley
Tested-byQuoted 11 lines · Conor Dooley
Quoted 10 lines · On Thu, Apr 25, 2024 at 02:42:32PM +0300, [email protected] wrote:
From: Marius Cristea <[email protected]>
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]>
Huh, this is an empty message. I intended to send some tags, but must not have saved the buffer.
Cheers,
Conor.
Quoted 29 lines
Quoted 29 lines
--- drivers/iio/adc/pac1934.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/iio/adc/pac1934.c +9
-0@@ -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;base-commit:
b80ad8e3cd2712b78b98804d1f59199680d8ed91Signature · 1 line
2.34.1
Quoted 14 lines · On Thu, 25 Apr 2024 16:36:19 +0100 Conor Dooley <[email protected]> wrote:
Quoted 11 lines · Conor Dooley
Quoted 10 lines · On Thu, Apr 25, 2024 at 02:42:32PM +0300, [email protected] wrote:
From: Marius Cristea <[email protected]>
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]>
Quoted 5 lines
Huh, this is an empty message. I intended to send some tags, but must not have saved the buffer.
Applied to the fixes-togreg branch of iio.git
Thanks,
Jonathan
Quoted 35 lines
Cheers,
Conor.Quoted 29 lines
Quoted 29 lines
--- drivers/iio/adc/pac1934.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/iio/adc/pac1934.c +9
-0@@ -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;base-commit:
b80ad8e3cd2712b78b98804d1f59199680d8ed91Signature · 1 line
2.34.1