[PATCH v6 04/13] spi: spidev_test: allow zero-length transfers
From: Jonas Rebmann
Date: Thu Sep 24 2026 - 08:29:40 EST
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 <jre@xxxxxxxxxxxxxx>
---
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)
--
2.56.0.rc0.108.gf0ef1b96a0