iio: adc: ad4000: Avoid potential double data word read
authorMarcelo Schmitt <marcelo.schmitt@analog.com>
Tue, 15 Apr 2025 12:21:10 +0000 (09:21 -0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Wed, 21 May 2025 13:20:30 +0000 (14:20 +0100)
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: 59b51edf717b ("iio: adc: ad4000: Add support for SPI offload")
Suggested-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Link: https://patch.msgid.link/8f765cfd6e93fad4e755dd95d709b7bea2a388e2.1744718916.git.marcelo.schmitt@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ad4000.c

index 93ecaf401f27386d50627723a3132f6af427d484..5609a7845b6f50b5818613170df6b234f8f0c496 100644 (file)
@@ -942,7 +942,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