All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] spi: Skip zero-length transfers in spi_transfer_one_message()
@ 2021-02-11 18:08 Nicolas Saenz Julienne
  2021-02-12 12:31 ` Mark Brown
  2021-02-12 14:01 ` Mark Brown
  0 siblings, 2 replies; 7+ messages in thread
From: Nicolas Saenz Julienne @ 2021-02-11 18:08 UTC (permalink / raw)
  To: Mark Brown, Robin Murphy
  Cc: Nicolas Saenz Julienne, Phil Elwell, linux-spi, linux-kernel

With the introduction of 26751de25d25 ("spi: bcm2835: Micro-optimise
FIFO loops") it has become apparent that some users might initiate
zero-length SPI transfers. A fact the micro-optimization omitted, and
which turned out to cause crashes[1].

Instead of changing the micro-optimization itself, use a bigger hammer
and skip zero-length transfers altogether for drivers using the default
transfer_one_message() implementation.

Reported-by: Phil Elwell <phil@raspberrypi.com>
Fixes: 26751de25d25 ("spi: bcm2835: Micro-optimise FIFO loops")
Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>

[1] https://github.com/raspberrypi/linux/issues/4100

---

NOTE: I've reviewed a bunch of drivers and couldn't find a compelling
reason why zero-length transfers should be passed into them. But I
might be missing something.

 drivers/spi/spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 7745eec994fd..b08efe88ccd6 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1269,7 +1269,7 @@ static int spi_transfer_one_message(struct spi_controller *ctlr,
 			ptp_read_system_prets(xfer->ptp_sts);
 		}
 
-		if (xfer->tx_buf || xfer->rx_buf) {
+		if ((xfer->tx_buf || xfer->rx_buf) && xfer->len) {
 			reinit_completion(&ctlr->xfer_completion);
 
 fallback_pio:
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-02-12 14:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-11 18:08 [PATCH] spi: Skip zero-length transfers in spi_transfer_one_message() Nicolas Saenz Julienne
2021-02-12 12:31 ` Mark Brown
2021-02-12 12:48   ` Nicolas Saenz Julienne
2021-02-12 12:52     ` Mark Brown
2021-02-12 12:57       ` Geert Uytterhoeven
2021-02-12 13:05         ` Mark Brown
2021-02-12 14:01 ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.