From 352d18b48ead8b67fef4cc19f77d51455e8df28c Mon Sep 17 00:00:00 2001 From: Shengyu Qu Date: Sun, 12 Jul 2026 03:38:54 +0800 Subject: [PATCH 1/2] fix(spi_flash): add #if check for s_mxic_set_required_regs() Currently, s_mxic_set_required_regs() lacks checking for CONFIG_SPI_FLASH_SUPPORT_MXIC_OPI_CHIP. And this causes a defined but not used warning when MXIC flash driver is disabled in project config. So add a #if check for this to supress warning. Signed-off-by: Shengyu Qu (cherry picked from commit 062c948c1885222c2ee7c7fe5daa21d1a5e32f73) --- components/spi_flash/esp32s3/spi_flash_oct_flash_init.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/spi_flash/esp32s3/spi_flash_oct_flash_init.c b/components/spi_flash/esp32s3/spi_flash_oct_flash_init.c index ba78e0ed122..f55d562223d 100644 --- a/components/spi_flash/esp32s3/spi_flash_oct_flash_init.c +++ b/components/spi_flash/esp32s3/spi_flash_oct_flash_init.c @@ -219,6 +219,7 @@ static void s_flash_init_mxic(esp_rom_spiflash_read_mode_t mode) } #endif // #if CONFIG_SPI_FLASH_SUPPORT_MXIC_OPI_CHIP +#if CONFIG_SPI_FLASH_SUPPORT_MXIC_OPI_CHIP static void s_mxic_set_required_regs(uint32_t chip_id) { bool is_swap = false; @@ -230,6 +231,7 @@ static void s_mxic_set_required_regs(uint32_t chip_id) esp_rom_spi_set_dtr_swap_mode(0, is_swap, is_swap); esp_rom_spi_set_dtr_swap_mode(1, is_swap, is_swap); } +#endif /*---------------------------------------------------------------------------------------------------- From c7dd46e84b992aadd3f848068944858527328ac7 Mon Sep 17 00:00:00 2001 From: "C.S.M" Date: Thu, 23 Jul 2026 19:26:50 +0800 Subject: [PATCH 2/2] fix(spi_flash): Fix spi_flash leaks release aes-xts in error path (cherry picked from commit 305c5869ee8e8e072e2fc197a4674f97d091b2f9) --- components/spi_flash/spi_flash_chip_generic.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/components/spi_flash/spi_flash_chip_generic.c b/components/spi_flash/spi_flash_chip_generic.c index d48cc6a4984..2d6b0a5eb30 100644 --- a/components/spi_flash/spi_flash_chip_generic.c +++ b/components/spi_flash/spi_flash_chip_generic.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -546,7 +546,7 @@ esp_err_t spi_flash_chip_generic_write_encrypted(esp_flash_t *chip, const void * esp_flash_encryption->flash_encryption_data_prepare(address, (uint32_t *)data_bytes, block_size); err = chip->chip_drv->set_chip_write_protect(chip, false); if (err != ESP_OK) { - return err; + goto err_out; } // Waiting for encrypting buffer to finish and making result visible for SPI1 esp_flash_encryption->flash_encryption_done(); @@ -557,11 +557,11 @@ esp_err_t spi_flash_chip_generic_write_encrypted(esp_flash_t *chip, const void * err = chip->chip_drv->write(chip, (uint32_t *)data_bytes, address, length); if (err != ESP_OK) { - return err; + goto err_out; } err = chip->chip_drv->wait_idle(chip, chip->chip_drv->timeout->page_program_timeout); if (err != ESP_OK) { - return err; + goto err_out; } // Note: we don't wait for idle status here, because this way @@ -577,6 +577,11 @@ esp_err_t spi_flash_chip_generic_write_encrypted(esp_flash_t *chip, const void * esp_flash_encryption->flash_encryption_disable(); return err; + +err_out: + esp_flash_encryption->flash_encryption_destroy(); + esp_flash_encryption->flash_encryption_disable(); + return err; } #endif // !CONFIG_SPI_FLASH_ROM_IMPL || ESP_ROM_HAS_ENCRYPTED_WRITES_USING_LEGACY_DRV