From d1fababfc5e4cc2221adb04bece89809024a55f2 Mon Sep 17 00:00:00 2001 From: nuttxs Date: Fri, 18 Jul 2025 17:54:04 +0800 Subject: [PATCH] =?UTF-8?q?arch/xtensa:=20esp32(s3)=5Fasync=5Fop()=20using?= =?UTF-8?q?=20nxsem=5Fwait(),=20threads=20may=20return=20early=20due=20to?= =?UTF-8?q?=20signal=20interruption=20(EINTR).=20This=20makes=20the=20main?= =?UTF-8?q?=20thread=20think=20the=20async=20operation=20is=20done,=20but?= =?UTF-8?q?=20the=20background=20worker=20thread=20is=20still=20running?= =?UTF-8?q?=E2=80=94risking=20access=20to=20freed=20memory,=20race=20condi?= =?UTF-8?q?tions,=20crashes=20or=20undefined=20behavior.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using nxsem_wait_uninterruptible():the main thread waits until the worker thread finishes, preventing these issues. Signed-off-by: nuttxs --- arch/xtensa/src/esp32/esp32_spiflash.c | 2 +- arch/xtensa/src/esp32s3/esp32s3_spiflash_mtd.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/xtensa/src/esp32/esp32_spiflash.c b/arch/xtensa/src/esp32/esp32_spiflash.c index 9622fc77bf..a1d5f06284 100644 --- a/arch/xtensa/src/esp32/esp32_spiflash.c +++ b/arch/xtensa/src/esp32/esp32_spiflash.c @@ -1732,7 +1732,7 @@ static int esp32_async_op(enum spiflash_op_code_e opcode, ret = work_queue(LPWORK, &g_work, esp32_spiflash_work, &work_arg, 0); if (ret == 0) { - nxsem_wait(&work_arg.sem); + nxsem_wait_uninterruptible(&work_arg.sem); ret = work_arg.ret; } diff --git a/arch/xtensa/src/esp32s3/esp32s3_spiflash_mtd.c b/arch/xtensa/src/esp32s3/esp32s3_spiflash_mtd.c index ab0a0d596c..2e58fbf9d8 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_spiflash_mtd.c +++ b/arch/xtensa/src/esp32s3/esp32s3_spiflash_mtd.c @@ -857,7 +857,7 @@ static int esp32s3_async_op(enum spiflash_op_code_e opcode, ret = work_queue(LPWORK, &g_work, esp32s3_spiflash_work, &work_arg, 0); if (ret == 0) { - nxsem_wait(&work_arg.sem); + nxsem_wait_uninterruptible(&work_arg.sem); ret = work_arg.ret; }