Skip to content

Commit d078cd6

Browse files
author
Ubuntu
committed
Use comment suppression instead of config suppression
1 parent 9c7d1b7 commit d078cd6

File tree

6 files changed

+53
-11
lines changed

6 files changed

+53
-11
lines changed

MISRA.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ _Ref 8.4.1_
3131
a declaration in header file is not useful as the assembly code will
3232
still need to declare it separately.
3333

34+
35+
#### Rule 11.3
36+
37+
_Ref 11.3.1_
38+
39+
- MISRA C:2012 Rule 11.3: A cast shall not be performed between a pointer to object
40+
type and a pointer to a different object type.
41+
The rule requires not to cast a pointer to object into a pointer to a different object to prevent undefined behavior due to incorrectly aligned. To support static memory allocation, FreeRTOS creates static type kernel objects which are aliases for kernel object type with prefix "Static" for data hiding purpose. A static kernel object type is guaranteed to have the same size and alignment with kernel object, which is checked by configASSERT. Static kernel object types include StaticEventGroup_t, StaticQueue_t, StaticStreamBuffer_t, StaticTimer_t and StaticTask_t.
42+
43+
3444
### MISRA configuration
3545

3646
Copy below content to `misra.conf` to run Coverity on FreeRTOS-Kernel.
@@ -63,14 +73,10 @@ Copy below content to `misra.conf` to run Coverity on FreeRTOS-Kernel.
6373
deviation: "Rule 8.7",
6474
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."
6575
},
66-
{
67-
deviation: "Rule 11.3",
68-
reason: "Allow kernel object static allocation for StaticEventGroup_t, StaticQueue_t, StaticStreamBuffer_t, StaticTimer_t and StaticTask_t."
69-
},
7076
{
7177
deviation: "Rule 11.5",
7278
reason: "Allow casts from `void *`. List owner, pvOwner, is stored as `void *` and are cast to various types for use in functions."
7379
}
7480
]
7581
}
76-
```
82+
```

event_groups.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
9898
#endif /* configASSERT_DEFINED */
9999

100100
/* The user has provided a statically allocated event group - use it. */
101-
pxEventBits = ( EventGroup_t * ) pxEventGroupBuffer; /*lint !e740 !e9087 EventGroup_t and StaticEventGroup_t are deliberately aliased for data hiding purposes and guaranteed to have the same size and alignment requirement - checked by configASSERT(). */
101+
/* MISRA Ref 11.3.1 [Misaligned access] */
102+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
103+
/* coverity[misra_c_2012_rule_11_3_violation] */
104+
pxEventBits = ( EventGroup_t * ) pxEventGroupBuffer;
102105

103106
if( pxEventBits != NULL )
104107
{
@@ -710,6 +713,9 @@ void vEventGroupDelete( EventGroupHandle_t xEventGroup )
710713
/* Check if the event group was statically allocated. */
711714
if( pxEventBits->ucStaticallyAllocated == ( uint8_t ) pdTRUE )
712715
{
716+
/* MISRA Ref 11.3.1 [Misaligned access] */
717+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
718+
/* coverity[misra_c_2012_rule_11_3_violation] */
713719
*ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits;
714720
xReturn = pdTRUE;
715721
}
@@ -721,6 +727,9 @@ void vEventGroupDelete( EventGroupHandle_t xEventGroup )
721727
#else /* configSUPPORT_DYNAMIC_ALLOCATION */
722728
{
723729
/* Event group must have been statically allocated. */
730+
/* MISRA Ref 11.3.1 [Misaligned access] */
731+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
732+
/* coverity[misra_c_2012_rule_11_3_violation] */
724733
*ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits;
725734
xReturn = pdTRUE;
726735
}

queue.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,10 @@ BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
408408
/* The address of a statically allocated queue was passed in, use it.
409409
* The address of a statically allocated storage area was also passed in
410410
* but is already set. */
411-
pxNewQueue = ( Queue_t * ) pxStaticQueue; /*lint !e740 !e9087 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */
411+
/* MISRA Ref 11.3.1 [Misaligned access] */
412+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
413+
/* coverity[misra_c_2012_rule_11_3_violation] */
414+
pxNewQueue = ( Queue_t * ) pxStaticQueue;
412415

413416
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
414417
{
@@ -459,6 +462,9 @@ BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
459462
*ppucQueueStorage = ( uint8_t * ) pxQueue->pcHead;
460463
}
461464

465+
/* MISRA Ref 11.3.1 [Misaligned access] */
466+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
467+
/* coverity[misra_c_2012_rule_11_3_violation] */
462468
*ppxStaticQueue = ( StaticQueue_t * ) pxQueue;
463469
xReturn = pdTRUE;
464470
}

stream_buffer.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,10 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
406406
StreamBufferCallbackFunction_t pxSendCompletedCallback,
407407
StreamBufferCallbackFunction_t pxReceiveCompletedCallback )
408408
{
409-
StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) pxStaticStreamBuffer; /*lint !e740 !e9087 Safe cast as StaticStreamBuffer_t is opaque Streambuffer_t. */
409+
/* MISRA Ref 11.3.1 [Misaligned access] */
410+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
411+
/* coverity[misra_c_2012_rule_11_3_violation] */
412+
StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) pxStaticStreamBuffer;
410413
StreamBufferHandle_t xReturn;
411414
uint8_t ucFlags;
412415

@@ -466,7 +469,10 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
466469

467470
traceSTREAM_BUFFER_CREATE( pxStreamBuffer, xIsMessageBuffer );
468471

469-
xReturn = ( StreamBufferHandle_t ) pxStaticStreamBuffer; /*lint !e9087 Data hiding requires cast to opaque type. */
472+
/* MISRA Ref 11.3.1 [Misaligned access] */
473+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
474+
/* coverity[misra_c_2012_rule_11_3_violation] */
475+
xReturn = ( StreamBufferHandle_t ) pxStaticStreamBuffer;
470476
}
471477
else
472478
{
@@ -498,6 +504,9 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
498504
if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_STATICALLY_ALLOCATED ) != ( uint8_t ) 0 )
499505
{
500506
*ppucStreamBufferStorageArea = pxStreamBuffer->pucBuffer;
507+
/* MISRA Ref 11.3.1 [Misaligned access] */
508+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
509+
/* coverity[misra_c_2012_rule_11_3_violation] */
501510
*ppxStaticStreamBuffer = ( StaticStreamBuffer_t * ) pxStreamBuffer;
502511
xReturn = pdTRUE;
503512
}

tasks.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,10 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
12711271
{
12721272
/* The memory used for the task's TCB and stack are passed into this
12731273
* function - use them. */
1274-
pxNewTCB = ( TCB_t * ) pxTaskBuffer; /*lint !e740 !e9087 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */
1274+
/* MISRA Ref 11.3.1 [Misaligned access] */
1275+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
1276+
/* coverity[misra_c_2012_rule_11_3_violation] */
1277+
pxNewTCB = ( TCB_t * ) pxTaskBuffer;
12751278
( void ) memset( ( void * ) pxNewTCB, 0x00, sizeof( TCB_t ) );
12761279
pxNewTCB->pxStack = ( StackType_t * ) puxStackBuffer;
12771280

@@ -4319,6 +4322,9 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char
43194322
if( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_AND_TCB )
43204323
{
43214324
*ppuxStackBuffer = pxTCB->pxStack;
4325+
/* MISRA Ref 11.3.1 [Misaligned access] */
4326+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
4327+
/* coverity[misra_c_2012_rule_11_3_violation] */
43224328
*ppxTaskBuffer = ( StaticTask_t * ) pxTCB;
43234329
xReturn = pdTRUE;
43244330
}

timers.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,10 @@
394394

395395
/* A pointer to a StaticTimer_t structure MUST be provided, use it. */
396396
configASSERT( pxTimerBuffer );
397-
pxNewTimer = ( Timer_t * ) pxTimerBuffer; /*lint !e740 !e9087 StaticTimer_t is a pointer to a Timer_t, so guaranteed to be aligned and sized correctly (checked by an assert()), so this is safe. */
397+
/* MISRA Ref 11.3.1 [Misaligned access] */
398+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
399+
/* coverity[misra_c_2012_rule_11_3_violation] */
400+
pxNewTimer = ( Timer_t * ) pxTimerBuffer;
398401

399402
if( pxNewTimer != NULL )
400403
{
@@ -664,6 +667,9 @@
664667

665668
if( ( pxTimer->ucStatus & tmrSTATUS_IS_STATICALLY_ALLOCATED ) != 0 )
666669
{
670+
/* MISRA Ref 11.3.1 [Misaligned access] */
671+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
672+
/* coverity[misra_c_2012_rule_11_3_violation] */
667673
*ppxTimerBuffer = ( StaticTimer_t * ) pxTimer;
668674
xReturn = pdTRUE;
669675
}

0 commit comments

Comments
 (0)