From 13df3b9f62dd06faf87a4a5d2f4b2d6a69633f89 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Mon, 9 Dec 2024 11:40:26 +1000 Subject: [PATCH] spi: context: update state when already locked Update the context state parameters when the context is already locked. This allows changing the callback information for asynchronous operations while the context is locked. Signed-off-by: Jordan Yates --- drivers/spi/spi_context.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi_context.h b/drivers/spi/spi_context.h index d5e04ee4457..7ae3cfb2bba 100644 --- a/drivers/spi/spi_context.h +++ b/drivers/spi/spi_context.h @@ -96,13 +96,11 @@ static inline void spi_context_lock(struct spi_context *ctx, (k_sem_count_get(&ctx->lock) == 0) && (ctx->owner == spi_cfg); - if (already_locked) { - return; + if (!already_locked) { + k_sem_take(&ctx->lock, K_FOREVER); + ctx->owner = spi_cfg; } - k_sem_take(&ctx->lock, K_FOREVER); - ctx->owner = spi_cfg; - #ifdef CONFIG_SPI_ASYNC ctx->asynchronous = asynchronous; ctx->callback = callback;