Skip to content

Commit d2e8d0a

Browse files
gautierg-stdanieldegrasse
authored andcommitted
drivers: spi: context: check that config exists before reading it
Function spi_context_release reads the content of ctx->config without checking first if it is set. In many drivers (including STM32), when a bad configuration is made for the first transaction, ctx->config is not set, and spi_context_release is called, resulting in hard fault. This commit adds a check that ctx->config exists before reading it to avoid this problem. Signed-off-by: Guillaume Gautier <[email protected]>
1 parent 1de500e commit d2e8d0a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/spi/spi_context.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static inline void spi_context_release(struct spi_context *ctx, int status)
144144
{
145145
#ifdef CONFIG_MULTITHREADING
146146
#ifdef CONFIG_SPI_SLAVE
147-
if (status >= 0 && (ctx->config->operation & SPI_LOCK_ON)) {
147+
if (status >= 0 && ((ctx->config == NULL) || (ctx->config->operation & SPI_LOCK_ON))) {
148148
return;
149149
}
150150
#endif /* CONFIG_SPI_SLAVE */
@@ -155,7 +155,7 @@ static inline void spi_context_release(struct spi_context *ctx, int status)
155155
k_sem_give(&ctx->lock);
156156
}
157157
#else
158-
if (!(ctx->config->operation & SPI_LOCK_ON)) {
158+
if ((ctx->config == NULL) || !(ctx->config->operation & SPI_LOCK_ON)) {
159159
ctx->owner = NULL;
160160
k_sem_give(&ctx->lock);
161161
}

0 commit comments

Comments
 (0)