* [PATCH v1] iio: adc: PAC1934: fix accessing out of bounds array index
@ 2024-04-25 11:42 marius.cristea
2024-04-25 12:22 ` Conor Dooley
0 siblings, 1 reply; 4+ messages in thread
From: marius.cristea @ 2024-04-25 11:42 UTC (permalink / raw
To: jic23, lars, lgirdwood, broonie
Cc: linux-iio, linux-kernel, conor+dt, marius.cristea
From: Marius Cristea <marius.cristea@microchip.com>
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@microchip.com>
Signed-off-by: Marius Cristea <marius.cristea@microchip.com>
---
drivers/iio/adc/pac1934.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/iio/adc/pac1934.c b/drivers/iio/adc/pac1934.c
index f751260605e4..456f12faa348 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;
base-commit: b80ad8e3cd2712b78b98804d1f59199680d8ed91
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v1] iio: adc: PAC1934: fix accessing out of bounds array index
2024-04-25 11:42 [PATCH v1] iio: adc: PAC1934: fix accessing out of bounds array index marius.cristea
@ 2024-04-25 12:22 ` Conor Dooley
2024-04-25 15:36 ` Conor Dooley
0 siblings, 1 reply; 4+ messages in thread
From: Conor Dooley @ 2024-04-25 12:22 UTC (permalink / raw
To: marius.cristea
Cc: jic23, lars, lgirdwood, broonie, linux-iio, linux-kernel,
conor+dt
[-- Attachment #1: Type: text/plain, Size: 1504 bytes --]
On Thu, Apr 25, 2024 at 02:42:32PM +0300, marius.cristea@microchip.com wrote:
> From: Marius Cristea <marius.cristea@microchip.com>
>
> 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@microchip.com>
> Signed-off-by: Marius Cristea <marius.cristea@microchip.com>
> ---
> drivers/iio/adc/pac1934.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/drivers/iio/adc/pac1934.c b/drivers/iio/adc/pac1934.c
> index f751260605e4..456f12faa348 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;
>
> base-commit: b80ad8e3cd2712b78b98804d1f59199680d8ed91
> --
> 2.34.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] iio: adc: PAC1934: fix accessing out of bounds array index
2024-04-25 12:22 ` Conor Dooley
@ 2024-04-25 15:36 ` Conor Dooley
2024-04-28 13:32 ` Jonathan Cameron
0 siblings, 1 reply; 4+ messages in thread
From: Conor Dooley @ 2024-04-25 15:36 UTC (permalink / raw
To: Conor Dooley
Cc: marius.cristea, jic23, lars, lgirdwood, broonie, linux-iio,
linux-kernel, conor+dt
[-- Attachment #1: Type: text/plain, Size: 1920 bytes --]
On Thu, Apr 25, 2024 at 01:22:45PM +0100, Conor Dooley wrote:
> On Thu, Apr 25, 2024 at 02:42:32PM +0300, marius.cristea@microchip.com wrote:
> > From: Marius Cristea <marius.cristea@microchip.com>
> >
> > 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@microchip.com>
> > Signed-off-by: Marius Cristea <marius.cristea@microchip.com>
Huh, this is an empty message. I intended to send some tags, but must
not have saved the buffer.
Closes: https://lore.kernel.org/linux-iio/20240405-embellish-bonnet-ab5f10560d93@wendy/
Tested-by: Conor Dooley <conor.dooley@microchip.com>
Cheers,
Conor.
> > ---
> > drivers/iio/adc/pac1934.c | 9 +++++++++
> > 1 file changed, 9 insertions(+)
> >
> > diff --git a/drivers/iio/adc/pac1934.c b/drivers/iio/adc/pac1934.c
> > index f751260605e4..456f12faa348 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;
> >
> > base-commit: b80ad8e3cd2712b78b98804d1f59199680d8ed91
> > --
> > 2.34.1
> >
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] iio: adc: PAC1934: fix accessing out of bounds array index
2024-04-25 15:36 ` Conor Dooley
@ 2024-04-28 13:32 ` Jonathan Cameron
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2024-04-28 13:32 UTC (permalink / raw
To: Conor Dooley
Cc: Conor Dooley, marius.cristea, lars, lgirdwood, broonie, linux-iio,
linux-kernel, conor+dt
On Thu, 25 Apr 2024 16:36:19 +0100
Conor Dooley <conor@kernel.org> wrote:
> On Thu, Apr 25, 2024 at 01:22:45PM +0100, Conor Dooley wrote:
> > On Thu, Apr 25, 2024 at 02:42:32PM +0300, marius.cristea@microchip.com wrote:
> > > From: Marius Cristea <marius.cristea@microchip.com>
> > >
> > > 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@microchip.com>
> > > Signed-off-by: Marius Cristea <marius.cristea@microchip.com>
>
>
> Huh, this is an empty message. I intended to send some tags, but must
> not have saved the buffer.
>
> Closes: https://lore.kernel.org/linux-iio/20240405-embellish-bonnet-ab5f10560d93@wendy/
> Tested-by: Conor Dooley <conor.dooley@microchip.com>
Applied to the fixes-togreg branch of iio.git
Thanks,
Jonathan
>
> Cheers,
> Conor.
>
> > > ---
> > > drivers/iio/adc/pac1934.c | 9 +++++++++
> > > 1 file changed, 9 insertions(+)
> > >
> > > diff --git a/drivers/iio/adc/pac1934.c b/drivers/iio/adc/pac1934.c
> > > index f751260605e4..456f12faa348 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;
> > >
> > > base-commit: b80ad8e3cd2712b78b98804d1f59199680d8ed91
> > > --
> > > 2.34.1
> > >
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-04-28 13:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-25 11:42 [PATCH v1] iio: adc: PAC1934: fix accessing out of bounds array index marius.cristea
2024-04-25 12:22 ` Conor Dooley
2024-04-25 15:36 ` Conor Dooley
2024-04-28 13:32 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).