Skip to content

Commit f1043c4

Browse files
authored
MISRA 17.12 fixes, justifications for other reporting issues. (#1372)
* [8.6] Suppress declaration without definitions warnings This is expected from the portable header as it is implemented by the port. * [21.3] Document unsupressed deviation Deviations which are unsupressed should be documented for user awareness. * [2.2] Disclose dead code warning * [2.1] Justify unreachable code in example * [17.12] Add addressing operator to callback function This is required to disambiguate a function call and a function to-be called * [4.12] Explain deviation for dynamic allocation * [8.6] Remove suppression, instead explain reporting * Suppress false null dereference Coverity provides a false positive of pxQueueSetContainer being null.
1 parent 0f8efd9 commit f1043c4

4 files changed

Lines changed: 93 additions & 3 deletions

File tree

MISRA.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ grep 'MISRA Ref 8.4.1' . -rI
1919
```
2020

2121
#### Dir 4.7
22+
2223
MISRA C:2012 Dir 4.7: If a function returns error information, then that error
2324
information shall be tested.
2425

@@ -143,3 +144,90 @@ _Ref 21.6.1_
143144
- The Standard Library function snprintf is used in vTaskListTasks and
144145
vTaskGetRunTimeStatistics APIs, both of which are utility functions only and
145146
are not considered part of core kernel implementation.
147+
148+
### Unsuppressed Deviations
149+
150+
Certain deviating code is left unsuppressed for awareness. These violations
151+
will be reported when audited by a MISRA-checking static analysis tool.
152+
153+
Some of these unsuppressed exceptions correspond to example code provided
154+
either for demonstration or verification of the FreeRTOS kernel. This code
155+
is not considered part of the kernel implementation and should not be used
156+
in an application.
157+
158+
Other unsuppressed violations are left present in the kernel implementation
159+
as implementations, code, or other missing functionality being flagged for
160+
violations will be present with the porting layer provided by the
161+
application. The presence of these errors after providing a port indicates
162+
a valid MISRA issue.
163+
164+
#### Rule 2.1
165+
166+
MISRA C:2012 Dir 2.1: A project shall not contain unreachable code
167+
168+
_Ref 2.1_
169+
- Simplified example contains unreachable code for demonstration of
170+
FreeRTOS scheduler. A production implementation should not contain
171+
this.
172+
173+
Affected Files:
174+
- examples/cmake_example/main.c
175+
176+
#### Rule 2.2
177+
178+
MISRA C:2012 Dir 2.2: There shall be no dead code.
179+
180+
_Ref 2.2_
181+
- `vPortEndScheduler` is erroneously determined to be dead code due to
182+
the use of a simplified verification port.
183+
184+
Affected Files:
185+
- tasks.c
186+
187+
#### Dir 4.12
188+
189+
MISRA C:2012 Dir 4.12: Dynamic allocation shall not be used
190+
191+
_Ref 4.12_
192+
- Heap memory solutions utilize pvPortMalloc/vPortFree to provide heap
193+
memory for dynamic object allocation. These functions may rely upon
194+
the malloc/free of the underlying port. Static allocation is recommended
195+
for MISRA compliant applications.
196+
197+
Affected Files:
198+
- portable/MemMang/heap_*.c
199+
200+
201+
#### Rule 8.6
202+
203+
MISRA C:2012 Rule 8.6: An identifier with external linkage shall have exactly
204+
one external definition.
205+
206+
_Ref 8.6.1_
207+
- Port layer function declarations are provided without corresponding
208+
implementations to provide for ease of porting to a device. These definitions
209+
cannot be implemented until a port is selected.
210+
211+
#### Rule 21.3
212+
213+
MISRA C-2012 Rule 21.3: The memory allocation and deallocation functions of
214+
<stdlib.h> shall not be used.
215+
216+
_Ref 21.3_
217+
- See justification from Directive 4.12
218+
219+
Affected Files:
220+
- portable/MemMang/heap_*.c
221+
222+
#### Rule 21.6
223+
224+
MISRA C-2012 Rule 21.6: The Standard Library input/output functions shall not
225+
be used.
226+
227+
_Ref 21.6.1_
228+
- The Standard Library function `printf` is used in examples to provide a
229+
simple getting started demonstration. This example is not considered part
230+
of the kernel implementation.
231+
232+
Affected Files:
233+
- examples/cmake_example/main.c

event_groups.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@
511511
traceENTER_xEventGroupClearBitsFromISR( xEventGroup, uxBitsToClear );
512512

513513
traceEVENT_GROUP_CLEAR_BITS_FROM_ISR( xEventGroup, uxBitsToClear );
514-
xReturn = xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToClear, NULL );
514+
xReturn = xTimerPendFunctionCallFromISR( &vEventGroupClearBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToClear, NULL );
515515

516516
traceRETURN_xEventGroupClearBitsFromISR( xReturn );
517517

@@ -823,7 +823,7 @@
823823
traceENTER_xEventGroupSetBitsFromISR( xEventGroup, uxBitsToSet, pxHigherPriorityTaskWoken );
824824

825825
traceEVENT_GROUP_SET_BITS_FROM_ISR( xEventGroup, uxBitsToSet );
826-
xReturn = xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToSet, pxHigherPriorityTaskWoken );
826+
xReturn = xTimerPendFunctionCallFromISR( &vEventGroupSetBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToSet, pxHigherPriorityTaskWoken );
827827

828828
traceRETURN_xEventGroupSetBitsFromISR( xReturn );
829829

examples/cmake_example/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int main( void )
6969

7070
( void ) printf( "Example FreeRTOS Project\n" );
7171

72-
( void ) xTaskCreateStatic( exampleTask,
72+
( void ) xTaskCreateStatic( &exampleTask,
7373
"example",
7474
configMINIMAL_STACK_SIZE,
7575
NULL,

queue.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3343,6 +3343,8 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
33433343
configASSERT( pxQueueSetContainer ); /* LCOV_EXCL_BR_LINE */
33443344
configASSERT( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength );
33453345

3346+
/* pxQueue->pxQueueSetContainer is verified to be non-null by caller. */
3347+
/* coverity[dereference] */
33463348
if( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength )
33473349
{
33483350
const int8_t cTxLock = pxQueueSetContainer->cTxLock;

0 commit comments

Comments
 (0)