Skip to content

Commit f6db1cb

Browse files
etienne-lmsjhedberg
authored andcommitted
drivers: disk: sdmmc_stm32: test HAL init/deinit return values
Add tests of the value returned by initialization and deinitialization HAL functions. Signed-off-by: Etienne Carriere <[email protected]>
1 parent 4575afa commit f6db1cb

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

drivers/disk/sdmmc_stm32.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,15 +300,19 @@ static int stm32_sdmmc_dma_init(struct stm32_sdmmc_priv *priv)
300300
return err;
301301
}
302302
__HAL_LINKDMA(&priv->hsd, hdmatx, priv->dma_tx_handle);
303-
HAL_DMA_Init(&priv->dma_tx_handle);
303+
if (HAL_DMA_Init(&priv->dma_tx_handle) != HAL_OK) {
304+
return -EIO;
305+
}
304306

305307
err = stm32_sdmmc_configure_dma(&priv->dma_rx_handle, &priv->dma_rx);
306308
if (err) {
307309
LOG_ERR("failed to init rx dma");
308310
return err;
309311
}
310312
__HAL_LINKDMA(&priv->hsd, hdmarx, priv->dma_rx_handle);
311-
HAL_DMA_Init(&priv->dma_rx_handle);
313+
if (HAL_DMA_Init(&priv->dma_rx_handle) != HAL_OK) {
314+
return -EIO;
315+
}
312316
#endif /* STM32_SDMMC_USE_DMA_SHARED */
313317

314318
return err;
@@ -332,14 +336,17 @@ static int stm32_sdmmc_dma_deinit(struct stm32_sdmmc_priv *priv)
332336
#else
333337
struct sdmmc_dma_stream *dma_tx = &priv->dma_tx;
334338
struct sdmmc_dma_stream *dma_rx = &priv->dma_rx;
339+
HAL_StatusTypeDef __maybe_unused hal_ret;
335340

336341
ret = dma_stop(dma_tx->dev, dma_tx->channel);
337342
__ASSERT(ret == 0, "TX DMA channel index corrupted");
338-
HAL_DMA_DeInit(&priv->dma_tx_handle);
343+
hal_ret = HAL_DMA_DeInit(&priv->dma_tx_handle);
344+
__ASSERT_NO_MSG(hal_ret == HAL_OK);
339345

340346
ret = dma_stop(dma_rx->dev, dma_rx->channel);
341347
__ASSERT(ret == 0, "RX DMA channel index corrupted");
342-
HAL_DMA_DeInit(&priv->dma_rx_handle);
348+
hal_ret = HAL_DMA_DeInit(&priv->dma_rx_handle);
349+
__ASSERT_NO_MSG(hal_ret == HAL_OK);
343350
#endif
344351
return 0;
345352
}
@@ -556,7 +563,10 @@ static int stm32_sdmmc_access_read(struct disk_info *disk, uint8_t *data_buf,
556563
k_sem_take(&priv->sync, K_FOREVER);
557564

558565
#if STM32_SDMMC_USE_DMA_SHARED
559-
HAL_DMA_DeInit(&priv->dma_txrx_handle);
566+
if (HAL_DMA_DeInit(&priv->dma_txrx_handle) != HAL_OK) {
567+
err = -EIO;
568+
goto end;
569+
}
560570
#endif
561571

562572
if (priv->status != DISK_STATUS_OK) {
@@ -632,7 +642,11 @@ static int stm32_sdmmc_access_write(struct disk_info *disk,
632642
k_sem_take(&priv->sync, K_FOREVER);
633643

634644
#if STM32_SDMMC_USE_DMA_SHARED
635-
HAL_DMA_DeInit(&priv->dma_txrx_handle);
645+
if (HAL_DMA_DeInit(&priv->dma_txrx_handle) != HAL_OK) {
646+
LOG_ERR("DMA deinit error");
647+
err = -EIO;
648+
goto end;
649+
}
636650
#endif
637651

638652
if (priv->status != DISK_STATUS_OK) {

0 commit comments

Comments
 (0)