Skip to content

Commit

Permalink
Fix MISRA_C_2012 rule 8.4 violation (#844)
Browse files Browse the repository at this point in the history
Fix MISRA_C_2012 rule 8.4 violation
  • Loading branch information
kar-rahul-aws authored Dec 7, 2023
1 parent 22eb827 commit d1a0202
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
17 changes: 9 additions & 8 deletions MISRA.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ MISRA C:2012 Rule 8.4: A compatible declaration shall be visible when an
object or function with external linkage is defined.

_Ref 8.4.1_

- 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.

- 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.

_Ref 8.4.2_
- xQueueRegistry is defined with external linkage because it is accessed by the
kernel unit tests. It is not meant to be directly accessed by the application
and therefore, not declared in a header file.

#### Rule 11.3

Expand Down
4 changes: 4 additions & 0 deletions queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ typedef xQUEUE Queue_t;
/* The queue registry is simply an array of QueueRegistryItem_t structures.
* The pcQueueName member of a structure being NULL is indicative of the
* array position being vacant. */

/* MISRA Ref 8.4.2 [Declaration shall be visible] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-84 */
/* coverity[misra_c_2012_rule_8_4_violation] */
PRIVILEGED_DATA QueueRegistryItem_t xQueueRegistry[ configQUEUE_REGISTRY_SIZE ];

#endif /* configQUEUE_REGISTRY_SIZE */
Expand Down
5 changes: 4 additions & 1 deletion tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,9 @@ typedef tskTCB TCB_t;
/*lint -save -e956 A manual analysis and inspection has been used to determine
* which static variables must be declared volatile. */
#if ( configNUMBER_OF_CORES == 1 )
/* MISRA Ref 8.4.1 [Declaration shall be visible] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-84 */
/* coverity[misra_c_2012_rule_8_4_violation] */
portDONT_DISCARD PRIVILEGED_DATA TCB_t * volatile pxCurrentTCB = NULL;
#else
/* MISRA Ref 8.4.1 [Declaration shall be visible] */
Expand Down Expand Up @@ -490,7 +493,7 @@ PRIVILEGED_DATA static TaskHandle_t xIdleTaskHandles[ configNUMBER_OF_CORES ];
/* Improve support for OpenOCD. The kernel tracks Ready tasks via priority lists.
* For tracking the state of remote threads, OpenOCD uses uxTopUsedPriority
* to determine the number of priority lists to read back from the remote target. */
const volatile UBaseType_t uxTopUsedPriority = configMAX_PRIORITIES - 1U;
static const volatile UBaseType_t uxTopUsedPriority = configMAX_PRIORITIES - 1U;

/* Context switches are held pending while the scheduler is suspended. Also,
* interrupts must not manipulate the xStateListItem of a TCB, or any of the
Expand Down

0 comments on commit d1a0202

Please sign in to comment.