Skip to content

driver: spi: spi_release() implementations requires an owner check #92687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

GardeningStevie
Copy link
Contributor

Without this check, spi_context_unlock_unconditionally() is capable to release the SPI bus semaphore (ctx->lock) which might be taken by an other 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, hold by an other SPI slave device, is prematurely released.
The observable result is the simultaneous engagement of two SPI chip selects after such a SPI release call.

Note: this PR fixes my issue with a Nordic SPI master. As far as I have seen, most vendor implementations have this issue.

Without this check, `spi_context_unlock_unconditionally()` is capable
to release the SPI bus semaphore (ctx->lock) which might be taken by
an other SPI slave device in the meantime.

Actually, this race condtion 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, hold by an other SPI
slave device,  is prematurely released.
The observable result is the simultaneous engagement of two SPI
chip selects after such a SPI release call.

Signed-off-by: Stefan Schwendeler <Stefan.Schwendeler@husqvarnagroup.com>
@GardeningStevie
Copy link
Contributor Author

In SystemView we could spot this event (2 chip selects)
nrf_spim_2xCS_

Copy link

sonarqubecloud bot commented Jul 4, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: SPI SPI bus platform: nRF Nordic nRFx
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants