Skip to content

Commit c6c1e30

Browse files
vladimirolteanbroonie
authored andcommitted
spi: spi-fsl-dspi: Avoid reading more data than written in EOQ mode
If dspi->words_in_flight is populated with the hardware FIFO size, then in dspi_fifo_read it will attempt to read more data at the end of a buffer that is not a multiple of 16 bytes in length. It will probably time out attempting to do so. So limit the num_fifo_entries variable to the actual number of FIFO entries that is going to be used. Fixes: d59c90a ("spi: spi-fsl-dspi: Convert TCFQ users to XSPI FIFO mode") Signed-off-by: Vladimir Oltean <[email protected]> Tested-by: Michael Walle <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent a957499 commit c6c1e30

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/spi/spi-fsl-dspi.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,13 +739,16 @@ static void dspi_eoq_fifo_write(struct fsl_dspi *dspi)
739739
int num_fifo_entries = dspi->devtype_data->fifo_size;
740740
u16 xfer_cmd = dspi->tx_cmd;
741741

742+
if (num_fifo_entries * dspi->oper_word_size > dspi->len)
743+
num_fifo_entries = dspi->len / dspi->oper_word_size;
744+
742745
dspi->words_in_flight = num_fifo_entries;
743746

744747
/* Fill TX FIFO with as many transfers as possible */
745-
while (dspi->len && num_fifo_entries--) {
748+
while (num_fifo_entries--) {
746749
dspi->tx_cmd = xfer_cmd;
747750
/* Request EOQF for last transfer in FIFO */
748-
if (dspi->len == dspi->oper_word_size || num_fifo_entries == 0)
751+
if (num_fifo_entries == 0)
749752
dspi->tx_cmd |= SPI_PUSHR_CMD_EOQ;
750753
/* Write combined TX FIFO and CMD FIFO entry */
751754
dspi_pushr_write(dspi);

0 commit comments

Comments
 (0)