This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 3522ee372d03c37b0f9c62f270b8174aee43af4d
Author: pangzhen1 <[email protected]>
AuthorDate: Mon Aug 25 22:08:22 2025 +0800

    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 <[email protected]>
---
 sched/irq/irq_chain.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/sched/irq/irq_chain.c b/sched/irq/irq_chain.c
index fd9bd4ba8ad..bd9b43ff5e0 100644
--- a/sched/irq/irq_chain.c
+++ b/sched/irq/irq_chain.c
@@ -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 */

Reply via email to