Skip to content

Commit

Permalink
spi: context: update state when already locked
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
JordanYates authored and kartben committed Jan 6, 2025
1 parent ebc2ca5 commit 13df3b9
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions drivers/spi/spi_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 13df3b9

Please sign in to comment.