From 069a55ce3195fe1fac0f134f460d222a5fa647fd Mon Sep 17 00:00:00 2001 From: Mario Paja Date: Sat, 30 Aug 2025 00:08:44 +0200 Subject: [PATCH 1/2] drivers: i2s: stm32_sai fix tx callback mem_block release This change fixes a wrong buffer release on tx callback which was not correctly fixed by https://github.com/zephyrproject-rtos/zephyr/pull/94696. Signed-off-by: Mario Paja --- drivers/i2s/i2s_stm32_sai.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/i2s/i2s_stm32_sai.c b/drivers/i2s/i2s_stm32_sai.c index dade7f2bc0041..2bb655c63a864 100644 --- a/drivers/i2s/i2s_stm32_sai.c +++ b/drivers/i2s/i2s_stm32_sai.c @@ -133,6 +133,7 @@ void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai) { struct i2s_stm32_sai_data *dev_data = CONTAINER_OF(hsai, struct i2s_stm32_sai_data, hsai); struct stream *stream = &dev_data->stream; + void *mem_block_tmp = stream->mem_block; struct queue_item item; int ret; @@ -183,7 +184,7 @@ void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai) exit: /* Free memory slab & exit */ - k_mem_slab_free(stream->i2s_cfg.mem_slab, stream->mem_block); + k_mem_slab_free(stream->i2s_cfg.mem_slab, mem_block_tmp); } void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai) From ececba1055168b371f5e36e186c93b4964368843 Mon Sep 17 00:00:00 2001 From: Mario Paja Date: Sat, 30 Aug 2025 12:19:03 +0200 Subject: [PATCH 2/2] drivers: i2s: stm32_sai set mem_block to NULL after STOPPING Set mem_block to NULL after the STOPPING command in order to exit TX callback at the end of the buffer transmission. Signed-off-by: Mario Paja --- drivers/i2s/i2s_stm32_sai.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/i2s/i2s_stm32_sai.c b/drivers/i2s/i2s_stm32_sai.c index 2bb655c63a864..bcaa5096ac3ce 100644 --- a/drivers/i2s/i2s_stm32_sai.c +++ b/drivers/i2s/i2s_stm32_sai.c @@ -155,6 +155,7 @@ void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai) if (stream->last_block) { LOG_DBG("TX Stopped ..."); stream->state = I2S_STATE_READY; + stream->mem_block = NULL; goto exit; } @@ -163,6 +164,7 @@ void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai) if (k_msgq_num_used_get(&stream->queue) == 0) { LOG_DBG("Exit TX callback, no more data in the queue"); stream->state = I2S_STATE_READY; + stream->mem_block = NULL; goto exit; }