From 829c6cef395e9eeb05ab5c0780abcb59286c888d Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 23 Apr 2018 14:38:00 +0800 Subject: [PATCH] sdmmc host: when parameter validation fails, exit cleanly This fixes lock-up which happened when sending a command, if the previous command has failed. --- components/driver/sdmmc_transaction.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/components/driver/sdmmc_transaction.c b/components/driver/sdmmc_transaction.c index 8d87847282..52dec2991c 100644 --- a/components/driver/sdmmc_transaction.c +++ b/components/driver/sdmmc_transaction.c @@ -112,6 +112,7 @@ void sdmmc_host_transaction_handler_deinit() esp_err_t sdmmc_host_do_transaction(int slot, sdmmc_command_t* cmdinfo) { + esp_err_t ret; xSemaphoreTake(s_request_mutex, portMAX_DELAY); #ifdef CONFIG_PM_ENABLE esp_pm_lock_acquire(s_pm_lock); @@ -124,12 +125,14 @@ esp_err_t sdmmc_host_do_transaction(int slot, sdmmc_command_t* cmdinfo) if (cmdinfo->datalen < 4 || cmdinfo->blklen % 4 != 0) { ESP_LOGD(TAG, "%s: invalid size: total=%d block=%d", __func__, cmdinfo->datalen, cmdinfo->blklen); - return ESP_ERR_INVALID_SIZE; + ret = ESP_ERR_INVALID_SIZE; + goto out; } if ((intptr_t) cmdinfo->data % 4 != 0 || !esp_ptr_dma_capable(cmdinfo->data)) { ESP_LOGD(TAG, "%s: buffer %p can not be used for DMA", __func__, cmdinfo->data); - return ESP_ERR_INVALID_ARG; + ret = ESP_ERR_INVALID_ARG; + goto out; } // this clears "owned by IDMAC" bits memset(s_dma_desc, 0, sizeof(s_dma_desc)); @@ -146,10 +149,9 @@ esp_err_t sdmmc_host_do_transaction(int slot, sdmmc_command_t* cmdinfo) sdmmc_host_dma_prepare(&s_dma_desc[0], cmdinfo->blklen, cmdinfo->datalen); } // write command into hardware, this also sends the command to the card - esp_err_t ret = sdmmc_host_start_command(slot, hw_cmd, cmdinfo->arg); + ret = sdmmc_host_start_command(slot, hw_cmd, cmdinfo->arg); if (ret != ESP_OK) { - xSemaphoreGive(s_request_mutex); - return ret; + goto out; } // process events until transfer is complete cmdinfo->error = ESP_OK; @@ -161,6 +163,8 @@ esp_err_t sdmmc_host_do_transaction(int slot, sdmmc_command_t* cmdinfo) } } s_is_app_cmd = (ret == ESP_OK && cmdinfo->opcode == MMC_APP_CMD); + +out: #ifdef CONFIG_PM_ENABLE esp_pm_lock_release(s_pm_lock); #endif -- 2.40.0