From 85c7a2c59fe39f11865e8869c9ceb2c41f6428f0 Mon Sep 17 00:00:00 2001 From: Bertho Stultiens Date: Wed, 4 Dec 2024 17:20:27 +0100 Subject: [PATCH] Return an error for non-existent ports to probe and empty spi_probe. --- src/hal/drivers/mesa-hostmot2/hm2_spix.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/hal/drivers/mesa-hostmot2/hm2_spix.c b/src/hal/drivers/mesa-hostmot2/hm2_spix.c index ea353ab8267..34f05cd0c9d 100644 --- a/src/hal/drivers/mesa-hostmot2/hm2_spix.c +++ b/src/hal/drivers/mesa-hostmot2/hm2_spix.c @@ -542,6 +542,16 @@ static int spix_setup(void) LL_WARN("Setting spi_pull_{miso,mosi,sclk} has no effect in the hm2_spix driver.\n"); } + if(spi_probe > (1 << SPIX_MAX_BOARDS) - 1) { + LL_WARN("Probing with spi_probe must not have flags larger than %d included; truncating.\n", 1 << (SPIX_MAX_BOARDS - 1)); + spi_probe &= (1 << SPIX_MAX_BOARDS) - 1; + } + + if(!spi_probe) { + LL_ERR("No SPI ports to probe (spi_probe is zero).\n"); + return -EINVAL; + } + // Set process-level message level if requested if(spi_debug >= RTAPI_MSG_NONE && spi_debug <= RTAPI_MSG_ALL) rtapi_set_msg_level(spi_debug);