sched_profil: Move static variable to block scope for MISRA C 2012 compliance #18215
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Move the static
g_profvariable declaration to block scope within theprofil()function when CONFIG_SMP is disabled, to comply with MISRA C 2012 Rule 8.9 which
requires objects used by only one function to be declared within that function's scope.
Motivation and Problem
MISRA C 2012 Rule 8.9 enforces improved code locality by requiring that objects
with internal linkage be declared at the smallest possible scope. The original
code declared
g_profat file scope globally, even though it is only used withinthe
profil()function when CONFIG_SMP is not enabled. When CONFIG_SMP is enabled,g_profis used in SMP call data initialization, requiring file-scope visibility.This change optimizes the scope based on build configuration, improving code clarity
and compliance with embedded systems coding standards.
Changes
static struct profinfo_s g_profdeclarationstatic struct profinfo_s g_profdeclaration inside profil() functionwhen CONFIG_SMP is disabled, restricting scope to only where it's used
Impact
Verification
Testing
Tested with:
Files Changed
sched/sched/sched_profil.c(6 lines: 4 insertions, 2 deletions)