sched/irq: Fix MISRA C-2012 Rule 8.9 - declare objects in block scope

This patch fixes a Coverity issue where static objects that are only referenced
within a single function should be declared in block scope rather than file scope.
This improves code encapsulation and reduces global namespace pollution.

Changes:
- Moved 'g_irqchainpool[]' from file-level static variable to function-level
  static variable within irqchain_initialize()

This ensures compliance with MISRA C-2012 Rule 8.9 which states: 'An object
should be declared in block scope if its identifier is only referenced within
one function.' The change improves code clarity, maintainability, and follows
best practices for variable scoping.

Benefits:
- Reduces file-level namespace pollution
- Improves code encapsulation
- Makes the scope of the variable immediately obvious
- Maintains static storage duration for the array

Signed-off-by: pangzhen1 <pangzhen1@xiaomi.com>
This commit is contained in:
pangzhen1
2025-08-25 22:08:22 +08:00
committed by Xiang Xiao
parent 02eaf3c973
commit 3522ee372d
+7 -7
View File
@@ -46,12 +46,6 @@ struct irqchain_s
* Private Data
****************************************************************************/
/* g_irqchainpool is a list of pre-allocated irq chain. The number of irq
* chains in the pool is a configuration item.
*/
static struct irqchain_s g_irqchainpool[CONFIG_PREALLOC_IRQCHAIN];
/* The g_irqchainfreelist data structure is a single linked list of irqchains
* available to the system for delayed function use.
*/
@@ -109,7 +103,13 @@ static int irqchain_dispatch(int irq, FAR void *context, FAR void *arg)
void irqchain_initialize(void)
{
FAR struct irqchain_s *irqchain = g_irqchainpool;
/* irqchainpool is a list of pre-allocated irq chain. The number of irq
* chains in the pool is a configuration item.
*/
static struct irqchain_s irqchainpool[CONFIG_PREALLOC_IRQCHAIN];
FAR struct irqchain_s *irqchain = irqchainpool;
int i;
/* Initialize irqchain free lists */