Skip to content

Commit

Permalink
mpfs_corespi: fix semaphore race condition
Browse files Browse the repository at this point in the history
SPI TX_DONE interrupt can be received after a semaphore timeout,
but before interrupts are disabled. This will leave the semaphore
to the signaled state.

After a timeout the semaphore is always reset to non-signaled state
to fix this race condition.

Signed-off-by: Tero Salminen <[email protected]>
  • Loading branch information
t-salminen committed Apr 2, 2024
1 parent b037ee8 commit 5e30e33
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions arch/risc-v/src/mpfs/mpfs_corespi.c
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,18 @@ static void mpfs_spi_irq_exchange(struct mpfs_spi_priv_s *priv,
MPFS_SPI_INTTXDONE,
0);

/* TX_DONE interrupt can be received after a semaphore timeout, but before
* interrupts are disabled. This will leave the semaphore to the signaled
* state.
* After a timeout the semaphore is always reset to non-signaled state
* to fix this race condition.
*/

if (priv->error == -ETIMEDOUT)
{
nxsem_reset(&priv->sem_isr, 0);
}

putreg32(MPFS_SPI_TXCHUNDRUN |
MPFS_SPI_RXCHOVRFLW |
MPFS_SPI_DATA_RX |
Expand Down

0 comments on commit 5e30e33

Please sign in to comment.