Skip to content

Commit a9e7ccb

Browse files
committed
Merge branch 'contrib/github_pr_10648' into 'master'
[AES] Timeout: return error dont abort (GitHub PR) Closes IDFGH-9265 See merge request espressif/esp-idf!22266
2 parents 1ed5d3a + ca0f982 commit a9e7ccb

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

components/mbedtls/port/aes/dma/esp_aes.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@
7474
busy-waiting, 30000 bytes is approx 0.5 ms */
7575
#define AES_DMA_INTR_TRIG_LEN 2000
7676

77+
/* With buffers in PSRAM (worst condition) we still achieve a speed of 4 MB/s
78+
thus a 2 second timeout value should be suffient for even very large buffers.
79+
*/
80+
#define AES_WAIT_INTR_TIMEOUT_MS 2000
7781

7882
#if defined(CONFIG_MBEDTLS_AES_USE_INTERRUPT)
7983
static SemaphoreHandle_t op_complete_sem;
@@ -209,14 +213,14 @@ static esp_err_t esp_aes_isr_initialise( void )
209213
#endif // CONFIG_MBEDTLS_AES_USE_INTERRUPT
210214

211215
/* Wait for AES hardware block operation to complete */
212-
static void esp_aes_dma_wait_complete(bool use_intr, lldesc_t *output_desc)
216+
static int esp_aes_dma_wait_complete(bool use_intr, lldesc_t *output_desc)
213217
{
214218
#if defined (CONFIG_MBEDTLS_AES_USE_INTERRUPT)
215219
if (use_intr) {
216-
if (!xSemaphoreTake(op_complete_sem, 2000 / portTICK_PERIOD_MS)) {
220+
if (!xSemaphoreTake(op_complete_sem, AES_WAIT_INTR_TIMEOUT_MS / portTICK_PERIOD_MS)) {
217221
/* indicates a fundamental problem with driver */
218-
ESP_LOGE("AES", "Timed out waiting for completion of AES Interrupt");
219-
abort();
222+
ESP_LOGE(TAG, "Timed out waiting for completion of AES Interrupt");
223+
return -1;
220224
}
221225
#ifdef CONFIG_PM_ENABLE
222226
esp_pm_lock_release(s_pm_cpu_lock);
@@ -230,6 +234,7 @@ static void esp_aes_dma_wait_complete(bool use_intr, lldesc_t *output_desc)
230234
aes_hal_wait_done();
231235

232236
esp_aes_wait_dma_done(output_desc);
237+
return 0;
233238
}
234239

235240

@@ -436,7 +441,12 @@ static int esp_aes_process_dma(esp_aes_context *ctx, const unsigned char *input,
436441
}
437442

438443
aes_hal_transform_dma_start(blocks);
439-
esp_aes_dma_wait_complete(use_intr, out_desc_tail);
444+
445+
if (esp_aes_dma_wait_complete(use_intr, out_desc_tail) < 0) {
446+
ESP_LOGE(TAG, "esp_aes_dma_wait_complete failed");
447+
ret = -1;
448+
goto cleanup;
449+
}
440450

441451
#if (CONFIG_SPIRAM && SOC_PSRAM_DMA_CAPABLE)
442452
if (block_bytes > 0) {
@@ -561,7 +571,11 @@ int esp_aes_process_dma_gcm(esp_aes_context *ctx, const unsigned char *input, un
561571

562572
aes_hal_transform_dma_gcm_start(blocks);
563573

564-
esp_aes_dma_wait_complete(use_intr, out_desc_head);
574+
if (esp_aes_dma_wait_complete(use_intr, out_desc_head) < 0) {
575+
ESP_LOGE(TAG, "esp_aes_dma_wait_complete failed");
576+
ret = -1;
577+
goto cleanup;
578+
}
565579

566580
aes_hal_transform_dma_finish();
567581

0 commit comments

Comments
 (0)