From 75a874d4fdf623a8ceba45109633a3cc4ab4ccc2 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Wed, 29 Jul 2020 11:39:56 +0200 Subject: [PATCH] spi_flash: make {get,release}_temp_buffer OS functions optional Fixes a crash when calling a NULL release_temp_buffer pointer throug esp_flash_noos_functions, when doing a core dump. --- components/spi_flash/esp_flash_api.c | 10 +++++++--- components/spi_flash/spi_flash_os_func_noos.c | 11 +++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/components/spi_flash/esp_flash_api.c b/components/spi_flash/esp_flash_api.c index 872a89fdde..87e572738e 100644 --- a/components/spi_flash/esp_flash_api.c +++ b/components/spi_flash/esp_flash_api.c @@ -562,8 +562,10 @@ esp_err_t IRAM_ATTR esp_flash_read(esp_flash_t *chip, void *buffer, uint32_t add if (!direct_read) { size_t actual_len = 0; - temp_buffer = chip->os_func->get_temp_buffer(chip->os_func_data, read_chunk_size, &actual_len); - read_chunk_size = actual_len; + if (chip->os_func->get_temp_buffer != NULL) { + temp_buffer = chip->os_func->get_temp_buffer(chip->os_func_data, read_chunk_size, &actual_len); + read_chunk_size = actual_len; + } if (temp_buffer == NULL) { return ESP_ERR_NO_MEM; } @@ -600,7 +602,9 @@ esp_err_t IRAM_ATTR esp_flash_read(esp_flash_t *chip, void *buffer, uint32_t add buffer = (void*)((intptr_t)buffer + length_to_read); } while (err == ESP_OK && length > 0); - chip->os_func->release_temp_buffer(chip->os_func_data, temp_buffer); + if (chip->os_func->release_temp_buffer != NULL) { + chip->os_func->release_temp_buffer(chip->os_func_data, temp_buffer); + } return err; } diff --git a/components/spi_flash/spi_flash_os_func_noos.c b/components/spi_flash/spi_flash_os_func_noos.c index a71e5289d7..28b4195eca 100644 --- a/components/spi_flash/spi_flash_os_func_noos.c +++ b/components/spi_flash/spi_flash_os_func_noos.c @@ -70,19 +70,14 @@ static IRAM_ATTR esp_err_t delay_us(void *arg, unsigned us) return ESP_OK; } -// Currently when the os is not up yet, the caller is supposed to call esp_flash APIs with proper -// buffers. -IRAM_ATTR void* get_temp_buffer_not_supported(void* arg, size_t reqest_size, size_t* out_size) -{ - return NULL; -} - const DRAM_ATTR esp_flash_os_functions_t esp_flash_noos_functions = { .start = start, .end = end, .delay_us = delay_us, .region_protected = NULL, - .get_temp_buffer = get_temp_buffer_not_supported, + /* the caller is supposed to call esp_flash_read/esp_flash_write APIs with buffers in DRAM */ + .get_temp_buffer = NULL, + .release_temp_buffer = NULL, .yield = NULL, };