Skip to content

Commit e49a091

Browse files
committed
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 d9fcc1e commit e49a091

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
@@ -292,15 +292,19 @@ static int stm32_sdmmc_dma_init(struct stm32_sdmmc_priv *priv)
292292
return err;
293293
}
294294
__HAL_LINKDMA(&priv->hsd, hdmatx, priv->dma_tx_handle);
295-
HAL_DMA_Init(&priv->dma_tx_handle);
295+
if (HAL_DMA_Init(&priv->dma_tx_handle) != HAL_OK) {
296+
return -EIO;
297+
}
296298

297299
err = stm32_sdmmc_configure_dma(&priv->dma_rx_handle, &priv->dma_rx);
298300
if (err) {
299301
LOG_ERR("failed to init rx dma");
300302
return err;
301303
}
302304
__HAL_LINKDMA(&priv->hsd, hdmarx, priv->dma_rx_handle);
303-
HAL_DMA_Init(&priv->dma_rx_handle);
305+
if (HAL_DMA_Init(&priv->dma_rx_handle) != HAL_OK) {
306+
return -EIO;
307+
}
304308
#endif /* STM32_SDMMC_USE_DMA_SHARED */
305309

306310
return err;
@@ -324,14 +328,17 @@ static int stm32_sdmmc_dma_deinit(struct stm32_sdmmc_priv *priv)
324328
#else
325329
struct sdmmc_dma_stream *dma_tx = &priv->dma_tx;
326330
struct sdmmc_dma_stream *dma_rx = &priv->dma_rx;
331+
HAL_StatusTypeDef __maybe_unused hal_ret;
327332

328333
ret = dma_stop(dma_tx->dev, dma_tx->channel);
329334
__ASSERT(ret == 0, "TX DMA channel index corrupted");
330-
HAL_DMA_DeInit(&priv->dma_tx_handle);
335+
hal_ret = HAL_DMA_DeInit(&priv->dma_tx_handle);
336+
__ASSERT_NO_MSG(hal_ret == HAL_OK);
331337

332338
ret = dma_stop(dma_rx->dev, dma_rx->channel);
333339
__ASSERT(ret == 0, "RX DMA channel index corrupted");
334-
HAL_DMA_DeInit(&priv->dma_rx_handle);
340+
hal_ret = HAL_DMA_DeInit(&priv->dma_rx_handle);
341+
__ASSERT_NO_MSG(hal_ret == HAL_OK);
335342
#endif
336343
return 0;
337344
}
@@ -535,7 +542,10 @@ static int stm32_sdmmc_access_read(struct disk_info *disk, uint8_t *data_buf,
535542
k_sem_take(&priv->sync, K_FOREVER);
536543

537544
#if STM32_SDMMC_USE_DMA_SHARED
538-
HAL_DMA_DeInit(&priv->dma_txrx_handle);
545+
if (HAL_DMA_DeInit(&priv->dma_txrx_handle) != HAL_OK) {
546+
err = -EIO;
547+
goto end;
548+
}
539549
#endif
540550

541551
if (priv->status != DISK_STATUS_OK) {
@@ -611,7 +621,11 @@ static int stm32_sdmmc_access_write(struct disk_info *disk,
611621
k_sem_take(&priv->sync, K_FOREVER);
612622

613623
#if STM32_SDMMC_USE_DMA_SHARED
614-
HAL_DMA_DeInit(&priv->dma_txrx_handle);
624+
if (HAL_DMA_DeInit(&priv->dma_txrx_handle) != HAL_OK) {
625+
LOG_ERR("DMA deinit error");
626+
err = -EIO;
627+
goto end;
628+
}
615629
#endif
616630

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

0 commit comments

Comments
 (0)