linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/1] iio: imu: adis16475.c: Add buffer padding after temp
@ 2023-09-26  8:57 Ramona Gradinariu
  2023-09-26  8:57 ` [PATCH 1/1] iio: imu: adis16475.c: Add buffer padding after temp channel Ramona Gradinariu
  0 siblings, 1 reply; 4+ messages in thread
From: Ramona Gradinariu @ 2023-09-26  8:57 UTC (permalink / raw)
  To: jic23, nuno.sa, linux-iio, linux-kernel; +Cc: Ramona Gradinariu

The temperature channel has 16-bit storage size. We need to perform
the padding to have the buffer elements naturally aligned in case
the temperature channel is enabled and there are any 32-bit storage
size channels enabled which have a scan index higher than the
temperature channel scan index.
This is a fix for the bug which was introduced with
8f6bc87d67c0 ("iio: imu: adis16475.c: Add delta angle and delta velocity channels").

Ramona Gradinariu (1):
  iio: imu: adis16475.c: Add buffer padding after temp channel

 drivers/iio/imu/adis16475.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

--
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/1] iio: imu: adis16475.c: Add buffer padding after temp channel
  2023-09-26  8:57 [PATCH 0/1] iio: imu: adis16475.c: Add buffer padding after temp Ramona Gradinariu
@ 2023-09-26  8:57 ` Ramona Gradinariu
  2023-09-26 10:50   ` Nuno Sá
  0 siblings, 1 reply; 4+ messages in thread
From: Ramona Gradinariu @ 2023-09-26  8:57 UTC (permalink / raw)
  To: jic23, nuno.sa, linux-iio, linux-kernel; +Cc: Ramona Gradinariu

The temperature channel has 16-bit storage size. We need to perform
the padding to have the buffer elements naturally aligned in case
the temperature channel is enabled and there are any 32-bit storage
size channels enabled which have a scan index higher than the
temperature channel scan index.

Fixes: 8f6bc87d67c0 ("iio: imu: adis16475.c: Add delta angle and delta velocity channels")
Signed-off-by: Ramona Gradinariu <ramona.gradinariu@analog.com>
---
 drivers/iio/imu/adis16475.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/iio/imu/adis16475.c b/drivers/iio/imu/adis16475.c
index 00e4e09cdafb..9af07fec0d89 100644
--- a/drivers/iio/imu/adis16475.c
+++ b/drivers/iio/imu/adis16475.c
@@ -1197,6 +1197,16 @@ static irqreturn_t adis16475_trigger_handler(int irq, void *p)
 		switch (bit) {
 		case ADIS16475_SCAN_TEMP:
 			st->data[i++] = buffer[offset];
+			/*
+			 * The temperature channel has 16-bit storage size.
+			 * We need to perform the padding to have the buffer
+			 * elements naturally aligned in case there are any
+			 * 32-bit storage size channels enabled which have a
+			 * scan index higher than the temperature channel scan
+			 * index.
+			 */
+			if (*indio_dev->active_scan_mask & GENMASK(ADIS16475_SCAN_DELTVEL_Z, ADIS16475_SCAN_DELTANG_X))
+				st->data[i++] = 0;
 			break;
 		case ADIS16475_SCAN_DELTANG_X ... ADIS16475_SCAN_DELTVEL_Z:
 			buff_offset = ADIS16475_SCAN_DELTANG_X;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] iio: imu: adis16475.c: Add buffer padding after temp channel
  2023-09-26  8:57 ` [PATCH 1/1] iio: imu: adis16475.c: Add buffer padding after temp channel Ramona Gradinariu
@ 2023-09-26 10:50   ` Nuno Sá
  2023-09-30 16:39     ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Nuno Sá @ 2023-09-26 10:50 UTC (permalink / raw)
  To: Ramona Gradinariu, jic23, nuno.sa, linux-iio, linux-kernel

On Tue, 2023-09-26 at 11:57 +0300, Ramona Gradinariu wrote:
> The temperature channel has 16-bit storage size. We need to perform
> the padding to have the buffer elements naturally aligned in case
> the temperature channel is enabled and there are any 32-bit storage
> size channels enabled which have a scan index higher than the
> temperature channel scan index.
> 
> Fixes: 8f6bc87d67c0 ("iio: imu: adis16475.c: Add delta angle and delta
> velocity channels")
> Signed-off-by: Ramona Gradinariu <ramona.gradinariu@analog.com>
> ---

Reviewed-by: Nuno Sa <nuno.sa@analog.com>

>  drivers/iio/imu/adis16475.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/iio/imu/adis16475.c b/drivers/iio/imu/adis16475.c
> index 00e4e09cdafb..9af07fec0d89 100644
> --- a/drivers/iio/imu/adis16475.c
> +++ b/drivers/iio/imu/adis16475.c
> @@ -1197,6 +1197,16 @@ static irqreturn_t adis16475_trigger_handler(int irq,
> void *p)
>                 switch (bit) {
>                 case ADIS16475_SCAN_TEMP:
>                         st->data[i++] = buffer[offset];
> +                       /*
> +                        * The temperature channel has 16-bit storage size.
> +                        * We need to perform the padding to have the buffer
> +                        * elements naturally aligned in case there are any
> +                        * 32-bit storage size channels enabled which have a
> +                        * scan index higher than the temperature channel scan
> +                        * index.
> +                        */
> +                       if (*indio_dev->active_scan_mask &
> GENMASK(ADIS16475_SCAN_DELTVEL_Z, ADIS16475_SCAN_DELTANG_X))
> +                               st->data[i++] = 0;

You could use ADIS16500_BURST_DATA_SEL_1_CHN_MASK but I kind of agree like this
is more obvious what's going on...

>                         break;
>                 case ADIS16475_SCAN_DELTANG_X ... ADIS16475_SCAN_DELTVEL_Z:
>                         buff_offset = ADIS16475_SCAN_DELTANG_X;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] iio: imu: adis16475.c: Add buffer padding after temp channel
  2023-09-26 10:50   ` Nuno Sá
@ 2023-09-30 16:39     ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2023-09-30 16:39 UTC (permalink / raw)
  To: Nuno Sá; +Cc: Ramona Gradinariu, nuno.sa, linux-iio, linux-kernel

On Tue, 26 Sep 2023 12:50:38 +0200
Nuno Sá <noname.nuno@gmail.com> wrote:

> On Tue, 2023-09-26 at 11:57 +0300, Ramona Gradinariu wrote:
> > The temperature channel has 16-bit storage size. We need to perform
> > the padding to have the buffer elements naturally aligned in case
> > the temperature channel is enabled and there are any 32-bit storage
> > size channels enabled which have a scan index higher than the
> > temperature channel scan index.
> > 
> > Fixes: 8f6bc87d67c0 ("iio: imu: adis16475.c: Add delta angle and delta
> > velocity channels")
> > Signed-off-by: Ramona Gradinariu <ramona.gradinariu@analog.com>
> > ---  
> 
> Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Applied to the togreg branch of iio.git.

Jonathan

> 
> >  drivers/iio/imu/adis16475.c | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> > 
> > diff --git a/drivers/iio/imu/adis16475.c b/drivers/iio/imu/adis16475.c
> > index 00e4e09cdafb..9af07fec0d89 100644
> > --- a/drivers/iio/imu/adis16475.c
> > +++ b/drivers/iio/imu/adis16475.c
> > @@ -1197,6 +1197,16 @@ static irqreturn_t adis16475_trigger_handler(int irq,
> > void *p)
> >                 switch (bit) {
> >                 case ADIS16475_SCAN_TEMP:
> >                         st->data[i++] = buffer[offset];
> > +                       /*
> > +                        * The temperature channel has 16-bit storage size.
> > +                        * We need to perform the padding to have the buffer
> > +                        * elements naturally aligned in case there are any
> > +                        * 32-bit storage size channels enabled which have a
> > +                        * scan index higher than the temperature channel scan
> > +                        * index.
> > +                        */
> > +                       if (*indio_dev->active_scan_mask &
> > GENMASK(ADIS16475_SCAN_DELTVEL_Z, ADIS16475_SCAN_DELTANG_X))
> > +                               st->data[i++] = 0;  
> 
> You could use ADIS16500_BURST_DATA_SEL_1_CHN_MASK but I kind of agree like this
> is more obvious what's going on...
> 
> >                         break;
> >                 case ADIS16475_SCAN_DELTANG_X ... ADIS16475_SCAN_DELTVEL_Z:
> >                         buff_offset = ADIS16475_SCAN_DELTANG_X;  
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-09-30 16:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-26  8:57 [PATCH 0/1] iio: imu: adis16475.c: Add buffer padding after temp Ramona Gradinariu
2023-09-26  8:57 ` [PATCH 1/1] iio: imu: adis16475.c: Add buffer padding after temp channel Ramona Gradinariu
2023-09-26 10:50   ` Nuno Sá
2023-09-30 16:39     ` 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 NNTP newsgroup(s).