From 022192ecee4608a2dd55e138d66ec0e8f8235c1c Mon Sep 17 00:00:00 2001 From: Joshua DeWeese Date: Fri, 9 Dec 2022 14:28:02 -0500 Subject: [PATCH] drivers/soft_spi: fix over-allocation of locks The intent was to allocate one lock per device, but that was not the case in practice. This patch fixes this. --- drivers/soft_spi/include/soft_spi_params.h | 5 +++++ drivers/soft_spi/soft_spi.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/soft_spi/include/soft_spi_params.h b/drivers/soft_spi/include/soft_spi_params.h index 78a2425766..f17f8be93f 100644 --- a/drivers/soft_spi/include/soft_spi_params.h +++ b/drivers/soft_spi/include/soft_spi_params.h @@ -48,6 +48,11 @@ static soft_spi_conf_t soft_spi_config[] = { SOFT_SPI_PARAMS, }; +/** + * @brief Number of software SPI buses + */ +#define SOFT_SPI_NUMOF ARRAY_SIZE(soft_spi_config) + #ifdef __cplusplus } #endif diff --git a/drivers/soft_spi/soft_spi.c b/drivers/soft_spi/soft_spi.c index 8786b4bcdb..6a7cff9698 100644 --- a/drivers/soft_spi/soft_spi.c +++ b/drivers/soft_spi/soft_spi.c @@ -34,7 +34,7 @@ /** * @brief Allocate one lock per SPI device */ -static mutex_t locks[sizeof soft_spi_config]; +static mutex_t locks[SOFT_SPI_NUMOF]; static inline bool soft_spi_bus_is_valid(soft_spi_t bus) {