diff mbox series

[v2,05/17] staging: iio: cdc: ad7746: Use local buffer for multi byte reads.

Message ID 20220619185839.1363503-6-jic23@kernel.org (mailing list archive)
State Changes Requested
Headers show
Series staging/iio: Clean up AD7746 CDC driver and move from staging. | expand

Commit Message

Jonathan Cameron June 19, 2022, 6:58 p.m. UTC
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

I2C does not require DMA safe buffers so there is no need to ensure
the buffers are in their own cacheline. Hence simplify things by
using a local variable instead of embedding the buffer in the chip
info structure.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/staging/iio/cdc/ad7746.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Andy Shevchenko June 19, 2022, 11 p.m. UTC | #1
On Sun, Jun 19, 2022 at 8:59 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> I2C does not require DMA safe buffers so there is no need to ensure
> the buffers are in their own cacheline. Hence simplify things by
> using a local variable instead of embedding the buffer in the chip
> info structure.

...

>                                                     sizeof(chip->data),
>                                                     chip->data);

How will these compile? Or am I missing something?

> -
>                 if (ret < 0)
>                         goto out;
>
> -               *val = get_unaligned_be24(chip->data) - 0x800000;
> +               *val = get_unaligned_be24(data) - 0x800000;
Jonathan Cameron June 20, 2022, 4:42 p.m. UTC | #2
On Mon, 20 Jun 2022 01:00:23 +0200
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:

> On Sun, Jun 19, 2022 at 8:59 PM Jonathan Cameron <jic23@kernel.org> wrote:
> >
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> >
> > I2C does not require DMA safe buffers so there is no need to ensure
> > the buffers are in their own cacheline. Hence simplify things by
> > using a local variable instead of embedding the buffer in the chip
> > info structure.  
> 
> ...
> 
> >                                                     sizeof(chip->data),
> >                                                     chip->data);  
> 
> How will these compile? Or am I missing something?

Nope.  Something went wrong in the rebase. I should have rechecked
build patch by patch.  Later on, this code is factored out, so I guess
that fixed up the build issue.

Will check properly for v3. :(


> 
> > -
> >                 if (ret < 0)
> >                         goto out;
> >
> > -               *val = get_unaligned_be24(chip->data) - 0x800000;
> > +               *val = get_unaligned_be24(data) - 0x800000;  
>
Jonathan Cameron June 20, 2022, 6:23 p.m. UTC | #3
On Mon, 20 Jun 2022 17:42:36 +0100
Jonathan Cameron <Jonathan.Cameron@Huawei.com> wrote:

> On Mon, 20 Jun 2022 01:00:23 +0200
> Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
> 
> > On Sun, Jun 19, 2022 at 8:59 PM Jonathan Cameron <jic23@kernel.org> wrote:  
> > >
> > > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > >
> > > I2C does not require DMA safe buffers so there is no need to ensure
> > > the buffers are in their own cacheline. Hence simplify things by
> > > using a local variable instead of embedding the buffer in the chip
> > > info structure.    
> > 
> > ...
> >   
> > >                                                     sizeof(chip->data),
> > >                                                     chip->data);    
> > 
> > How will these compile? Or am I missing something?  
> 
> Nope.  Something went wrong in the rebase. I should have rechecked
> build patch by patch.  Later on, this code is factored out, so I guess
> that fixed up the build issue.
> 
> Will check properly for v3. :(
yikes rebase went very wrong.  Anyhow, will fix up.

Turns out I as being an idiot and building with the roadtest makefile
which doesn't actually enable this driver until the last patch.

Jonathan

> 
> 
> >   
> > > -
> > >                 if (ret < 0)
> > >                         goto out;
> > >
> > > -               *val = get_unaligned_be24(chip->data) - 0x800000;
> > > +               *val = get_unaligned_be24(data) - 0x800000;    
> >   
>
diff mbox series

Patch

diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/ad7746.c
index df12fdb20662..f909b841c4d6 100644
--- a/drivers/staging/iio/cdc/ad7746.c
+++ b/drivers/staging/iio/cdc/ad7746.c
@@ -94,8 +94,6 @@  struct ad7746_chip_info {
 	u8	vt_setup;
 	u8	capdac[2][2];
 	s8	capdac_set;
-
-	u8 data[3] ____cacheline_aligned;
 };
 
 enum ad7746_chan {
@@ -520,6 +518,7 @@  static int ad7746_read_raw(struct iio_dev *indio_dev,
 	struct ad7746_chip_info *chip = iio_priv(indio_dev);
 	int ret, delay, idx;
 	u8 regval, reg;
+	u8 data[3];
 
 	mutex_lock(&chip->lock);
 
@@ -544,11 +543,10 @@  static int ad7746_read_raw(struct iio_dev *indio_dev,
 						    chan->address >> 8,
 						    sizeof(chip->data),
 						    chip->data);
-
 		if (ret < 0)
 			goto out;
 
-		*val = get_unaligned_be24(chip->data) - 0x800000;
+		*val = get_unaligned_be24(data) - 0x800000;
 
 		switch (chan->type) {
 		case IIO_TEMP: