From 4ee717950df4b6758c9def1fa576438077af0bf8 Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Mon, 13 Oct 2025 11:07:12 +0200 Subject: [PATCH] fix(freertos-smp): Stream Buffer task lists must be manipulated in critical sections Stream buffer task lists (xTaskWaitingToSend and xTaskWaitingToReceive) are updated without critical sections. These objects are shared objects and can be updated from an ISR context as well. Hence, these lists must always be updated in critical sections. --- stream_buffer.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/stream_buffer.c b/stream_buffer.c index fe52427c6..cc01d27ea 100644 --- a/stream_buffer.c +++ b/stream_buffer.c @@ -947,7 +947,11 @@ size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer, traceBLOCKING_ON_STREAM_BUFFER_SEND( xStreamBuffer ); ( void ) xTaskNotifyWaitIndexed( pxStreamBuffer->uxNotificationIndex, ( uint32_t ) 0, ( uint32_t ) 0, NULL, xTicksToWait ); - pxStreamBuffer->xTaskWaitingToSend = NULL; + sbENTER_CRITICAL( pxStreamBuffer ); + { + pxStreamBuffer->xTaskWaitingToSend = NULL; + } + sbEXIT_CRITICAL( pxStreamBuffer ); } while( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE ); } else @@ -1171,7 +1175,11 @@ size_t xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer, /* Wait for data to be available. */ traceBLOCKING_ON_STREAM_BUFFER_RECEIVE( xStreamBuffer ); ( void ) xTaskNotifyWaitIndexed( pxStreamBuffer->uxNotificationIndex, ( uint32_t ) 0, ( uint32_t ) 0, NULL, xTicksToWait ); - pxStreamBuffer->xTaskWaitingToReceive = NULL; + sbENTER_CRITICAL( pxStreamBuffer ); + { + pxStreamBuffer->xTaskWaitingToReceive = NULL; + } + sbEXIT_CRITICAL( pxStreamBuffer ); /* Recheck the data available after blocking. */ xBytesAvailable = prvBytesInBuffer( pxStreamBuffer );