From bd511c42d290807a04a325d584d65b98fd6721d7 Mon Sep 17 00:00:00 2001 From: Jonas Rebmann Date: Thu, 24 Sep 2026 15:43:54 +0200 Subject: [PATCH] spi: spidev_test: allow zero-length transfers SPI drivers may in fact handle zero-length transfers. The behavior so far was that such transfers would be executed but then result in the "can't send spi message" error message because the spi_sync() call returning 0 would be treated as an error while really it simply indicates that zero bytes were successfully transferred in a message. Don't treat a return value of zero as indication of an error. Update hex_dump() to work with empty buffers now printing e.g. TX | __ || Now including a trailing newline. Signed-off-by: Jonas Rebmann Link: https://patch.msgid.link/20260924-spi-sun4i-spidev_test-v7-4-126e31a07fdc@pengutronix.de Signed-off-by: Mark Brown --- tools/spi/spidev_test.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index 36292d868d69..908ed038889b 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c @@ -68,6 +68,10 @@ static void hex_dump(const void *src, size_t length, size_t line_size, unsigned char c; printf("%s | ", prefix); + + if (length == 0) + printf("__ ||\n"); + while (length-- > 0) { printf("%02X ", *address++); if (!(++i % line_size) || (length == 0 && i % line_size)) { @@ -149,7 +153,7 @@ static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len) } ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr); - if (ret < 1) + if (ret < 0) pabort("can't send spi message"); if (verbose)