Skip to content

Commit c4a8d7a

Browse files
authored
Update coverity violation for SMP (#81)
* Update coverity violation for SMP ( code surrounded by configNUMBER_OF_CORES > 1 ). * Single core and common code are still scanned by lint tool.
1 parent b40b9e3 commit c4a8d7a

File tree

4 files changed

+305
-167
lines changed

4 files changed

+305
-167
lines changed

.github/lexicon.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ coproc
317317
coprocessor
318318
coprocessors
319319
coreid
320+
coverity
320321
covfs
321322
cp
322323
cpacr

MISRA.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# MISRA Compliance
2+
3+
FreeRTOS-Kernel conforms to [MISRA C:2012](https://www.misra.org.uk/misra-c)
4+
guidelines, with the deviations listed below. Compliance is checked with
5+
Coverity static analysis. Since the FreeRTOS kernel is designed for
6+
small-embedded devices, it needs to have a very small memory footprint and
7+
has to be efficient. To achieve that and to increase the performance, it
8+
deviates from some MISRA rules. The specific deviations, suppressed inline,
9+
are listed below.
10+
11+
Additionally, [MISRA configuration](#misra-configuration) contains project
12+
wide deviations.
13+
14+
### Suppressed with Coverity Comments
15+
To find the violation references in the source files run grep on the source code
16+
with ( Assuming rule 8.4 violation; with justification in point 1 ):
17+
```
18+
grep 'MISRA Ref 8.4.1' . -rI
19+
```
20+
21+
#### Rule 8.4
22+
23+
_Ref 8.4.1_
24+
25+
- MISRA C:2012 Rule 8.4: A compatible declaration shall be visible when an
26+
object or function with external linkage is defined.
27+
This rule requires that a compatible declaration is made available
28+
in a header file when an object with external linkage is defined.
29+
pxCurrentTCB(s) is defined with external linkage but it is only
30+
referenced from the assembly code in the port files. Therefore, adding
31+
a declaration in header file is not useful as the assembly code will
32+
still need to declare it separately.
33+
34+
### MISRA configuration
35+
36+
Copy below content to `misra.conf` to run Coverity on FreeRTOS-Kernel.
37+
38+
```
39+
// MISRA C-2012 Rules
40+
{
41+
version : "2.0",
42+
standard : "c2012",
43+
title: "Coverity MISRA Configuration",
44+
deviations : [
45+
// Disable the following rules.
46+
{
47+
deviation: "Directive 4.8",
48+
reason: "HeapRegion_t and HeapStats_t are used only in heap files but declared in portable.h which is included in multiple source files. As a result, these definitions appear in multiple source files where they are not used."
49+
},
50+
{
51+
deviation: "Directive 4.9",
52+
reason: "FreeRTOS-Kernel is optimised to work on small micro-controllers. To achieve that, function-like macros are used."
53+
},
54+
{
55+
deviation: "Rule 1.2",
56+
reason: "The __attribute__ tags are used via macros which are defined in port files."
57+
},
58+
{
59+
deviation: "Rule 3.1",
60+
reason: "We post HTTP links in code comments which contain // inside comments blocks."
61+
},
62+
{
63+
deviation: "Rule 8.7",
64+
reason: "API functions are not used by the library outside of the files they are defined; however, they must be externally visible in order to be used by an application."
65+
},
66+
{
67+
deviation: "Rule 11.5",
68+
reason: "Allow casts from `void *`. List owner, pvOwner, is stored as `void *` and are cast to various types for use in functions."
69+
}
70+
]
71+
}
72+
```

include/task.h

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484
* \ingroup Tasks
8585
*/
8686
struct tskTaskControlBlock; /* The old naming convention is used to prevent breaking kernel aware debuggers. */
87-
typedef struct tskTaskControlBlock * TaskHandle_t;
87+
typedef struct tskTaskControlBlock * TaskHandle_t;
88+
typedef const struct tskTaskControlBlock * ConstTaskHandle_t;
8889

8990
/*
9091
* Defines the prototype to which the application task hook function must
@@ -193,7 +194,7 @@ typedef enum
193194
*
194195
* \ingroup TaskUtils
195196
*/
196-
#define tskNO_AFFINITY ( ( UBaseType_t ) -1U )
197+
#define tskNO_AFFINITY ( ( UBaseType_t ) -1 )
197198

198199
/**
199200
* task. h
@@ -271,7 +272,7 @@ typedef enum
271272
#define taskSCHEDULER_RUNNING ( ( BaseType_t ) 2 )
272273

273274
/* Checks if core ID is valid. */
274-
#define taskVALID_CORE_ID( xCoreID ) ( ( BaseType_t ) ( ( 0 <= xCoreID ) && ( xCoreID < configNUMBER_OF_CORES ) ) )
275+
#define taskVALID_CORE_ID( xCoreID ) ( ( ( ( ( BaseType_t ) 0 <= ( xCoreID ) ) && ( ( xCoreID ) < ( BaseType_t ) configNUMBER_OF_CORES ) ) ) ? ( pdTRUE ) : ( pdFALSE ) )
275276

276277
/*-----------------------------------------------------------
277278
* TASK CREATION API
@@ -746,7 +747,7 @@ typedef enum
746747
* \defgroup vTaskAllocateMPURegions vTaskAllocateMPURegions
747748
* \ingroup Tasks
748749
*/
749-
void vTaskAllocateMPURegions( TaskHandle_t xTask,
750+
void vTaskAllocateMPURegions( TaskHandle_t xTaskToModify,
750751
const MemoryRegion_t * const pxRegions ) PRIVILEGED_FUNCTION;
751752

752753
/**
@@ -1363,7 +1364,7 @@ BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
13631364
* }
13641365
* }
13651366
*/
1366-
UBaseType_t vTaskCoreAffinityGet( const TaskHandle_t xTask );
1367+
UBaseType_t vTaskCoreAffinityGet( ConstTaskHandle_t xTask );
13671368
#endif
13681369

13691370
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
@@ -3418,6 +3419,42 @@ void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNC
34183419
*/
34193420
void vTaskYieldWithinAPI( void );
34203421

3422+
/*
3423+
* This function is only intended for use when implementing a port of the scheduler
3424+
* and is only available when portCRITICAL_NESTING_IN_TCB is set to 1 or configNUMBER_OF_CORES
3425+
* is greater than 1. This function can be used in the implementation of portENTER_CRITICAL
3426+
* if port wants to maintain critical nesting count in TCB in single core FreeRTOS.
3427+
* It should be used in the implementation of portENTER_CRITICAL if port is running a
3428+
* multiple core FreeRTOS.
3429+
*/
3430+
void vTaskEnterCritical( void );
3431+
3432+
/*
3433+
* This function is only intended for use when implementing a port of the scheduler
3434+
* and is only available when portCRITICAL_NESTING_IN_TCB is set to 1 or configNUMBER_OF_CORES
3435+
* is greater than 1. This function can be used in the implementation of portEXIT_CRITICAL
3436+
* if port wants to maintain critical nesting count in TCB in single core FreeRTOS.
3437+
* It should be used in the implementation of portEXIT_CRITICAL if port is running a
3438+
* multiple core FreeRTOS.
3439+
*/
3440+
void vTaskExitCritical( void );
3441+
3442+
/*
3443+
* This function is only intended for use when implementing a port of the scheduler
3444+
* and is only available when configNUMBER_OF_CORES is greater than 1. This function
3445+
* should be used in the implementation of portENTER_CRITICAL_FROM_ISR if port is
3446+
* running a multiple core FreeRTOS.
3447+
*/
3448+
portBASE_TYPE vTaskEnterCriticalFromISR( void );
3449+
3450+
/*
3451+
* This function is only intended for use when implementing a port of the scheduler
3452+
* and is only available when configNUMBER_OF_CORES is greater than 1. This function
3453+
* should be used in the implementation of portEXIT_CRITICAL_FROM_ISR if port is
3454+
* running a multiple core FreeRTOS.
3455+
*/
3456+
void vTaskExitCriticalFromISR( portBASE_TYPE xSavedInterruptStatus );
3457+
34213458
/* *INDENT-OFF* */
34223459
#ifdef __cplusplus
34233460
}

0 commit comments

Comments
 (0)