From 0017e75bdad9bb48c2161063793ac423de4a609f Mon Sep 17 00:00:00 2001 From: Liu Zhi Fu Date: Tue, 24 Jan 2017 20:40:14 +0800 Subject: [PATCH] freertos: fix protection issue in freertos queue event list When functions in queue.c calls listLIST_IS_EMPTY() to check queue event list, the queue list is protected by queue mutex, on the other hand, when xTaskIncrementTick() modify the queue list, the queue list is protected by xTaskQueueMutex, this may cause xTaskRemoveFromEventList operate on the empty queue list and cause problem. This commit is to fix this bug. may cause --- components/freertos/tasks.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/components/freertos/tasks.c b/components/freertos/tasks.c index f885e9c013..02d1842874 100644 --- a/components/freertos/tasks.c +++ b/components/freertos/tasks.c @@ -3012,9 +3012,14 @@ BaseType_t xReturn; This function assumes that a check has already been made to ensure that pxEventList is not empty. */ - pxUnblockedTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList ); - configASSERT( pxUnblockedTCB ); - ( void ) uxListRemove( &( pxUnblockedTCB->xEventListItem ) ); + if ( ( listLIST_IS_EMPTY( pxEventList ) ) == pdFALSE ) { + pxUnblockedTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList ); + configASSERT( pxUnblockedTCB ); + ( void ) uxListRemove( &( pxUnblockedTCB->xEventListItem ) ); + } else { + taskEXIT_CRITICAL_ISR(&xTaskQueueMutex); + return pdFALSE; + } if( uxSchedulerSuspended[ xPortGetCoreID() ] == ( UBaseType_t ) pdFALSE ) { @@ -3025,9 +3030,7 @@ BaseType_t xReturn; { /* The delayed and ready lists cannot be accessed, so hold this task pending until the scheduler is resumed. */ - taskENTER_CRITICAL(&xTaskQueueMutex); vListInsertEnd( &( xPendingReadyList[ xPortGetCoreID() ] ), &( pxUnblockedTCB->xEventListItem ) ); - taskEXIT_CRITICAL(&xTaskQueueMutex); } if ( tskCAN_RUN_HERE(pxUnblockedTCB->xCoreID) && pxUnblockedTCB->uxPriority >= pxCurrentTCB[ xPortGetCoreID() ]->uxPriority ) -- 2.40.0