Skip to content

Commit cb77257

Browse files
GardeningSteviecfriedt
authored andcommitted
driver: spi: spi_release() implementations requires an owner check
Without this check, `spi_context_unlock_unconditionally()` is capable to release the SPI bus semaphore (ctx->lock) which might be taken by another SPI slave device in the meantime. Actually, this race condition happens when `spi_release()` is called when the SPI slave device in question (spi_cfg) has already released its chip select and also the SPI bus lock semaphore. So, any not required call of `spi_release()` may result in a SPI communication issue where the SPI bus lock, held by another SPI slave device, is prematurely released. The observable result is the simultaneous engagement of two SPI chip selects after such an SPI release call. Signed-off-by: Stefan Schwendeler <[email protected]>
1 parent 8e9fa6a commit cb77257

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/spi/spi_nrfx_spim.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,12 @@ static int spi_nrfx_release(const struct device *dev,
733733
{
734734
struct spi_nrfx_data *dev_data = dev->data;
735735

736+
#ifdef CONFIG_MULTITHREADING
737+
if (dev_data->ctx.owner != spi_cfg) {
738+
return -EALREADY;
739+
}
740+
#endif
741+
736742
if (!spi_context_configured(&dev_data->ctx, spi_cfg)) {
737743
return -EINVAL;
738744
}

0 commit comments

Comments
 (0)