All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: ad_sigma_delta: Don't put SPI transfer buffer on the stack
@ 2019-04-09  7:58 Alexandru Ardelean
  2019-04-14 12:45 ` Jonathan Cameron
  2019-04-16  8:19 ` [PATCH V2] " Alexandru Ardelean
  0 siblings, 2 replies; 10+ messages in thread
From: Alexandru Ardelean @ 2019-04-09  7:58 UTC (permalink / raw)
  To: linux-iio; +Cc: Lars-Peter Clausen, Alexandru Ardelean

From: Lars-Peter Clausen <lars@metafoo.de>

Use a heap allocated memory for the SPI transfer buffer. Using stack memory
will not work on some architectures when using DMA.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---

Note: this doesn't need a stable/fixes tag. It's more of an enhancement.

 drivers/iio/adc/ad_sigma_delta.c       | 22 +++++++++++-----------
 include/linux/iio/adc/ad_sigma_delta.h |  3 ++-
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index af6cbc683214..02d9049b9218 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -58,7 +58,7 @@ EXPORT_SYMBOL_GPL(ad_sd_set_comm);
 int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
 	unsigned int size, unsigned int val)
 {
-	uint8_t *data = sigma_delta->data;
+	uint8_t *data = sigma_delta->reg_data;
 	struct spi_transfer t = {
 		.tx_buf		= data,
 		.len		= size + 1,
@@ -102,7 +102,7 @@ EXPORT_SYMBOL_GPL(ad_sd_write_reg);
 static int ad_sd_read_reg_raw(struct ad_sigma_delta *sigma_delta,
 	unsigned int reg, unsigned int size, uint8_t *val)
 {
-	uint8_t *data = sigma_delta->data;
+	uint8_t *data = sigma_delta->reg_data;
 	int ret;
 	struct spi_transfer t[] = {
 		{
@@ -148,24 +148,24 @@ int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta,
 {
 	int ret;
 
-	ret = ad_sd_read_reg_raw(sigma_delta, reg, size, sigma_delta->data);
+	ret = ad_sd_read_reg_raw(sigma_delta, reg, size, sigma_delta->reg_data);
 	if (ret < 0)
 		goto out;
 
 	switch (size) {
 	case 4:
-		*val = get_unaligned_be32(sigma_delta->data);
+		*val = get_unaligned_be32(sigma_delta->reg_data);
 		break;
 	case 3:
-		*val = (sigma_delta->data[0] << 16) |
-			(sigma_delta->data[1] << 8) |
-			sigma_delta->data[2];
+		*val = (sigma_delta->reg_data[0] << 16) |
+			(sigma_delta->reg_data[1] << 8) |
+			sigma_delta->reg_data[2];
 		break;
 	case 2:
-		*val = get_unaligned_be16(sigma_delta->data);
+		*val = get_unaligned_be16(sigma_delta->reg_data);
 		break;
 	case 1:
-		*val = sigma_delta->data[0];
+		*val = sigma_delta->reg_data[0];
 		break;
 	default:
 		ret = -EINVAL;
@@ -403,12 +403,12 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
+	uint8_t *data = sigma_delta->buf_data;
 	unsigned int reg_size;
 	unsigned int data_reg;
-	uint8_t data[16];
 	int ret;
 
-	memset(data, 0x00, 16);
+	memset(sigma_delta->buf_data, 0x00, sizeof(sigma_delta->buf_data));
 
 	reg_size = indio_dev->channels[0].scan_type.realbits +
 			indio_dev->channels[0].scan_type.shift;
diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
index 6e9fb1932dde..fb77b2ebe498 100644
--- a/include/linux/iio/adc/ad_sigma_delta.h
+++ b/include/linux/iio/adc/ad_sigma_delta.h
@@ -79,7 +79,8 @@ struct ad_sigma_delta {
 	 * DMA (thus cache coherency maintenance) requires the
 	 * transfer buffers to live in their own cache lines.
 	 */
-	uint8_t				data[4] ____cacheline_aligned;
+	uint8_t				reg_data[4] ____cacheline_aligned;
+	uint8_t				buf_data[16];
 };
 
 static inline int ad_sigma_delta_set_channel(struct ad_sigma_delta *sd,
-- 
2.17.1


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

* Re: [PATCH] iio: ad_sigma_delta: Don't put SPI transfer buffer on the stack
  2019-04-09  7:58 [PATCH] iio: ad_sigma_delta: Don't put SPI transfer buffer on the stack Alexandru Ardelean
@ 2019-04-14 12:45 ` Jonathan Cameron
  2019-04-15  6:52   ` Ardelean, Alexandru
  2019-04-16  8:19 ` [PATCH V2] " Alexandru Ardelean
  1 sibling, 1 reply; 10+ messages in thread
From: Jonathan Cameron @ 2019-04-14 12:45 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: linux-iio, Lars-Peter Clausen

On Tue, 9 Apr 2019 10:58:21 +0300
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> From: Lars-Peter Clausen <lars@metafoo.de>
> 
> Use a heap allocated memory for the SPI transfer buffer. Using stack memory
> will not work on some architectures when using DMA.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Yikes, surprised this one snuck in here.
> ---
> 
> Note: this doesn't need a stable/fixes tag. It's more of an enhancement.

Talk me through this...  Right now I think this is a bug that is going
to cause random and extremely hard to debug problems.  I've had these
in the past and they are really really nasty as it's random stack corruption.
The nasty is not the fact it's on the stack, but the fact that it isn't
in it's own cacheline.

So my inclination is this definitely needs stable and fixes tag.
What am I missing?

Jonathan

> 
>  drivers/iio/adc/ad_sigma_delta.c       | 22 +++++++++++-----------
>  include/linux/iio/adc/ad_sigma_delta.h |  3 ++-
>  2 files changed, 13 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
> index af6cbc683214..02d9049b9218 100644
> --- a/drivers/iio/adc/ad_sigma_delta.c
> +++ b/drivers/iio/adc/ad_sigma_delta.c
> @@ -58,7 +58,7 @@ EXPORT_SYMBOL_GPL(ad_sd_set_comm);
>  int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
>  	unsigned int size, unsigned int val)
>  {
> -	uint8_t *data = sigma_delta->data;
> +	uint8_t *data = sigma_delta->reg_data;
>  	struct spi_transfer t = {
>  		.tx_buf		= data,
>  		.len		= size + 1,
> @@ -102,7 +102,7 @@ EXPORT_SYMBOL_GPL(ad_sd_write_reg);
>  static int ad_sd_read_reg_raw(struct ad_sigma_delta *sigma_delta,
>  	unsigned int reg, unsigned int size, uint8_t *val)
>  {
> -	uint8_t *data = sigma_delta->data;
> +	uint8_t *data = sigma_delta->reg_data;
>  	int ret;
>  	struct spi_transfer t[] = {
>  		{
> @@ -148,24 +148,24 @@ int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta,
>  {
>  	int ret;
>  
> -	ret = ad_sd_read_reg_raw(sigma_delta, reg, size, sigma_delta->data);
> +	ret = ad_sd_read_reg_raw(sigma_delta, reg, size, sigma_delta->reg_data);
>  	if (ret < 0)
>  		goto out;
>  
>  	switch (size) {
>  	case 4:
> -		*val = get_unaligned_be32(sigma_delta->data);
> +		*val = get_unaligned_be32(sigma_delta->reg_data);
>  		break;
>  	case 3:
> -		*val = (sigma_delta->data[0] << 16) |
> -			(sigma_delta->data[1] << 8) |
> -			sigma_delta->data[2];
> +		*val = (sigma_delta->reg_data[0] << 16) |
> +			(sigma_delta->reg_data[1] << 8) |
> +			sigma_delta->reg_data[2];
>  		break;
>  	case 2:
> -		*val = get_unaligned_be16(sigma_delta->data);
> +		*val = get_unaligned_be16(sigma_delta->reg_data);
>  		break;
>  	case 1:
> -		*val = sigma_delta->data[0];
> +		*val = sigma_delta->reg_data[0];
>  		break;
>  	default:
>  		ret = -EINVAL;
> @@ -403,12 +403,12 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
>  	struct iio_poll_func *pf = p;
>  	struct iio_dev *indio_dev = pf->indio_dev;
>  	struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
> +	uint8_t *data = sigma_delta->buf_data;
>  	unsigned int reg_size;
>  	unsigned int data_reg;
> -	uint8_t data[16];
>  	int ret;
>  
> -	memset(data, 0x00, 16);
> +	memset(sigma_delta->buf_data, 0x00, sizeof(sigma_delta->buf_data));
>  
>  	reg_size = indio_dev->channels[0].scan_type.realbits +
>  			indio_dev->channels[0].scan_type.shift;
> diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
> index 6e9fb1932dde..fb77b2ebe498 100644
> --- a/include/linux/iio/adc/ad_sigma_delta.h
> +++ b/include/linux/iio/adc/ad_sigma_delta.h
> @@ -79,7 +79,8 @@ struct ad_sigma_delta {
>  	 * DMA (thus cache coherency maintenance) requires the
>  	 * transfer buffers to live in their own cache lines.
>  	 */
> -	uint8_t				data[4] ____cacheline_aligned;
> +	uint8_t				reg_data[4] ____cacheline_aligned;
> +	uint8_t				buf_data[16];
>  };
>  
>  static inline int ad_sigma_delta_set_channel(struct ad_sigma_delta *sd,


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

* Re: [PATCH] iio: ad_sigma_delta: Don't put SPI transfer buffer on the stack
  2019-04-14 12:45 ` Jonathan Cameron
@ 2019-04-15  6:52   ` Ardelean, Alexandru
  0 siblings, 0 replies; 10+ messages in thread
From: Ardelean, Alexandru @ 2019-04-15  6:52 UTC (permalink / raw)
  To: jic23; +Cc: lars, linux-iio

On Sun, 2019-04-14 at 13:45 +0100, Jonathan Cameron wrote:
> [External]
> 
> 
> On Tue, 9 Apr 2019 10:58:21 +0300
> Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:
> 
> > From: Lars-Peter Clausen <lars@metafoo.de>
> > 
> > Use a heap allocated memory for the SPI transfer buffer. Using stack
> > memory
> > will not work on some architectures when using DMA.
> > 
> > Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> 
> Yikes, surprised this one snuck in here.
> > ---
> > 
> > Note: this doesn't need a stable/fixes tag. It's more of an
> > enhancement.
> 
> Talk me through this...  Right now I think this is a bug that is going
> to cause random and extremely hard to debug problems.  I've had these
> in the past and they are really really nasty as it's random stack
> corruption.
> The nasty is not the fact it's on the stack, but the fact that it isn't
> in it's own cacheline.
> 
> So my inclination is this definitely needs stable and fixes tag.
> What am I missing?

I guess I'm not that great with discerning stuff (about whether it needs a
stable & fixes tag).
I guess I'm still in an early phase with this one.

My sentiment, is that there haven't been enough support questions about
weird issues with sigma-delta to have categorized this earlier.

But, I guess you're right. This could do with a Fixes/stable tag.

Thanks
Alex

> 
> Jonathan
> 
> > 
> >  drivers/iio/adc/ad_sigma_delta.c       | 22 +++++++++++-----------
> >  include/linux/iio/adc/ad_sigma_delta.h |  3 ++-
> >  2 files changed, 13 insertions(+), 12 deletions(-)
> > 
> > diff --git a/drivers/iio/adc/ad_sigma_delta.c
> > b/drivers/iio/adc/ad_sigma_delta.c
> > index af6cbc683214..02d9049b9218 100644
> > --- a/drivers/iio/adc/ad_sigma_delta.c
> > +++ b/drivers/iio/adc/ad_sigma_delta.c
> > @@ -58,7 +58,7 @@ EXPORT_SYMBOL_GPL(ad_sd_set_comm);
> >  int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, unsigned int
> > reg,
> >       unsigned int size, unsigned int val)
> >  {
> > -     uint8_t *data = sigma_delta->data;
> > +     uint8_t *data = sigma_delta->reg_data;
> >       struct spi_transfer t = {
> >               .tx_buf         = data,
> >               .len            = size + 1,
> > @@ -102,7 +102,7 @@ EXPORT_SYMBOL_GPL(ad_sd_write_reg);
> >  static int ad_sd_read_reg_raw(struct ad_sigma_delta *sigma_delta,
> >       unsigned int reg, unsigned int size, uint8_t *val)
> >  {
> > -     uint8_t *data = sigma_delta->data;
> > +     uint8_t *data = sigma_delta->reg_data;
> >       int ret;
> >       struct spi_transfer t[] = {
> >               {
> > @@ -148,24 +148,24 @@ int ad_sd_read_reg(struct ad_sigma_delta
> > *sigma_delta,
> >  {
> >       int ret;
> > 
> > -     ret = ad_sd_read_reg_raw(sigma_delta, reg, size, sigma_delta-
> > >data);
> > +     ret = ad_sd_read_reg_raw(sigma_delta, reg, size, sigma_delta-
> > >reg_data);
> >       if (ret < 0)
> >               goto out;
> > 
> >       switch (size) {
> >       case 4:
> > -             *val = get_unaligned_be32(sigma_delta->data);
> > +             *val = get_unaligned_be32(sigma_delta->reg_data);
> >               break;
> >       case 3:
> > -             *val = (sigma_delta->data[0] << 16) |
> > -                     (sigma_delta->data[1] << 8) |
> > -                     sigma_delta->data[2];
> > +             *val = (sigma_delta->reg_data[0] << 16) |
> > +                     (sigma_delta->reg_data[1] << 8) |
> > +                     sigma_delta->reg_data[2];
> >               break;
> >       case 2:
> > -             *val = get_unaligned_be16(sigma_delta->data);
> > +             *val = get_unaligned_be16(sigma_delta->reg_data);
> >               break;
> >       case 1:
> > -             *val = sigma_delta->data[0];
> > +             *val = sigma_delta->reg_data[0];
> >               break;
> >       default:
> >               ret = -EINVAL;
> > @@ -403,12 +403,12 @@ static irqreturn_t ad_sd_trigger_handler(int irq,
> > void *p)
> >       struct iio_poll_func *pf = p;
> >       struct iio_dev *indio_dev = pf->indio_dev;
> >       struct ad_sigma_delta *sigma_delta =
> > iio_device_get_drvdata(indio_dev);
> > +     uint8_t *data = sigma_delta->buf_data;
> >       unsigned int reg_size;
> >       unsigned int data_reg;
> > -     uint8_t data[16];
> >       int ret;
> > 
> > -     memset(data, 0x00, 16);
> > +     memset(sigma_delta->buf_data, 0x00, sizeof(sigma_delta-
> > >buf_data));
> > 
> >       reg_size = indio_dev->channels[0].scan_type.realbits +
> >                       indio_dev->channels[0].scan_type.shift;
> > diff --git a/include/linux/iio/adc/ad_sigma_delta.h
> > b/include/linux/iio/adc/ad_sigma_delta.h
> > index 6e9fb1932dde..fb77b2ebe498 100644
> > --- a/include/linux/iio/adc/ad_sigma_delta.h
> > +++ b/include/linux/iio/adc/ad_sigma_delta.h
> > @@ -79,7 +79,8 @@ struct ad_sigma_delta {
> >        * DMA (thus cache coherency maintenance) requires the
> >        * transfer buffers to live in their own cache lines.
> >        */
> > -     uint8_t                         data[4] ____cacheline_aligned;
> > +     uint8_t                         reg_data[4]
> > ____cacheline_aligned;
> > +     uint8_t                         buf_data[16];
> >  };
> > 
> >  static inline int ad_sigma_delta_set_channel(struct ad_sigma_delta
> > *sd,
> 
> 

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

* [PATCH V2] iio: ad_sigma_delta: Don't put SPI transfer buffer on the stack
  2019-04-09  7:58 [PATCH] iio: ad_sigma_delta: Don't put SPI transfer buffer on the stack Alexandru Ardelean
  2019-04-14 12:45 ` Jonathan Cameron
@ 2019-04-16  8:19 ` Alexandru Ardelean
  2019-04-22  8:56   ` Jonathan Cameron
  1 sibling, 1 reply; 10+ messages in thread
From: Alexandru Ardelean @ 2019-04-16  8:19 UTC (permalink / raw)
  To: linux-iio; +Cc: Lars-Peter Clausen, Alexandru Ardelean

From: Lars-Peter Clausen <lars@metafoo.de>

Use a heap allocated memory for the SPI transfer buffer. Using stack memory
will not work on some architectures when using DMA.

This also avoids potential stack corruption, as it makes sure that the
buffer is in it's own cacheline and (obviously) not on the stack.

Fixes: af3008485ea03 ("iio:adc: Add common code for ADI Sigma Delta devices")
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
Changelog v1 -> v2:
* added ____cacheline_aligned to `buf_data`
* extended comment about cacheline
* added fixes tag

 drivers/iio/adc/ad_sigma_delta.c       | 22 +++++++++++-----------
 include/linux/iio/adc/ad_sigma_delta.h |  3 ++-
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index af6cbc683214..02d9049b9218 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -58,7 +58,7 @@ EXPORT_SYMBOL_GPL(ad_sd_set_comm);
 int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
 	unsigned int size, unsigned int val)
 {
-	uint8_t *data = sigma_delta->data;
+	uint8_t *data = sigma_delta->reg_data;
 	struct spi_transfer t = {
 		.tx_buf		= data,
 		.len		= size + 1,
@@ -102,7 +102,7 @@ EXPORT_SYMBOL_GPL(ad_sd_write_reg);
 static int ad_sd_read_reg_raw(struct ad_sigma_delta *sigma_delta,
 	unsigned int reg, unsigned int size, uint8_t *val)
 {
-	uint8_t *data = sigma_delta->data;
+	uint8_t *data = sigma_delta->reg_data;
 	int ret;
 	struct spi_transfer t[] = {
 		{
@@ -148,24 +148,24 @@ int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta,
 {
 	int ret;
 
-	ret = ad_sd_read_reg_raw(sigma_delta, reg, size, sigma_delta->data);
+	ret = ad_sd_read_reg_raw(sigma_delta, reg, size, sigma_delta->reg_data);
 	if (ret < 0)
 		goto out;
 
 	switch (size) {
 	case 4:
-		*val = get_unaligned_be32(sigma_delta->data);
+		*val = get_unaligned_be32(sigma_delta->reg_data);
 		break;
 	case 3:
-		*val = (sigma_delta->data[0] << 16) |
-			(sigma_delta->data[1] << 8) |
-			sigma_delta->data[2];
+		*val = (sigma_delta->reg_data[0] << 16) |
+			(sigma_delta->reg_data[1] << 8) |
+			sigma_delta->reg_data[2];
 		break;
 	case 2:
-		*val = get_unaligned_be16(sigma_delta->data);
+		*val = get_unaligned_be16(sigma_delta->reg_data);
 		break;
 	case 1:
-		*val = sigma_delta->data[0];
+		*val = sigma_delta->reg_data[0];
 		break;
 	default:
 		ret = -EINVAL;
@@ -403,12 +403,12 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
+	uint8_t *data = sigma_delta->buf_data;
 	unsigned int reg_size;
 	unsigned int data_reg;
-	uint8_t data[16];
 	int ret;
 
-	memset(data, 0x00, 16);
+	memset(sigma_delta->buf_data, 0x00, sizeof(sigma_delta->buf_data));
 
 	reg_size = indio_dev->channels[0].scan_type.realbits +
 			indio_dev->channels[0].scan_type.shift;
diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
index 6e9fb1932dde..d95216ce8a94 100644
--- a/include/linux/iio/adc/ad_sigma_delta.h
+++ b/include/linux/iio/adc/ad_sigma_delta.h
@@ -79,7 +79,8 @@ struct ad_sigma_delta {
 	 * DMA (thus cache coherency maintenance) requires the
 	 * transfer buffers to live in their own cache lines.
 	 */
-	uint8_t				data[4] ____cacheline_aligned;
+	uint8_t				reg_data[4] ____cacheline_aligned;
+	uint8_t				buf_data[16] ____cacheline_aligned;
 };
 
 static inline int ad_sigma_delta_set_channel(struct ad_sigma_delta *sd,
-- 
2.17.1


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

* Re: [PATCH V2] iio: ad_sigma_delta: Don't put SPI transfer buffer on the stack
  2019-04-16  8:19 ` [PATCH V2] " Alexandru Ardelean
@ 2019-04-22  8:56   ` Jonathan Cameron
  2019-04-22 10:28     ` Ardelean, Alexandru
  0 siblings, 1 reply; 10+ messages in thread
From: Jonathan Cameron @ 2019-04-22  8:56 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: linux-iio, Lars-Peter Clausen

On Tue, 16 Apr 2019 11:19:16 +0300
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> From: Lars-Peter Clausen <lars@metafoo.de>
> 
> Use a heap allocated memory for the SPI transfer buffer. Using stack memory
> will not work on some architectures when using DMA.
> 
> This also avoids potential stack corruption, as it makes sure that the
> buffer is in it's own cacheline and (obviously) not on the stack.
> 
> Fixes: af3008485ea03 ("iio:adc: Add common code for ADI Sigma Delta devices")
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Hi Alex,

Thanks for the update.

I'm unclear why we can't just use one large buffer for both cases?
i.e put the reg_data usecases in the buf_data buffer (renamed).

Jonathan
> ---
> Changelog v1 -> v2:
> * added ____cacheline_aligned to `buf_data`
> * extended comment about cacheline
> * added fixes tag
> 
>  drivers/iio/adc/ad_sigma_delta.c       | 22 +++++++++++-----------
>  include/linux/iio/adc/ad_sigma_delta.h |  3 ++-
>  2 files changed, 13 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
> index af6cbc683214..02d9049b9218 100644
> --- a/drivers/iio/adc/ad_sigma_delta.c
> +++ b/drivers/iio/adc/ad_sigma_delta.c
> @@ -58,7 +58,7 @@ EXPORT_SYMBOL_GPL(ad_sd_set_comm);
>  int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
>  	unsigned int size, unsigned int val)
>  {
> -	uint8_t *data = sigma_delta->data;
> +	uint8_t *data = sigma_delta->reg_data;
>  	struct spi_transfer t = {
>  		.tx_buf		= data,
>  		.len		= size + 1,
> @@ -102,7 +102,7 @@ EXPORT_SYMBOL_GPL(ad_sd_write_reg);
>  static int ad_sd_read_reg_raw(struct ad_sigma_delta *sigma_delta,
>  	unsigned int reg, unsigned int size, uint8_t *val)
>  {
> -	uint8_t *data = sigma_delta->data;
> +	uint8_t *data = sigma_delta->reg_data;
>  	int ret;
>  	struct spi_transfer t[] = {
>  		{
> @@ -148,24 +148,24 @@ int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta,
>  {
>  	int ret;
>  
> -	ret = ad_sd_read_reg_raw(sigma_delta, reg, size, sigma_delta->data);
> +	ret = ad_sd_read_reg_raw(sigma_delta, reg, size, sigma_delta->reg_data);
>  	if (ret < 0)
>  		goto out;
>  
>  	switch (size) {
>  	case 4:
> -		*val = get_unaligned_be32(sigma_delta->data);
> +		*val = get_unaligned_be32(sigma_delta->reg_data);
>  		break;
>  	case 3:
> -		*val = (sigma_delta->data[0] << 16) |
> -			(sigma_delta->data[1] << 8) |
> -			sigma_delta->data[2];
> +		*val = (sigma_delta->reg_data[0] << 16) |
> +			(sigma_delta->reg_data[1] << 8) |
> +			sigma_delta->reg_data[2];
>  		break;
>  	case 2:
> -		*val = get_unaligned_be16(sigma_delta->data);
> +		*val = get_unaligned_be16(sigma_delta->reg_data);
>  		break;
>  	case 1:
> -		*val = sigma_delta->data[0];
> +		*val = sigma_delta->reg_data[0];
>  		break;
>  	default:
>  		ret = -EINVAL;
> @@ -403,12 +403,12 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
>  	struct iio_poll_func *pf = p;
>  	struct iio_dev *indio_dev = pf->indio_dev;
>  	struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
> +	uint8_t *data = sigma_delta->buf_data;
>  	unsigned int reg_size;
>  	unsigned int data_reg;
> -	uint8_t data[16];
>  	int ret;
>  
> -	memset(data, 0x00, 16);
> +	memset(sigma_delta->buf_data, 0x00, sizeof(sigma_delta->buf_data));
>  
>  	reg_size = indio_dev->channels[0].scan_type.realbits +
>  			indio_dev->channels[0].scan_type.shift;
> diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
> index 6e9fb1932dde..d95216ce8a94 100644
> --- a/include/linux/iio/adc/ad_sigma_delta.h
> +++ b/include/linux/iio/adc/ad_sigma_delta.h
> @@ -79,7 +79,8 @@ struct ad_sigma_delta {
>  	 * DMA (thus cache coherency maintenance) requires the
>  	 * transfer buffers to live in their own cache lines.
>  	 */
> -	uint8_t				data[4] ____cacheline_aligned;
> +	uint8_t				reg_data[4] ____cacheline_aligned;
> +	uint8_t				buf_data[16] ____cacheline_aligned;
The usual assumption is that a device is safe against itself, so we can't
get cacheline corruption in a single action from the device to itself.
This does make me wonder why we have two buffers like this at all though!

>  };
>  
>  static inline int ad_sigma_delta_set_channel(struct ad_sigma_delta *sd,


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

* Re: [PATCH V2] iio: ad_sigma_delta: Don't put SPI transfer buffer on the stack
  2019-04-22  8:56   ` Jonathan Cameron
@ 2019-04-22 10:28     ` Ardelean, Alexandru
  0 siblings, 0 replies; 10+ messages in thread
From: Ardelean, Alexandru @ 2019-04-22 10:28 UTC (permalink / raw)
  To: jic23; +Cc: lars, linux-iio

On Mon, 2019-04-22 at 09:56 +0100, Jonathan Cameron wrote:
> [External]
> 
> 
> On Tue, 16 Apr 2019 11:19:16 +0300
> Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:
> 
> > From: Lars-Peter Clausen <lars@metafoo.de>
> > 
> > Use a heap allocated memory for the SPI transfer buffer. Using stack
> > memory
> > will not work on some architectures when using DMA.
> > 
> > This also avoids potential stack corruption, as it makes sure that the
> > buffer is in it's own cacheline and (obviously) not on the stack.
> > 
> > Fixes: af3008485ea03 ("iio:adc: Add common code for ADI Sigma Delta
> > devices")
> > Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> 
> Hi Alex,
> 
> Thanks for the update.
> 
> I'm unclear why we can't just use one large buffer for both cases?
> i.e put the reg_data usecases in the buf_data buffer (renamed).
> 

That's a good point.
I didn't think much of it.


Looking through the code, the only argument for doing it like this
(separate buffer) is that the change is less complicated to look at, since
it makes no assumptions about offset in the buffer.

At a later point in time, this `buf_data` will be replaced with a kzalloc-
ed buffer [when adding sequencer support for SigmaDelta].

It may only make sense to have this change [whether 2 buffers or a single
buffer] for stable, to fix the cacheline issue.

I'll take a closer look at this.
It should work well to just increase the existing buffer and re-use that.


> Jonathan
> > ---
> > Changelog v1 -> v2:
> > * added ____cacheline_aligned to `buf_data`
> > * extended comment about cacheline
> > * added fixes tag
> > 
> >  drivers/iio/adc/ad_sigma_delta.c       | 22 +++++++++++-----------
> >  include/linux/iio/adc/ad_sigma_delta.h |  3 ++-
> >  2 files changed, 13 insertions(+), 12 deletions(-)
> > 
> > diff --git a/drivers/iio/adc/ad_sigma_delta.c
> > b/drivers/iio/adc/ad_sigma_delta.c
> > index af6cbc683214..02d9049b9218 100644
> > --- a/drivers/iio/adc/ad_sigma_delta.c
> > +++ b/drivers/iio/adc/ad_sigma_delta.c
> > @@ -58,7 +58,7 @@ EXPORT_SYMBOL_GPL(ad_sd_set_comm);
> >  int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, unsigned int
> > reg,
> >       unsigned int size, unsigned int val)
> >  {
> > -     uint8_t *data = sigma_delta->data;
> > +     uint8_t *data = sigma_delta->reg_data;
> >       struct spi_transfer t = {
> >               .tx_buf         = data,
> >               .len            = size + 1,
> > @@ -102,7 +102,7 @@ EXPORT_SYMBOL_GPL(ad_sd_write_reg);
> >  static int ad_sd_read_reg_raw(struct ad_sigma_delta *sigma_delta,
> >       unsigned int reg, unsigned int size, uint8_t *val)
> >  {
> > -     uint8_t *data = sigma_delta->data;
> > +     uint8_t *data = sigma_delta->reg_data;
> >       int ret;
> >       struct spi_transfer t[] = {
> >               {
> > @@ -148,24 +148,24 @@ int ad_sd_read_reg(struct ad_sigma_delta
> > *sigma_delta,
> >  {
> >       int ret;
> > 
> > -     ret = ad_sd_read_reg_raw(sigma_delta, reg, size, sigma_delta-
> > >data);
> > +     ret = ad_sd_read_reg_raw(sigma_delta, reg, size, sigma_delta-
> > >reg_data);
> >       if (ret < 0)
> >               goto out;
> > 
> >       switch (size) {
> >       case 4:
> > -             *val = get_unaligned_be32(sigma_delta->data);
> > +             *val = get_unaligned_be32(sigma_delta->reg_data);
> >               break;
> >       case 3:
> > -             *val = (sigma_delta->data[0] << 16) |
> > -                     (sigma_delta->data[1] << 8) |
> > -                     sigma_delta->data[2];
> > +             *val = (sigma_delta->reg_data[0] << 16) |
> > +                     (sigma_delta->reg_data[1] << 8) |
> > +                     sigma_delta->reg_data[2];
> >               break;
> >       case 2:
> > -             *val = get_unaligned_be16(sigma_delta->data);
> > +             *val = get_unaligned_be16(sigma_delta->reg_data);
> >               break;
> >       case 1:
> > -             *val = sigma_delta->data[0];
> > +             *val = sigma_delta->reg_data[0];
> >               break;
> >       default:
> >               ret = -EINVAL;
> > @@ -403,12 +403,12 @@ static irqreturn_t ad_sd_trigger_handler(int irq,
> > void *p)
> >       struct iio_poll_func *pf = p;
> >       struct iio_dev *indio_dev = pf->indio_dev;
> >       struct ad_sigma_delta *sigma_delta =
> > iio_device_get_drvdata(indio_dev);
> > +     uint8_t *data = sigma_delta->buf_data;
> >       unsigned int reg_size;
> >       unsigned int data_reg;
> > -     uint8_t data[16];
> >       int ret;
> > 
> > -     memset(data, 0x00, 16);
> > +     memset(sigma_delta->buf_data, 0x00, sizeof(sigma_delta-
> > >buf_data));
> > 
> >       reg_size = indio_dev->channels[0].scan_type.realbits +
> >                       indio_dev->channels[0].scan_type.shift;
> > diff --git a/include/linux/iio/adc/ad_sigma_delta.h
> > b/include/linux/iio/adc/ad_sigma_delta.h
> > index 6e9fb1932dde..d95216ce8a94 100644
> > --- a/include/linux/iio/adc/ad_sigma_delta.h
> > +++ b/include/linux/iio/adc/ad_sigma_delta.h
> > @@ -79,7 +79,8 @@ struct ad_sigma_delta {
> >        * DMA (thus cache coherency maintenance) requires the
> >        * transfer buffers to live in their own cache lines.
> >        */
> > -     uint8_t                         data[4] ____cacheline_aligned;
> > +     uint8_t                         reg_data[4]
> > ____cacheline_aligned;
> > +     uint8_t                         buf_data[16]
> > ____cacheline_aligned;
> 
> The usual assumption is that a device is safe against itself, so we can't
> get cacheline corruption in a single action from the device to itself.
> This does make me wonder why we have two buffers like this at all though!
> >  };
> > 
> >  static inline int ad_sigma_delta_set_channel(struct ad_sigma_delta
> > *sd,
> 
> 

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

* Re: [PATCH] iio: ad_sigma_delta: Don't put SPI transfer buffer on the stack
  2020-11-12 10:14   ` Alexandru Ardelean
@ 2020-11-12 10:52     ` Lars-Peter Clausen
  0 siblings, 0 replies; 10+ messages in thread
From: Lars-Peter Clausen @ 2020-11-12 10:52 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: Alexandru Ardelean, linux-iio, LKML, Jonathan Cameron

On 11/12/20 11:14 AM, Alexandru Ardelean wrote:
> On Thu, Nov 12, 2020 at 11:55 AM Lars-Peter Clausen <lars@metafoo.de> wrote:
>> On 11/12/20 10:10 AM, Alexandru Ardelean wrote:
>>> From: Lars-Peter Clausen <lars@metafoo.de>
>>>
>>> Use a heap allocated memory for the SPI transfer buffer. Using stack memory
>>> can corrupt stack memory when using DMA on some systems.
>>>
>>> This change adds 4 bytes at the end of the current DMA buffer, which will
>>> be used by the trigger handler.
>>> This is required because the first 4 bytes are reserved for register data.
>>>
>>> Fixes: af3008485ea03 ("iio:adc: Add common code for ADI Sigma Delta devices")
>>> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
>>> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
>>> ---
>>>    drivers/iio/adc/ad_sigma_delta.c       | 4 ++--
>>>    include/linux/iio/adc/ad_sigma_delta.h | 2 +-
>>>    2 files changed, 3 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
>>> index 86039e9ecaca..33297f26508a 100644
>>> --- a/drivers/iio/adc/ad_sigma_delta.c
>>> +++ b/drivers/iio/adc/ad_sigma_delta.c
>>> @@ -395,11 +395,11 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
>>>        struct iio_poll_func *pf = p;
>>>        struct iio_dev *indio_dev = pf->indio_dev;
>>>        struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
>>> +     uint8_t *data = &sigma_delta->data[4];
>>>        unsigned int reg_size;
>>>        unsigned int data_reg;
>>> -     uint8_t data[16];
>>>
>>> -     memset(data, 0x00, 16);
>>> +     memset(data, 0x00, 4);
>> Younger me didn't know what he was doing, this is wrong. We need the
>> extra space for the padding and timestamp.
>>
>> We also can't put the beginning of the buffer at an 4 byte offset since
>> it needs to be 8 byte aligned for the timestamp.
> I'll correct this.
> I was re-spinning this out of some old patches and discussions on this
> that I have.
> So, then this becomes 24 bytes? Or 16?
>
> Something like:
> uint8_t                         data[24] ____cacheline_aligned;
>
> uint8_t *data = &sigma_delta->data[8];

Yes.


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

* Re: [PATCH] iio: ad_sigma_delta: Don't put SPI transfer buffer on the stack
  2020-11-12  9:54 ` Lars-Peter Clausen
@ 2020-11-12 10:14   ` Alexandru Ardelean
  2020-11-12 10:52     ` Lars-Peter Clausen
  0 siblings, 1 reply; 10+ messages in thread
From: Alexandru Ardelean @ 2020-11-12 10:14 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: Alexandru Ardelean, linux-iio, LKML, Jonathan Cameron

On Thu, Nov 12, 2020 at 11:55 AM Lars-Peter Clausen <lars@metafoo.de> wrote:
>
> On 11/12/20 10:10 AM, Alexandru Ardelean wrote:
> > From: Lars-Peter Clausen <lars@metafoo.de>
> >
> > Use a heap allocated memory for the SPI transfer buffer. Using stack memory
> > can corrupt stack memory when using DMA on some systems.
> >
> > This change adds 4 bytes at the end of the current DMA buffer, which will
> > be used by the trigger handler.
> > This is required because the first 4 bytes are reserved for register data.
> >
> > Fixes: af3008485ea03 ("iio:adc: Add common code for ADI Sigma Delta devices")
> > Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> > ---
> >   drivers/iio/adc/ad_sigma_delta.c       | 4 ++--
> >   include/linux/iio/adc/ad_sigma_delta.h | 2 +-
> >   2 files changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
> > index 86039e9ecaca..33297f26508a 100644
> > --- a/drivers/iio/adc/ad_sigma_delta.c
> > +++ b/drivers/iio/adc/ad_sigma_delta.c
> > @@ -395,11 +395,11 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
> >       struct iio_poll_func *pf = p;
> >       struct iio_dev *indio_dev = pf->indio_dev;
> >       struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
> > +     uint8_t *data = &sigma_delta->data[4];
> >       unsigned int reg_size;
> >       unsigned int data_reg;
> > -     uint8_t data[16];
> >
> > -     memset(data, 0x00, 16);
> > +     memset(data, 0x00, 4);
>
> Younger me didn't know what he was doing, this is wrong. We need the
> extra space for the padding and timestamp.
>
> We also can't put the beginning of the buffer at an 4 byte offset since
> it needs to be 8 byte aligned for the timestamp.

I'll correct this.
I was re-spinning this out of some old patches and discussions on this
that I have.
So, then this becomes 24 bytes? Or 16?

Something like:
uint8_t                         data[24] ____cacheline_aligned;

uint8_t *data = &sigma_delta->data[8];


>
> >
> >       reg_size = indio_dev->channels[0].scan_type.realbits +
> >                       indio_dev->channels[0].scan_type.shift;
> > diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
> > index a3a838dcf8e4..ac4ac4752c62 100644
> > --- a/include/linux/iio/adc/ad_sigma_delta.h
> > +++ b/include/linux/iio/adc/ad_sigma_delta.h
> > @@ -80,7 +80,7 @@ struct ad_sigma_delta {
> >        * DMA (thus cache coherency maintenance) requires the
> >        * transfer buffers to live in their own cache lines.
> >        */
> > -     uint8_t                         data[4] ____cacheline_aligned;
> > +     uint8_t                         data[8] ____cacheline_aligned;
> >   };
> >
> >   static inline int ad_sigma_delta_set_channel(struct ad_sigma_delta *sd,
>
>

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

* Re: [PATCH] iio: ad_sigma_delta: Don't put SPI transfer buffer on the stack
  2020-11-12  9:10 [PATCH] " Alexandru Ardelean
@ 2020-11-12  9:54 ` Lars-Peter Clausen
  2020-11-12 10:14   ` Alexandru Ardelean
  0 siblings, 1 reply; 10+ messages in thread
From: Lars-Peter Clausen @ 2020-11-12  9:54 UTC (permalink / raw)
  To: Alexandru Ardelean, linux-iio, linux-kernel; +Cc: jic23

On 11/12/20 10:10 AM, Alexandru Ardelean wrote:
> From: Lars-Peter Clausen <lars@metafoo.de>
>
> Use a heap allocated memory for the SPI transfer buffer. Using stack memory
> can corrupt stack memory when using DMA on some systems.
>
> This change adds 4 bytes at the end of the current DMA buffer, which will
> be used by the trigger handler.
> This is required because the first 4 bytes are reserved for register data.
>
> Fixes: af3008485ea03 ("iio:adc: Add common code for ADI Sigma Delta devices")
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> ---
>   drivers/iio/adc/ad_sigma_delta.c       | 4 ++--
>   include/linux/iio/adc/ad_sigma_delta.h | 2 +-
>   2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
> index 86039e9ecaca..33297f26508a 100644
> --- a/drivers/iio/adc/ad_sigma_delta.c
> +++ b/drivers/iio/adc/ad_sigma_delta.c
> @@ -395,11 +395,11 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
>   	struct iio_poll_func *pf = p;
>   	struct iio_dev *indio_dev = pf->indio_dev;
>   	struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
> +	uint8_t *data = &sigma_delta->data[4];
>   	unsigned int reg_size;
>   	unsigned int data_reg;
> -	uint8_t data[16];
>   
> -	memset(data, 0x00, 16);
> +	memset(data, 0x00, 4);

Younger me didn't know what he was doing, this is wrong. We need the 
extra space for the padding and timestamp.

We also can't put the beginning of the buffer at an 4 byte offset since 
it needs to be 8 byte aligned for the timestamp.

>   
>   	reg_size = indio_dev->channels[0].scan_type.realbits +
>   			indio_dev->channels[0].scan_type.shift;
> diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
> index a3a838dcf8e4..ac4ac4752c62 100644
> --- a/include/linux/iio/adc/ad_sigma_delta.h
> +++ b/include/linux/iio/adc/ad_sigma_delta.h
> @@ -80,7 +80,7 @@ struct ad_sigma_delta {
>   	 * DMA (thus cache coherency maintenance) requires the
>   	 * transfer buffers to live in their own cache lines.
>   	 */
> -	uint8_t				data[4] ____cacheline_aligned;
> +	uint8_t				data[8] ____cacheline_aligned;
>   };
>   
>   static inline int ad_sigma_delta_set_channel(struct ad_sigma_delta *sd,



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

* [PATCH] iio: ad_sigma_delta: Don't put SPI transfer buffer on the stack
@ 2020-11-12  9:10 Alexandru Ardelean
  2020-11-12  9:54 ` Lars-Peter Clausen
  0 siblings, 1 reply; 10+ messages in thread
From: Alexandru Ardelean @ 2020-11-12  9:10 UTC (permalink / raw)
  To: linux-iio, linux-kernel; +Cc: alexandru.ardelean, lars, jic23

From: Lars-Peter Clausen <lars@metafoo.de>

Use a heap allocated memory for the SPI transfer buffer. Using stack memory
can corrupt stack memory when using DMA on some systems.

This change adds 4 bytes at the end of the current DMA buffer, which will
be used by the trigger handler.
This is required because the first 4 bytes are reserved for register data.

Fixes: af3008485ea03 ("iio:adc: Add common code for ADI Sigma Delta devices")
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/adc/ad_sigma_delta.c       | 4 ++--
 include/linux/iio/adc/ad_sigma_delta.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 86039e9ecaca..33297f26508a 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -395,11 +395,11 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
+	uint8_t *data = &sigma_delta->data[4];
 	unsigned int reg_size;
 	unsigned int data_reg;
-	uint8_t data[16];
 
-	memset(data, 0x00, 16);
+	memset(data, 0x00, 4);
 
 	reg_size = indio_dev->channels[0].scan_type.realbits +
 			indio_dev->channels[0].scan_type.shift;
diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
index a3a838dcf8e4..ac4ac4752c62 100644
--- a/include/linux/iio/adc/ad_sigma_delta.h
+++ b/include/linux/iio/adc/ad_sigma_delta.h
@@ -80,7 +80,7 @@ struct ad_sigma_delta {
 	 * DMA (thus cache coherency maintenance) requires the
 	 * transfer buffers to live in their own cache lines.
 	 */
-	uint8_t				data[4] ____cacheline_aligned;
+	uint8_t				data[8] ____cacheline_aligned;
 };
 
 static inline int ad_sigma_delta_set_channel(struct ad_sigma_delta *sd,
-- 
2.17.1


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

end of thread, other threads:[~2020-11-12 10:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-09  7:58 [PATCH] iio: ad_sigma_delta: Don't put SPI transfer buffer on the stack Alexandru Ardelean
2019-04-14 12:45 ` Jonathan Cameron
2019-04-15  6:52   ` Ardelean, Alexandru
2019-04-16  8:19 ` [PATCH V2] " Alexandru Ardelean
2019-04-22  8:56   ` Jonathan Cameron
2019-04-22 10:28     ` Ardelean, Alexandru
2020-11-12  9:10 [PATCH] " Alexandru Ardelean
2020-11-12  9:54 ` Lars-Peter Clausen
2020-11-12 10:14   ` Alexandru Ardelean
2020-11-12 10:52     ` Lars-Peter Clausen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.