diff mbox series

[1/8] spi: stm32: properly handle 0 byte transfer

Message ID 1612523342-10466-2-git-send-email-alain.volmat@foss.st.com (mailing list archive)
State New, archived
Headers show
Series spi: stm32: fix and enhancements for spi-stm32 | expand

Commit Message

Alain Volmat Feb. 5, 2021, 11:08 a.m. UTC
On 0 byte transfer request, return straight from the
xfer function after finalizing the transfer.

Fixes: dcbe0d84dfa5 ("spi: add driver for STM32 SPI controller")
Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
---
 drivers/spi/spi-stm32.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Mark Brown Feb. 5, 2021, 1:29 p.m. UTC | #1
On Fri, Feb 05, 2021 at 12:08:55PM +0100, Alain Volmat wrote:
> On 0 byte transfer request, return straight from the
> xfer function after finalizing the transfer.

> +	if (transfer->len == 0) {
> +		spi_finalize_current_transfer(master);
> +		return 0;

The driver only needs to finalize the transfer if it returned a value
greater than 0, returning 0 indicates that the transfer is already done.
diff mbox series

Patch

diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index db3e305d9ec4..137213633e6d 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -1657,6 +1657,12 @@  static int stm32_spi_transfer_one(struct spi_master *master,
 	struct stm32_spi *spi = spi_master_get_devdata(master);
 	int ret;
 
+	/* Don't do anything on 0 bytes transfers */
+	if (transfer->len == 0) {
+		spi_finalize_current_transfer(master);
+		return 0;
+	}
+
 	spi->tx_buf = transfer->tx_buf;
 	spi->rx_buf = transfer->rx_buf;
 	spi->tx_len = spi->tx_buf ? transfer->len : 0;