From a118f6a35177342d45b17b278af605143e61f59c Mon Sep 17 00:00:00 2001 From: guilherme giacomo simoes Date: Tue, 1 Oct 2024 23:26:35 -0300 Subject: [PATCH 1/3] refactor: change methods ENTER|EXIT critical The read and write from BaseType_t, can be do in a atomic context, and dont need a mutex contol. Change this methods for access the critical regiao only if is neccessary. For make this, create a macro in portable.h that apoint to tasENTER|EXIT_CRITIAL() function. Now, if port is guarantee that access BaseType_t in atomic context, a empty macro can be define in portmacro.h, like this: Signed-off-by: guilherme giacomo simoes --- include/portable.h | 8 ++++++++ queue.c | 8 ++++---- tasks.c | 12 ++++++------ timers.c | 8 ++++---- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/include/portable.h b/include/portable.h index f7afb69792c..874d261ff9c 100644 --- a/include/portable.h +++ b/include/portable.h @@ -85,6 +85,14 @@ #define portARCH_NAME NULL #endif +#ifndef portBASE_TYPE_ENTER_CRITICAL + #define portBASE_TYPE_ENTER_CRITICAL() taskENTER_CRITICAL() +#endif + +#ifndef portBASE_TYPE_EXIT_CRITICAL + #define portBASE_TYPE_EXIT_CRITICAL() taskEXIT_CRITICAL() +#endif + #ifndef configSTACK_DEPTH_TYPE #define configSTACK_DEPTH_TYPE StackType_t #endif diff --git a/queue.c b/queue.c index 34cf17ba69a..fd62489f569 100644 --- a/queue.c +++ b/queue.c @@ -2202,11 +2202,11 @@ UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue ) configASSERT( xQueue ); - taskENTER_CRITICAL(); + portBASE_TYPE_ENTER_CRITICAL(); { uxReturn = ( ( Queue_t * ) xQueue )->uxMessagesWaiting; } - taskEXIT_CRITICAL(); + portBASE_TYPE_EXIT_CRITICAL(); traceRETURN_uxQueueMessagesWaiting( uxReturn ); @@ -2223,11 +2223,11 @@ UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue ) configASSERT( pxQueue ); - taskENTER_CRITICAL(); + portBASE_TYPE_ENTER_CRITICAL(); { uxReturn = ( UBaseType_t ) ( pxQueue->uxLength - pxQueue->uxMessagesWaiting ); } - taskEXIT_CRITICAL(); + portBASE_TYPE_EXIT_CRITICAL(); traceRETURN_uxQueueSpacesAvailable( uxReturn ); diff --git a/tasks.c b/tasks.c index 483ad29e69c..1be3fca914c 100644 --- a/tasks.c +++ b/tasks.c @@ -2623,14 +2623,14 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, traceENTER_uxTaskPriorityGet( xTask ); - taskENTER_CRITICAL(); + portBASE_TYPE_ENTER_CRITICAL(); { /* If null is passed in here then it is the priority of the task * that called uxTaskPriorityGet() that is being queried. */ pxTCB = prvGetTCBFromHandle( xTask ); uxReturn = pxTCB->uxPriority; } - taskEXIT_CRITICAL(); + portBASE_TYPE_EXIT_CRITICAL(); traceRETURN_uxTaskPriorityGet( uxReturn ); @@ -2697,14 +2697,14 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, traceENTER_uxTaskBasePriorityGet( xTask ); - taskENTER_CRITICAL(); + portBASE_TYPE_ENTER_CRITICAL(); { /* If null is passed in here then it is the base priority of the task * that called uxTaskBasePriorityGet() that is being queried. */ pxTCB = prvGetTCBFromHandle( xTask ); uxReturn = pxTCB->uxBasePriority; } - taskEXIT_CRITICAL(); + portBASE_TYPE_EXIT_CRITICAL(); traceRETURN_uxTaskBasePriorityGet( uxReturn ); @@ -3040,12 +3040,12 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, traceENTER_vTaskCoreAffinityGet( xTask ); - taskENTER_CRITICAL(); + portBASE_TYPE_ENTER_CRITICAL(); { pxTCB = prvGetTCBFromHandle( xTask ); uxCoreAffinityMask = pxTCB->uxCoreAffinityMask; } - taskEXIT_CRITICAL(); + portBASE_TYPE_EXIT_CRITICAL(); traceRETURN_vTaskCoreAffinityGet( uxCoreAffinityMask ); diff --git a/timers.c b/timers.c index 4e2a9f61f3a..03765fe7b9f 100644 --- a/timers.c +++ b/timers.c @@ -601,7 +601,7 @@ traceENTER_xTimerGetReloadMode( xTimer ); configASSERT( xTimer ); - taskENTER_CRITICAL(); + portBASE_TYPE_ENTER_CRITICAL(); { if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) == 0U ) { @@ -614,7 +614,7 @@ xReturn = pdTRUE; } } - taskEXIT_CRITICAL(); + portBASE_TYPE_EXIT_CRITICAL(); traceRETURN_xTimerGetReloadMode( xReturn ); @@ -1169,7 +1169,7 @@ configASSERT( xTimer ); /* Is the timer in the list of active timers? */ - taskENTER_CRITICAL(); + portBASE_TYPE_ENTER_CRITICAL(); { if( ( pxTimer->ucStatus & tmrSTATUS_IS_ACTIVE ) == 0U ) { @@ -1180,7 +1180,7 @@ xReturn = pdTRUE; } } - taskEXIT_CRITICAL(); + portBASE_TYPE_EXIT_CRITICAL(); traceRETURN_xTimerIsTimerActive( xReturn ); From 472b9d2f63ba9f83b7b85b4fcd5473ece25327e9 Mon Sep 17 00:00:00 2001 From: Gaurav Aggarwal Date: Thu, 3 Oct 2024 10:34:12 +0000 Subject: [PATCH 2/3] Fix formatting check Signed-off-by: Gaurav Aggarwal --- include/portable.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/portable.h b/include/portable.h index 874d261ff9c..1b088b4278a 100644 --- a/include/portable.h +++ b/include/portable.h @@ -86,11 +86,11 @@ #endif #ifndef portBASE_TYPE_ENTER_CRITICAL - #define portBASE_TYPE_ENTER_CRITICAL() taskENTER_CRITICAL() + #define portBASE_TYPE_ENTER_CRITICAL() taskENTER_CRITICAL() #endif #ifndef portBASE_TYPE_EXIT_CRITICAL - #define portBASE_TYPE_EXIT_CRITICAL() taskEXIT_CRITICAL() + #define portBASE_TYPE_EXIT_CRITICAL() taskEXIT_CRITICAL() #endif #ifndef configSTACK_DEPTH_TYPE From 81c15b1bbfa174f8bd2bb12005be5c847b3b67b6 Mon Sep 17 00:00:00 2001 From: Gaurav Aggarwal Date: Thu, 3 Oct 2024 11:58:04 +0000 Subject: [PATCH 3/3] Fix link verifier Signed-off-by: Gaurav Aggarwal --- .github/third_party_tools.md | 2 +- examples/coverity/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/third_party_tools.md b/.github/third_party_tools.md index afe84b25723..09bd6d62c7f 100644 --- a/.github/third_party_tools.md +++ b/.github/third_party_tools.md @@ -11,4 +11,4 @@ team. | Tool | Website | Getting Started | |------|---------|-----------------| | Code Sonar | [Link](https://codesecure.com/our-products/codesonar/) | [Link](https://github.com/CodeSecure-SE/FreeRTOS-Kernel/blob/main/examples/codesonar/README.md) | -| Coverity | [Link](https://www.synopsys.com/software-integrity/security-testing/static-analysis-sast.html) | [Link](../examples/coverity/README.md) | +| Coverity | [Link](https://www.blackduck.com/static-analysis-tools-sast/coverity.html) | [Link](../examples/coverity/README.md) | diff --git a/examples/coverity/README.md b/examples/coverity/README.md index 967f33dca93..367c1d6e8e8 100644 --- a/examples/coverity/README.md +++ b/examples/coverity/README.md @@ -1,6 +1,6 @@ # MISRA Compliance for FreeRTOS-Kernel FreeRTOS-Kernel is MISRA C:2012 compliant. This directory contains a project to -run [Synopsys Coverity](https://www.synopsys.com/software-integrity/security-testing/static-analysis-sast.html) +run [Synopsys Coverity](https://www.blackduck.com/static-analysis-tools-sast/coverity.html) for checking MISRA compliance. > **Note**