[PATCH v5 03/13] spi: spidev_test: make size argument mandatory for --size

From: Jonas Rebmann

Date: Wed Sep 23 2026 - 16:15:24 EST


When the argument to --size is omitted, zero or not a number,
abort with a message instead of transmitting default_tx[].

Signed-off-by: Jonas Rebmann <jre@xxxxxxxxxxxxxx>
---
tools/spi/spidev_test.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c
index 3721ed15352f..b2940a25b7a8 100644
--- a/tools/spi/spidev_test.c
+++ b/tools/spi/spidev_test.c
@@ -44,6 +44,7 @@ static int verbose;
static int transfer_size;
static int iterations;
static int interval = 5; /* interval in seconds for showing transfer rate */
+static int random_input;
static int input_choices;

static uint8_t default_tx[] = {
@@ -319,6 +320,7 @@ static void parse_opts(int argc, char *argv[])
break;
case 'S':
transfer_size = atoi(optarg);
+ random_input = 1;
input_choices++;
break;
case 'I':
@@ -453,6 +455,9 @@ int main(int argc, char *argv[])
if (input_choices > 1)
pabort("only one of -S (--size), -p, -i (--input) may be selected");

+ if (random_input && !transfer_size)
+ pabort("a nonzero size argument is mandatory for -S (--size)");
+
fd = open(device, O_RDWR);
if (fd < 0)
pabort("can't open device");

--
2.56.0.rc0.108.gf0ef1b96a0