linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] iio: temperature: maxim_thermocouple: use DMA-safe buffer for spi_read()
@ 2025-07-21 23:04 David Lechner
  2025-07-21 23:06 ` David Lechner
  2025-07-22  9:23 ` Nuno Sá
  0 siblings, 2 replies; 5+ messages in thread
From: David Lechner @ 2025-07-21 23:04 UTC (permalink / raw)
  To: Jonathan Cameron, Nuno Sá, Andy Shevchenko, Matt Ranostay
  Cc: linux-iio, linux-kernel, David Lechner

Replace using stack-allocated buffers with a DMA-safe buffer for use
with spi_read(). This allows the driver to be safely used with
DMA-enabled SPI controllers.

The buffer array is also converted to a struct with a union to make the
usage of the memory in the buffer more clear and ensure proper alignment.

Fixes: 1f25ca11d84a ("iio: temperature: add support for Maxim thermocouple chips")
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
Changes in v2:
- This is a new patch since when looking at it again, I noticed a bug
  with passing stack-allocated memory to spi_read(). So now the primary
  purpose is a fix and converting the array to a struct comes free with
  it.
- Link to v1: https://lore.kernel.org/r/20250711-iio-use-more-iio_declare_buffer_with_ts-3-v1-1-f6dd3363fd85@baylibre.com
---
 drivers/iio/temperature/maxim_thermocouple.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c
index cae8e84821d7fd521d59432580d51def939fa4d1..fa648a6542a4e2f08adb556c776b68331ae69631 100644
--- a/drivers/iio/temperature/maxim_thermocouple.c
+++ b/drivers/iio/temperature/maxim_thermocouple.c
@@ -11,6 +11,7 @@
 #include <linux/module.h>
 #include <linux/err.h>
 #include <linux/spi/spi.h>
+#include <linux/types.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
 #include <linux/iio/trigger.h>
@@ -121,8 +122,15 @@ struct maxim_thermocouple_data {
 	struct spi_device *spi;
 	const struct maxim_thermocouple_chip *chip;
 	char tc_type;
-
-	u8 buffer[16] __aligned(IIO_DMA_MINALIGN);
+	/* Buffer for reading up to 2 hardware channels. */
+	struct {
+		union {
+			__be16 raw16;
+			__be32 raw32;
+			__be16 raw[2];
+		};
+		aligned_s64 timestamp;
+	} buffer __aligned(IIO_DMA_MINALIGN);
 };
 
 static int maxim_thermocouple_read(struct maxim_thermocouple_data *data,
@@ -130,18 +138,16 @@ static int maxim_thermocouple_read(struct maxim_thermocouple_data *data,
 {
 	unsigned int storage_bytes = data->chip->read_size;
 	unsigned int shift = chan->scan_type.shift + (chan->address * 8);
-	__be16 buf16;
-	__be32 buf32;
 	int ret;
 
 	switch (storage_bytes) {
 	case 2:
-		ret = spi_read(data->spi, (void *)&buf16, storage_bytes);
-		*val = be16_to_cpu(buf16);
+		ret = spi_read(data->spi, &data->buffer.raw16, storage_bytes);
+		*val = be16_to_cpu(data->buffer.raw16);
 		break;
 	case 4:
-		ret = spi_read(data->spi, (void *)&buf32, storage_bytes);
-		*val = be32_to_cpu(buf32);
+		ret = spi_read(data->spi, &data->buffer.raw32, storage_bytes);
+		*val = be32_to_cpu(data->buffer.raw32);
 		break;
 	default:
 		ret = -EINVAL;
@@ -166,9 +172,9 @@ static irqreturn_t maxim_thermocouple_trigger_handler(int irq, void *private)
 	struct maxim_thermocouple_data *data = iio_priv(indio_dev);
 	int ret;
 
-	ret = spi_read(data->spi, data->buffer, data->chip->read_size);
+	ret = spi_read(data->spi, &data->buffer.raw, data->chip->read_size);
 	if (!ret) {
-		iio_push_to_buffers_with_ts(indio_dev, data->buffer,
+		iio_push_to_buffers_with_ts(indio_dev, &data->buffer,
 					    sizeof(data->buffer),
 					    iio_get_time_ns(indio_dev));
 	}

---
base-commit: cd2731444ee4e35db76f4fb587f12d327eec5446
change-id: 20250711-iio-use-more-iio_declare_buffer_with_ts-3-2cc387a66bdc

Best regards,
-- 
David Lechner <dlechner@baylibre.com>


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

* Re: [PATCH v2] iio: temperature: maxim_thermocouple: use DMA-safe buffer for spi_read()
  2025-07-21 23:04 [PATCH v2] iio: temperature: maxim_thermocouple: use DMA-safe buffer for spi_read() David Lechner
@ 2025-07-21 23:06 ` David Lechner
  2025-07-22  9:24   ` Nuno Sá
  2025-07-22  9:23 ` Nuno Sá
  1 sibling, 1 reply; 5+ messages in thread
From: David Lechner @ 2025-07-21 23:06 UTC (permalink / raw)
  To: Jonathan Cameron, Nuno Sá, Andy Shevchenko, Matt Ranostay
  Cc: linux-iio, linux-kernel

On 7/21/25 6:04 PM, David Lechner wrote:
> Replace using stack-allocated buffers with a DMA-safe buffer for use
> with spi_read(). This allows the driver to be safely used with
> DMA-enabled SPI controllers.
> 
> The buffer array is also converted to a struct with a union to make the
> usage of the memory in the buffer more clear and ensure proper alignment.
> 
> Fixes: 1f25ca11d84a ("iio: temperature: add support for Maxim thermocouple chips")
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
> Changes in v2:
> - This is a new patch since when looking at it again, I noticed a bug
>   with passing stack-allocated memory to spi_read(). So now the primary
>   purpose is a fix and converting the array to a struct comes free with
>   it.
> - Link to v1: https://lore.kernel.org/r/20250711-iio-use-more-iio_declare_buffer_with_ts-3-v1-1-f6dd3363fd85@baylibre.com
> ---
>  drivers/iio/temperature/maxim_thermocouple.c | 26 ++++++++++++++++----------
>  1 file changed, 16 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c
> index cae8e84821d7fd521d59432580d51def939fa4d1..fa648a6542a4e2f08adb556c776b68331ae69631 100644
> --- a/drivers/iio/temperature/maxim_thermocouple.c
> +++ b/drivers/iio/temperature/maxim_thermocouple.c
> @@ -11,6 +11,7 @@
>  #include <linux/module.h>
>  #include <linux/err.h>
>  #include <linux/spi/spi.h>
> +#include <linux/types.h>
>  #include <linux/iio/iio.h>
>  #include <linux/iio/sysfs.h>
>  #include <linux/iio/trigger.h>
> @@ -121,8 +122,15 @@ struct maxim_thermocouple_data {
>  	struct spi_device *spi;
>  	const struct maxim_thermocouple_chip *chip;
>  	char tc_type;
> -
> -	u8 buffer[16] __aligned(IIO_DMA_MINALIGN);
> +	/* Buffer for reading up to 2 hardware channels. */
> +	struct {
> +		union {
> +			__be16 raw16;
> +			__be32 raw32;
> +			__be16 raw[2];
> +		};
> +		aligned_s64 timestamp;
> +	} buffer __aligned(IIO_DMA_MINALIGN);
>  };
>  
>  static int maxim_thermocouple_read(struct maxim_thermocouple_data *data,
> @@ -130,18 +138,16 @@ static int maxim_thermocouple_read(struct maxim_thermocouple_data *data,
>  {
>  	unsigned int storage_bytes = data->chip->read_size;
>  	unsigned int shift = chan->scan_type.shift + (chan->address * 8);
> -	__be16 buf16;
> -	__be32 buf32;
>  	int ret;
>  
>  	switch (storage_bytes) {
>  	case 2:
> -		ret = spi_read(data->spi, (void *)&buf16, storage_bytes);
> -		*val = be16_to_cpu(buf16);
> +		ret = spi_read(data->spi, &data->buffer.raw16, storage_bytes);
> +		*val = be16_to_cpu(data->buffer.raw16);
>  		break;
>  	case 4:
> -		ret = spi_read(data->spi, (void *)&buf32, storage_bytes);
> -		*val = be32_to_cpu(buf32);
> +		ret = spi_read(data->spi, &data->buffer.raw32, storage_bytes);
> +		*val = be32_to_cpu(data->buffer.raw32);
>  		break;
>  	default:
>  		ret = -EINVAL;
> @@ -166,9 +172,9 @@ static irqreturn_t maxim_thermocouple_trigger_handler(int irq, void *private)
>  	struct maxim_thermocouple_data *data = iio_priv(indio_dev);
>  	int ret;
>  
> -	ret = spi_read(data->spi, data->buffer, data->chip->read_size);
> +	ret = spi_read(data->spi, &data->buffer.raw, data->chip->read_size);

Compile check didn't catch this. Need to drop the &.
data->buffer.raw is already an array.


>  	if (!ret) {
> -		iio_push_to_buffers_with_ts(indio_dev, data->buffer,
> +		iio_push_to_buffers_with_ts(indio_dev, &data->buffer,
>  					    sizeof(data->buffer),
>  					    iio_get_time_ns(indio_dev));
>  	}
> 
> ---
> base-commit: cd2731444ee4e35db76f4fb587f12d327eec5446
> change-id: 20250711-iio-use-more-iio_declare_buffer_with_ts-3-2cc387a66bdc
> 
> Best regards,


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

* Re: [PATCH v2] iio: temperature: maxim_thermocouple: use DMA-safe buffer for spi_read()
  2025-07-21 23:04 [PATCH v2] iio: temperature: maxim_thermocouple: use DMA-safe buffer for spi_read() David Lechner
  2025-07-21 23:06 ` David Lechner
@ 2025-07-22  9:23 ` Nuno Sá
  1 sibling, 0 replies; 5+ messages in thread
From: Nuno Sá @ 2025-07-22  9:23 UTC (permalink / raw)
  To: David Lechner
  Cc: Jonathan Cameron, Nuno Sá, Andy Shevchenko, Matt Ranostay,
	linux-iio, linux-kernel

On Mon, Jul 21, 2025 at 06:04:04PM -0500, David Lechner wrote:
> Replace using stack-allocated buffers with a DMA-safe buffer for use
> with spi_read(). This allows the driver to be safely used with
> DMA-enabled SPI controllers.
> 
> The buffer array is also converted to a struct with a union to make the
> usage of the memory in the buffer more clear and ensure proper alignment.
> 
> Fixes: 1f25ca11d84a ("iio: temperature: add support for Maxim thermocouple chips")
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
> Changes in v2:
> - This is a new patch since when looking at it again, I noticed a bug
>   with passing stack-allocated memory to spi_read(). So now the primary
>   purpose is a fix and converting the array to a struct comes free with
>   it.
> - Link to v1: https://lore.kernel.org/r/20250711-iio-use-more-iio_declare_buffer_with_ts-3-v1-1-f6dd3363fd85@baylibre.com
> ---

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

>  drivers/iio/temperature/maxim_thermocouple.c | 26 ++++++++++++++++----------
>  1 file changed, 16 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c
> index cae8e84821d7fd521d59432580d51def939fa4d1..fa648a6542a4e2f08adb556c776b68331ae69631 100644
> --- a/drivers/iio/temperature/maxim_thermocouple.c
> +++ b/drivers/iio/temperature/maxim_thermocouple.c
> @@ -11,6 +11,7 @@
>  #include <linux/module.h>
>  #include <linux/err.h>
>  #include <linux/spi/spi.h>
> +#include <linux/types.h>
>  #include <linux/iio/iio.h>
>  #include <linux/iio/sysfs.h>
>  #include <linux/iio/trigger.h>
> @@ -121,8 +122,15 @@ struct maxim_thermocouple_data {
>  	struct spi_device *spi;
>  	const struct maxim_thermocouple_chip *chip;
>  	char tc_type;
> -
> -	u8 buffer[16] __aligned(IIO_DMA_MINALIGN);
> +	/* Buffer for reading up to 2 hardware channels. */
> +	struct {
> +		union {
> +			__be16 raw16;
> +			__be32 raw32;
> +			__be16 raw[2];
> +		};
> +		aligned_s64 timestamp;
> +	} buffer __aligned(IIO_DMA_MINALIGN);
>  };
>  
>  static int maxim_thermocouple_read(struct maxim_thermocouple_data *data,
> @@ -130,18 +138,16 @@ static int maxim_thermocouple_read(struct maxim_thermocouple_data *data,
>  {
>  	unsigned int storage_bytes = data->chip->read_size;
>  	unsigned int shift = chan->scan_type.shift + (chan->address * 8);
> -	__be16 buf16;
> -	__be32 buf32;
>  	int ret;
>  
>  	switch (storage_bytes) {
>  	case 2:
> -		ret = spi_read(data->spi, (void *)&buf16, storage_bytes);
> -		*val = be16_to_cpu(buf16);
> +		ret = spi_read(data->spi, &data->buffer.raw16, storage_bytes);
> +		*val = be16_to_cpu(data->buffer.raw16);
>  		break;
>  	case 4:
> -		ret = spi_read(data->spi, (void *)&buf32, storage_bytes);
> -		*val = be32_to_cpu(buf32);
> +		ret = spi_read(data->spi, &data->buffer.raw32, storage_bytes);
> +		*val = be32_to_cpu(data->buffer.raw32);
>  		break;
>  	default:
>  		ret = -EINVAL;
> @@ -166,9 +172,9 @@ static irqreturn_t maxim_thermocouple_trigger_handler(int irq, void *private)
>  	struct maxim_thermocouple_data *data = iio_priv(indio_dev);
>  	int ret;
>  
> -	ret = spi_read(data->spi, data->buffer, data->chip->read_size);
> +	ret = spi_read(data->spi, &data->buffer.raw, data->chip->read_size);
>  	if (!ret) {
> -		iio_push_to_buffers_with_ts(indio_dev, data->buffer,
> +		iio_push_to_buffers_with_ts(indio_dev, &data->buffer,
>  					    sizeof(data->buffer),
>  					    iio_get_time_ns(indio_dev));
>  	}
> 
> ---
> base-commit: cd2731444ee4e35db76f4fb587f12d327eec5446
> change-id: 20250711-iio-use-more-iio_declare_buffer_with_ts-3-2cc387a66bdc
> 
> Best regards,
> -- 
> David Lechner <dlechner@baylibre.com>
> 

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

* Re: [PATCH v2] iio: temperature: maxim_thermocouple: use DMA-safe buffer for spi_read()
  2025-07-21 23:06 ` David Lechner
@ 2025-07-22  9:24   ` Nuno Sá
  2025-07-24 11:15     ` Jonathan Cameron
  0 siblings, 1 reply; 5+ messages in thread
From: Nuno Sá @ 2025-07-22  9:24 UTC (permalink / raw)
  To: David Lechner
  Cc: Jonathan Cameron, Nuno Sá, Andy Shevchenko, Matt Ranostay,
	linux-iio, linux-kernel

On Mon, Jul 21, 2025 at 06:06:39PM -0500, David Lechner wrote:
> On 7/21/25 6:04 PM, David Lechner wrote:
> > Replace using stack-allocated buffers with a DMA-safe buffer for use
> > with spi_read(). This allows the driver to be safely used with
> > DMA-enabled SPI controllers.
> > 
> > The buffer array is also converted to a struct with a union to make the
> > usage of the memory in the buffer more clear and ensure proper alignment.
> > 
> > Fixes: 1f25ca11d84a ("iio: temperature: add support for Maxim thermocouple chips")
> > Signed-off-by: David Lechner <dlechner@baylibre.com>
> > ---
> > Changes in v2:
> > - This is a new patch since when looking at it again, I noticed a bug
> >   with passing stack-allocated memory to spi_read(). So now the primary
> >   purpose is a fix and converting the array to a struct comes free with
> >   it.
> > - Link to v1: https://lore.kernel.org/r/20250711-iio-use-more-iio_declare_buffer_with_ts-3-v1-1-f6dd3363fd85@baylibre.com
> > ---
> >  drivers/iio/temperature/maxim_thermocouple.c | 26 ++++++++++++++++----------
> >  1 file changed, 16 insertions(+), 10 deletions(-)
> > 
> > diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c
> > index cae8e84821d7fd521d59432580d51def939fa4d1..fa648a6542a4e2f08adb556c776b68331ae69631 100644
> > --- a/drivers/iio/temperature/maxim_thermocouple.c
> > +++ b/drivers/iio/temperature/maxim_thermocouple.c
> > @@ -11,6 +11,7 @@
> >  #include <linux/module.h>
> >  #include <linux/err.h>
> >  #include <linux/spi/spi.h>
> > +#include <linux/types.h>
> >  #include <linux/iio/iio.h>
> >  #include <linux/iio/sysfs.h>
> >  #include <linux/iio/trigger.h>
> > @@ -121,8 +122,15 @@ struct maxim_thermocouple_data {
> >  	struct spi_device *spi;
> >  	const struct maxim_thermocouple_chip *chip;
> >  	char tc_type;
> > -
> > -	u8 buffer[16] __aligned(IIO_DMA_MINALIGN);
> > +	/* Buffer for reading up to 2 hardware channels. */
> > +	struct {
> > +		union {
> > +			__be16 raw16;
> > +			__be32 raw32;
> > +			__be16 raw[2];
> > +		};
> > +		aligned_s64 timestamp;
> > +	} buffer __aligned(IIO_DMA_MINALIGN);
> >  };
> >  
> >  static int maxim_thermocouple_read(struct maxim_thermocouple_data *data,
> > @@ -130,18 +138,16 @@ static int maxim_thermocouple_read(struct maxim_thermocouple_data *data,
> >  {
> >  	unsigned int storage_bytes = data->chip->read_size;
> >  	unsigned int shift = chan->scan_type.shift + (chan->address * 8);
> > -	__be16 buf16;
> > -	__be32 buf32;
> >  	int ret;
> >  
> >  	switch (storage_bytes) {
> >  	case 2:
> > -		ret = spi_read(data->spi, (void *)&buf16, storage_bytes);
> > -		*val = be16_to_cpu(buf16);
> > +		ret = spi_read(data->spi, &data->buffer.raw16, storage_bytes);
> > +		*val = be16_to_cpu(data->buffer.raw16);
> >  		break;
> >  	case 4:
> > -		ret = spi_read(data->spi, (void *)&buf32, storage_bytes);
> > -		*val = be32_to_cpu(buf32);
> > +		ret = spi_read(data->spi, &data->buffer.raw32, storage_bytes);
> > +		*val = be32_to_cpu(data->buffer.raw32);
> >  		break;
> >  	default:
> >  		ret = -EINVAL;
> > @@ -166,9 +172,9 @@ static irqreturn_t maxim_thermocouple_trigger_handler(int irq, void *private)
> >  	struct maxim_thermocouple_data *data = iio_priv(indio_dev);
> >  	int ret;
> >  
> > -	ret = spi_read(data->spi, data->buffer, data->chip->read_size);
> > +	ret = spi_read(data->spi, &data->buffer.raw, data->chip->read_size);
> 
> Compile check didn't catch this. Need to drop the &.
> data->buffer.raw is already an array.

Neither did I :). I should have looked into this email __before__ (and
not after) sending my tag. Anyways, consider the tag with the above
fixed.

- Nuno Sá

> 
> 
> >  	if (!ret) {
> > -		iio_push_to_buffers_with_ts(indio_dev, data->buffer,
> > +		iio_push_to_buffers_with_ts(indio_dev, &data->buffer,
> >  					    sizeof(data->buffer),
> >  					    iio_get_time_ns(indio_dev));
> >  	}
> > 
> > ---
> > base-commit: cd2731444ee4e35db76f4fb587f12d327eec5446
> > change-id: 20250711-iio-use-more-iio_declare_buffer_with_ts-3-2cc387a66bdc
> > 
> > Best regards,
> 

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

* Re: [PATCH v2] iio: temperature: maxim_thermocouple: use DMA-safe buffer for spi_read()
  2025-07-22  9:24   ` Nuno Sá
@ 2025-07-24 11:15     ` Jonathan Cameron
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2025-07-24 11:15 UTC (permalink / raw)
  To: Nuno Sá
  Cc: David Lechner, Nuno Sá, Andy Shevchenko, Matt Ranostay,
	linux-iio, linux-kernel

On Tue, 22 Jul 2025 10:24:56 +0100
Nuno Sá <noname.nuno@gmail.com> wrote:

> On Mon, Jul 21, 2025 at 06:06:39PM -0500, David Lechner wrote:
> > On 7/21/25 6:04 PM, David Lechner wrote:  
> > > Replace using stack-allocated buffers with a DMA-safe buffer for use
> > > with spi_read(). This allows the driver to be safely used with
> > > DMA-enabled SPI controllers.
> > > 
> > > The buffer array is also converted to a struct with a union to make the
> > > usage of the memory in the buffer more clear and ensure proper alignment.
> > > 
> > > Fixes: 1f25ca11d84a ("iio: temperature: add support for Maxim thermocouple chips")
> > > Signed-off-by: David Lechner <dlechner@baylibre.com>
> > > ---
> > > Changes in v2:
> > > - This is a new patch since when looking at it again, I noticed a bug
> > >   with passing stack-allocated memory to spi_read(). So now the primary
> > >   purpose is a fix and converting the array to a struct comes free with
> > >   it.
> > > - Link to v1: https://lore.kernel.org/r/20250711-iio-use-more-iio_declare_buffer_with_ts-3-v1-1-f6dd3363fd85@baylibre.com
> > > ---
> > >  drivers/iio/temperature/maxim_thermocouple.c | 26 ++++++++++++++++----------
> > >  1 file changed, 16 insertions(+), 10 deletions(-)
> > > 
> > > diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c
> > > index cae8e84821d7fd521d59432580d51def939fa4d1..fa648a6542a4e2f08adb556c776b68331ae69631 100644
> > > --- a/drivers/iio/temperature/maxim_thermocouple.c
> > > +++ b/drivers/iio/temperature/maxim_thermocouple.c
> > > @@ -11,6 +11,7 @@
> > >  #include <linux/module.h>
> > >  #include <linux/err.h>
> > >  #include <linux/spi/spi.h>
> > > +#include <linux/types.h>
> > >  #include <linux/iio/iio.h>
> > >  #include <linux/iio/sysfs.h>
> > >  #include <linux/iio/trigger.h>
> > > @@ -121,8 +122,15 @@ struct maxim_thermocouple_data {
> > >  	struct spi_device *spi;
> > >  	const struct maxim_thermocouple_chip *chip;
> > >  	char tc_type;
> > > -
> > > -	u8 buffer[16] __aligned(IIO_DMA_MINALIGN);
> > > +	/* Buffer for reading up to 2 hardware channels. */
> > > +	struct {
> > > +		union {
> > > +			__be16 raw16;
> > > +			__be32 raw32;
> > > +			__be16 raw[2];
> > > +		};
> > > +		aligned_s64 timestamp;
> > > +	} buffer __aligned(IIO_DMA_MINALIGN);
> > >  };
> > >  
> > >  static int maxim_thermocouple_read(struct maxim_thermocouple_data *data,
> > > @@ -130,18 +138,16 @@ static int maxim_thermocouple_read(struct maxim_thermocouple_data *data,
> > >  {
> > >  	unsigned int storage_bytes = data->chip->read_size;
> > >  	unsigned int shift = chan->scan_type.shift + (chan->address * 8);
> > > -	__be16 buf16;
> > > -	__be32 buf32;
> > >  	int ret;
> > >  
> > >  	switch (storage_bytes) {
> > >  	case 2:
> > > -		ret = spi_read(data->spi, (void *)&buf16, storage_bytes);
> > > -		*val = be16_to_cpu(buf16);
> > > +		ret = spi_read(data->spi, &data->buffer.raw16, storage_bytes);
> > > +		*val = be16_to_cpu(data->buffer.raw16);
> > >  		break;
> > >  	case 4:
> > > -		ret = spi_read(data->spi, (void *)&buf32, storage_bytes);
> > > -		*val = be32_to_cpu(buf32);
> > > +		ret = spi_read(data->spi, &data->buffer.raw32, storage_bytes);
> > > +		*val = be32_to_cpu(data->buffer.raw32);
> > >  		break;
> > >  	default:
> > >  		ret = -EINVAL;
> > > @@ -166,9 +172,9 @@ static irqreturn_t maxim_thermocouple_trigger_handler(int irq, void *private)
> > >  	struct maxim_thermocouple_data *data = iio_priv(indio_dev);
> > >  	int ret;
> > >  
> > > -	ret = spi_read(data->spi, data->buffer, data->chip->read_size);
> > > +	ret = spi_read(data->spi, &data->buffer.raw, data->chip->read_size);  
> > 
> > Compile check didn't catch this. Need to drop the &.
> > data->buffer.raw is already an array.  
> 
> Neither did I :). I should have looked into this email __before__ (and
> not after) sending my tag. Anyways, consider the tag with the above
> fixed.
> 
> - Nuno Sá
> 
Applied to the fixes-togreg-for-6.17 branch + marked for stable with:
diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c
index fa648a6542a4..205939680fd4 100644
--- a/drivers/iio/temperature/maxim_thermocouple.c
+++ b/drivers/iio/temperature/maxim_thermocouple.c
@@ -172,7 +172,7 @@ static irqreturn_t maxim_thermocouple_trigger_handler(int irq, void *private)
        struct maxim_thermocouple_data *data = iio_priv(indio_dev);
        int ret;
 
-       ret = spi_read(data->spi, &data->buffer.raw, data->chip->read_size);
+       ret = spi_read(data->spi, data->buffer.raw, data->chip->read_size);
        if (!ret) {
                iio_push_to_buffers_with_ts(indio_dev, &data->buffer,
                                            sizeof(data->buffer),

Quicker than going around again :)

> > 
> >   
> > >  	if (!ret) {
> > > -		iio_push_to_buffers_with_ts(indio_dev, data->buffer,
> > > +		iio_push_to_buffers_with_ts(indio_dev, &data->buffer,
> > >  					    sizeof(data->buffer),
> > >  					    iio_get_time_ns(indio_dev));
> > >  	}
> > > 
> > > ---
> > > base-commit: cd2731444ee4e35db76f4fb587f12d327eec5446
> > > change-id: 20250711-iio-use-more-iio_declare_buffer_with_ts-3-2cc387a66bdc
> > > 
> > > Best regards,  
> >   


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

end of thread, other threads:[~2025-07-24 11:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-21 23:04 [PATCH v2] iio: temperature: maxim_thermocouple: use DMA-safe buffer for spi_read() David Lechner
2025-07-21 23:06 ` David Lechner
2025-07-22  9:24   ` Nuno Sá
2025-07-24 11:15     ` Jonathan Cameron
2025-07-22  9:23 ` Nuno Sá

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).