Skip to content

Commit c63b8fd

Browse files
fancerbroonie
authored andcommitted
spi: dw: Fix wrong FIFO level setting for long xfers
Due to using the u16 type in the min_t() macros the SPI transfer length will be cast to word before participating in the conditional statement implied by the macro. Thus if the transfer length is greater than 64KB the Tx/Rx FIFO threshold level value will be determined by the leftover of the truncated after the type-case length. In the worst case it will cause the dramatical performance drop due to the "Tx FIFO Empty" or "Rx FIFO Full" interrupts triggered on each xfer word sent/received to/from the bus. The problem can be easily fixed by specifying the unsigned int type in the min_t() macros thus preventing the possible data loss. Fixes: ea11370 ("spi: dw: get TX level without an additional variable") Reported-by: Sergey Nazarov <[email protected]> Signed-off-by: Serge Semin <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent b442990 commit c63b8fd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/spi/spi-dw-core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ static void dw_spi_irq_setup(struct dw_spi *dws)
366366
* will be adjusted at the final stage of the IRQ-based SPI transfer
367367
* execution so not to lose the leftover of the incoming data.
368368
*/
369-
level = min_t(u16, dws->fifo_len / 2, dws->tx_len);
369+
level = min_t(unsigned int, dws->fifo_len / 2, dws->tx_len);
370370
dw_writel(dws, DW_SPI_TXFTLR, level);
371371
dw_writel(dws, DW_SPI_RXFTLR, level - 1);
372372

0 commit comments

Comments
 (0)