public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: adc: ad4000: Avoid potential double data word read
@ 2025-04-15 12:21 Marcelo Schmitt
  2025-04-15 18:02 ` Andy Shevchenko
  2025-04-16 18:43 ` David Lechner
  0 siblings, 2 replies; 8+ messages in thread
From: Marcelo Schmitt @ 2025-04-15 12:21 UTC (permalink / raw)
  To: linux-iio, linux-kernel
  Cc: jic23, lars, Michael.Hennerich, nuno.sa, andy, marcelo.schmitt,
	marcelo.schmitt1, David Lechner

Currently, SPI-Engine offload module always sends 32-bit data elements to
DMA engine. Appropriately, when set for SPI offloading, the IIO driver uses
32 storagebits for IIO ADC channel buffer elements. However, setting SPI
transfer length according to storagebits (32-bits in case of offload) can
lead to unnecessarily long transfers for ADCs that are 16-bit or less
precision. Adjust AD4000 single-shot read to run transfers of 2 bytes when
that is enough to get all ADC data bits.

Fixes: d0dba3df842f ("iio: adc: ad4000: Add support for SPI offload")
Suggested-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
---
After enough sleep and some time not looking at this driver I finally realize
the potential issue David was talking about. Although I didn't see any clearly
wrong reading when testing it last week, I'm adding the fixes tag since it's
probably easier to drop the tag than to go fetch the commit log.
Also adding a suggested-by tag.

Thanks,
Marcelo

 drivers/iio/adc/ad4000.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad4000.c b/drivers/iio/adc/ad4000.c
index e69a9d2a3e8c..5813db28510d 100644
--- a/drivers/iio/adc/ad4000.c
+++ b/drivers/iio/adc/ad4000.c
@@ -941,7 +941,7 @@ static int ad4000_prepare_3wire_mode_message(struct ad4000_state *st,
 	xfers[0].cs_change_delay.unit = SPI_DELAY_UNIT_NSECS;
 
 	xfers[1].rx_buf = &st->scan.data;
-	xfers[1].len = BITS_TO_BYTES(chan->scan_type.storagebits);
+	xfers[1].len = chan->scan_type.realbits > 16 ? 4 : 2;
 
 	/*
 	 * If the device is set up for SPI offloading, IIO channel scan_type is

base-commit: 1c2409fe38d5c19015d69851d15ba543d1911932
-- 
2.47.2


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

end of thread, other threads:[~2025-05-05 16:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-15 12:21 [PATCH] iio: adc: ad4000: Avoid potential double data word read Marcelo Schmitt
2025-04-15 18:02 ` Andy Shevchenko
2025-04-15 21:22   ` David Lechner
2025-04-16  5:59     ` Andy Shevchenko
2025-04-16  6:01       ` Andy Shevchenko
2025-04-16  6:47         ` Andy Shevchenko
2025-05-05 16:14           ` Jonathan Cameron
2025-04-16 18:43 ` David Lechner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox