Skip to content

Commit 4341966

Browse files
pelwellpopcornmix
authored andcommitted
spi: bcm2835: Workaround/fix for zero-length transfers
A relatively recent commit ([1]) contained optimisation for the PIO SPI FIFO-filling functions. The commit message includes the phrase "[t]he blind and counted loops are always called with nonzero count". This is technically true, but it is still possible for count to become zero before the loop is entered - if tfr->len is zero. Moving the loop exit condition to the end of the loop saves a few cycles, but results in a near-infinite loop should the revised count be zero on entry. Strangely, zero-lengthed transfers aren't filtered by the SPI framework and, even more strangely, the Python3 spidev library is triggering them for no obvious reason. Avoid the problem completely by bailing out of the main transfer function early if trf->len is zero, although there may be a case for moving the mitigation into the framework. See: raspberrypi#4100 Signed-off-by: Phil Elwell <phil@raspberrypi.com> [1] 26751de ("spi: bcm2835: Micro-optimise FIFO loops")
1 parent a815184 commit 4341966

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎drivers/spi/spi-bcm2835.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,16 @@ static int bcm2835_spi_transfer_one(struct spi_controller *ctlr,
10551055
unsigned long hz_per_byte, byte_limit;
10561056
u32 cs = slv->prepare_cs;
10571057

1058+
if (unlikely(!tfr->len)) {
1059+
static int warned;
1060+
1061+
if (!warned)
1062+
dev_warn(&spi->dev,
1063+
"zero-length SPI transfer ignored\n");
1064+
warned = 1;
1065+
return 0;
1066+
}
1067+
10581068
/* set clock */
10591069
spi_hz = tfr->speed_hz;
10601070

0 commit comments

Comments
 (0)