From 8cfa7152f75c397e04eb779d2812c0edd26bd1c7 Mon Sep 17 00:00:00 2001 From: bradleysmith23 <74752142+bradleysmith23@users.noreply.github.com> Date: Mon, 12 Feb 2024 21:11:30 -0800 Subject: [PATCH] Fix MISRA C 2012 Rule 13.2 Violations (#979) * Fix violations of MISRA rule 13.2 * Fix typo in UBaseType_t * Uncrustify: triggered by comment. * Run Github Actions. * Remove temp variable for uxCurrentNumberOfTasks Co-authored-by: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com> * Declare uxCurrentListLength at top of function, update comment. * Update location of uxCurrentListLength Declaration * Uncrustify: triggered by comment. * Run Github Actions * Uncrustify: triggered by comment. * Run Github Actions. * Update comment explaining use of temp variable --------- Co-authored-by: GitHub Action Co-authored-by: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com> Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com> --- tasks.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tasks.c b/tasks.c index d226a91deca..95f60b1fb60 100644 --- a/tasks.c +++ b/tasks.c @@ -3208,6 +3208,8 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, #if ( configNUMBER_OF_CORES == 1 ) { + UBaseType_t uxCurrentListLength; + if( xSchedulerRunning != pdFALSE ) { /* Reset the next expected unblock time in case it referred to the @@ -3236,7 +3238,13 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, /* The scheduler is not running, but the task that was pointed * to by pxCurrentTCB has just been suspended and pxCurrentTCB * must be adjusted to point to a different task. */ - if( listCURRENT_LIST_LENGTH( &xSuspendedTaskList ) == uxCurrentNumberOfTasks ) + + /* Use a temp variable as a distinct sequence point for reading + * volatile variables prior to a comparison to ensure compliance + * with MISRA C 2012 Rule 13.2. */ + uxCurrentListLength = listCURRENT_LIST_LENGTH( &xSuspendedTaskList ); + + if( uxCurrentListLength == uxCurrentNumberOfTasks ) { /* No other tasks are ready, so set pxCurrentTCB back to * NULL so when the next task is created pxCurrentTCB will