From b0e327bd9c4d347bf8ec042aa684408b5abf2604 Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Wed, 5 Jun 2024 07:27:43 +0200 Subject: [PATCH] drivers/spi: Fix context release in case of error SPI context has to be released even in case of error. Fixes: #72782 Signed-off-by: Tomasz Bursztyka --- drivers/spi/spi_andes_atcspi200.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/spi/spi_andes_atcspi200.c b/drivers/spi/spi_andes_atcspi200.c index 1d95d9fc263..4fae6ec3534 100644 --- a/drivers/spi/spi_andes_atcspi200.c +++ b/drivers/spi/spi_andes_atcspi200.c @@ -639,14 +639,16 @@ static int transceive(const struct device *dev, if ((data->dma_tx.dma_dev != NULL) && (data->dma_rx.dma_dev != NULL)) { error = spi_transfer_dma(dev); if (error != 0) { - return error; + spi_context_cs_control(ctx, false); + goto out; } } else { #endif /* CONFIG_ANDES_SPI_DMA_MODE */ error = spi_transfer(dev); if (error != 0) { - return error; + spi_context_cs_control(ctx, false); + goto out; } #ifdef CONFIG_ANDES_SPI_DMA_MODE @@ -655,7 +657,7 @@ static int transceive(const struct device *dev, error = spi_context_wait_for_completion(ctx); spi_context_cs_control(ctx, false); } - +out: spi_context_release(ctx, error); return error;