Skip to content

Commit cce1229

Browse files
pelwellFang Yafen
authored and
Fang Yafen
committed
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/linux#4100 Signed-off-by: Phil Elwell <[email protected]> [1] 26751de ("spi: bcm2835: Micro-optimise FIFO loops") Signed-off-by: Fang Yafen <[email protected]>
1 parent d244098 commit cce1229

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

drivers/spi/spi-bcm2835.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,16 @@ static int bcm2835_spi_transfer_one(struct spi_controller *ctlr,
10901090
unsigned long hz_per_byte, byte_limit;
10911091
u32 cs = bs->prepare_cs[spi->chip_select];
10921092

1093+
if (unlikely(!tfr->len)) {
1094+
static int warned;
1095+
1096+
if (!warned)
1097+
dev_warn(&spi->dev,
1098+
"zero-length SPI transfer ignored\n");
1099+
warned = 1;
1100+
return 0;
1101+
}
1102+
10931103
/* set clock */
10941104
spi_hz = tfr->speed_hz;
10951105
clk_hz = clk_get_rate(bs->clk);

0 commit comments

Comments
 (0)