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 <jre@pengutronix.de>
Link: https://patch.msgid.link/20260924-spi-sun4i-spidev_test-v7-4-126e31a07fdc@pengutronix.de
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Jonas Rebmann 2026-09-24 15:43:54 +02:00 committed by Mark Brown
parent df79e49bd7
commit bd511c42d2
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0

View File

@ -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)