From 6318750837cea9badfcb9b2874f6ef42cce442d7 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Thu, 13 Jul 2017 18:31:44 -0400 Subject: [PATCH] spi: stm32: fix spi_stm32_init() It is incorrect to call spi_context_release() on an STM32 spi_stm32_data object's ctx field before data->ctx->config is first set in spi_stm32_configure(). This is because spi_context_release() reads ctx->config->operation. In particular, during spi_stm32_init(), calling spi_context_release() reads the uninitialized memory in data->ctx->config->operation. Call spi_context_unlock_unconditionally() instead to properly increase the semaphore count. Without this patch, the first call to spi_transceive() can block forever depending on the value of the uninitialized memory holding data->ctx->config->operation. Signed-off-by: Marti Bolivar --- drivers/spi/spi_ll_stm32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/spi/spi_ll_stm32.c b/drivers/spi/spi_ll_stm32.c index c798b160888..6aea35b9c92 100644 --- a/drivers/spi/spi_ll_stm32.c +++ b/drivers/spi/spi_ll_stm32.c @@ -351,7 +351,7 @@ static int spi_stm32_init(struct device *dev) cfg->irq_config(dev); #endif - spi_context_release(&data->ctx, 0); + spi_context_unlock_unconditionally(&data->ctx); return 0; }