Skip to content

Commit

Permalink
Update coverity violation for SMP (#81)
Browse files Browse the repository at this point in the history
* Update coverity violation for SMP ( code surrounded by configNUMBER_OF_CORES > 1 ).
* Single core and common code are still scanned by lint tool.
  • Loading branch information
chinglee-iot authored May 16, 2023
1 parent b40b9e3 commit c4a8d7a
Show file tree
Hide file tree
Showing 4 changed files with 305 additions and 167 deletions.
1 change: 1 addition & 0 deletions .github/lexicon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ coproc
coprocessor
coprocessors
coreid
coverity
covfs
cp
cpacr
Expand Down
72 changes: 72 additions & 0 deletions MISRA.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# MISRA Compliance

FreeRTOS-Kernel conforms to [MISRA C:2012](https://www.misra.org.uk/misra-c)
guidelines, with the deviations listed below. Compliance is checked with
Coverity static analysis. Since the FreeRTOS kernel is designed for
small-embedded devices, it needs to have a very small memory footprint and
has to be efficient. To achieve that and to increase the performance, it
deviates from some MISRA rules. The specific deviations, suppressed inline,
are listed below.

Additionally, [MISRA configuration](#misra-configuration) contains project
wide deviations.

### Suppressed with Coverity Comments
To find the violation references in the source files run grep on the source code
with ( Assuming rule 8.4 violation; with justification in point 1 ):
```
grep 'MISRA Ref 8.4.1' . -rI
```

#### Rule 8.4

_Ref 8.4.1_

- MISRA C:2012 Rule 8.4: A compatible declaration shall be visible when an
object or function with external linkage is defined.
This rule requires that a compatible declaration is made available
in a header file when an object with external linkage is defined.
pxCurrentTCB(s) is defined with external linkage but it is only
referenced from the assembly code in the port files. Therefore, adding
a declaration in header file is not useful as the assembly code will
still need to declare it separately.

### MISRA configuration

Copy below content to `misra.conf` to run Coverity on FreeRTOS-Kernel.

```
// MISRA C-2012 Rules
{
version : "2.0",
standard : "c2012",
title: "Coverity MISRA Configuration",
deviations : [
// Disable the following rules.
{
deviation: "Directive 4.8",
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."
},
{
deviation: "Directive 4.9",
reason: "FreeRTOS-Kernel is optimised to work on small micro-controllers. To achieve that, function-like macros are used."
},
{
deviation: "Rule 1.2",
reason: "The __attribute__ tags are used via macros which are defined in port files."
},
{
deviation: "Rule 3.1",
reason: "We post HTTP links in code comments which contain // inside comments blocks."
},
{
deviation: "Rule 8.7",
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."
},
{
deviation: "Rule 11.5",
reason: "Allow casts from `void *`. List owner, pvOwner, is stored as `void *` and are cast to various types for use in functions."
}
]
}
```
47 changes: 42 additions & 5 deletions include/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
* \ingroup Tasks
*/
struct tskTaskControlBlock; /* The old naming convention is used to prevent breaking kernel aware debuggers. */
typedef struct tskTaskControlBlock * TaskHandle_t;
typedef struct tskTaskControlBlock * TaskHandle_t;
typedef const struct tskTaskControlBlock * ConstTaskHandle_t;

/*
* Defines the prototype to which the application task hook function must
Expand Down Expand Up @@ -193,7 +194,7 @@ typedef enum
*
* \ingroup TaskUtils
*/
#define tskNO_AFFINITY ( ( UBaseType_t ) -1U )
#define tskNO_AFFINITY ( ( UBaseType_t ) -1 )

/**
* task. h
Expand Down Expand Up @@ -271,7 +272,7 @@ typedef enum
#define taskSCHEDULER_RUNNING ( ( BaseType_t ) 2 )

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

/*-----------------------------------------------------------
* TASK CREATION API
Expand Down Expand Up @@ -746,7 +747,7 @@ typedef enum
* \defgroup vTaskAllocateMPURegions vTaskAllocateMPURegions
* \ingroup Tasks
*/
void vTaskAllocateMPURegions( TaskHandle_t xTask,
void vTaskAllocateMPURegions( TaskHandle_t xTaskToModify,
const MemoryRegion_t * const pxRegions ) PRIVILEGED_FUNCTION;

/**
Expand Down Expand Up @@ -1363,7 +1364,7 @@ BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
* }
* }
*/
UBaseType_t vTaskCoreAffinityGet( const TaskHandle_t xTask );
UBaseType_t vTaskCoreAffinityGet( ConstTaskHandle_t xTask );
#endif

#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
Expand Down Expand Up @@ -3418,6 +3419,42 @@ void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNC
*/
void vTaskYieldWithinAPI( void );

/*
* This function is only intended for use when implementing a port of the scheduler
* and is only available when portCRITICAL_NESTING_IN_TCB is set to 1 or configNUMBER_OF_CORES
* is greater than 1. This function can be used in the implementation of portENTER_CRITICAL
* if port wants to maintain critical nesting count in TCB in single core FreeRTOS.
* It should be used in the implementation of portENTER_CRITICAL if port is running a
* multiple core FreeRTOS.
*/
void vTaskEnterCritical( void );

/*
* This function is only intended for use when implementing a port of the scheduler
* and is only available when portCRITICAL_NESTING_IN_TCB is set to 1 or configNUMBER_OF_CORES
* is greater than 1. This function can be used in the implementation of portEXIT_CRITICAL
* if port wants to maintain critical nesting count in TCB in single core FreeRTOS.
* It should be used in the implementation of portEXIT_CRITICAL if port is running a
* multiple core FreeRTOS.
*/
void vTaskExitCritical( void );

/*
* This function is only intended for use when implementing a port of the scheduler
* and is only available when configNUMBER_OF_CORES is greater than 1. This function
* should be used in the implementation of portENTER_CRITICAL_FROM_ISR if port is
* running a multiple core FreeRTOS.
*/
portBASE_TYPE vTaskEnterCriticalFromISR( void );

/*
* This function is only intended for use when implementing a port of the scheduler
* and is only available when configNUMBER_OF_CORES is greater than 1. This function
* should be used in the implementation of portEXIT_CRITICAL_FROM_ISR if port is
* running a multiple core FreeRTOS.
*/
void vTaskExitCriticalFromISR( portBASE_TYPE xSavedInterruptStatus );

/* *INDENT-OFF* */
#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit c4a8d7a

Please sign in to comment.