From 9d471f353d7bd70c26e2a287e3bdcf50c4cb0c8b Mon Sep 17 00:00:00 2001 From: pangzhen1 Date: Mon, 11 Aug 2025 19:48:44 +0800 Subject: [PATCH] sched/irq: declare the object in scope An object should be declared in block scope if its identifier is only referenced within one function(MISRA C-2012 Rule 8.9) Signed-off-by: pangzhen1 --- sched/irq/irq_attach_thread.c | 18 +++++------ sched/irq/irq_attach_wqueue.c | 59 ++++++++++++++++------------------- 2 files changed, 34 insertions(+), 43 deletions(-) diff --git a/sched/irq/irq_attach_thread.c b/sched/irq/irq_attach_thread.c index 02d47b58505..f65c46cad5e 100644 --- a/sched/irq/irq_attach_thread.c +++ b/sched/irq/irq_attach_thread.c @@ -53,12 +53,6 @@ struct irq_thread_info_s FAR sem_t *sem; /* irq sem used to notify irq thread */ }; -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static pid_t g_irq_thread_pid[NR_IRQS]; - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -151,6 +145,8 @@ int irq_attach_thread(int irq, xcpt_t isr, xcpt_t isrthread, FAR void *arg, int priority, int stack_size) { #if NR_IRQS > 0 + static pid_t irq_thread_pid[NR_IRQS]; + FAR char *argv[5]; char arg1[32]; /* irq */ char arg2[32]; /* isr */ @@ -175,14 +171,14 @@ int irq_attach_thread(int irq, xcpt_t isr, xcpt_t isrthread, FAR void *arg, if (isrthread == NULL) { irq_detach(irq); - DEBUGASSERT(g_irq_thread_pid[ndx] != 0); - kthread_delete(g_irq_thread_pid[ndx]); - g_irq_thread_pid[ndx] = 0; + DEBUGASSERT(irq_thread_pid[ndx] != 0); + kthread_delete(irq_thread_pid[ndx]); + irq_thread_pid[ndx] = 0; return OK; } - if (g_irq_thread_pid[ndx] != 0) + if (irq_thread_pid[ndx] != 0) { return -EINVAL; } @@ -204,7 +200,7 @@ int irq_attach_thread(int irq, xcpt_t isr, xcpt_t isrthread, FAR void *arg, return pid; } - g_irq_thread_pid[ndx] = pid; + irq_thread_pid[ndx] = pid; #endif /* NR_IRQS */ diff --git a/sched/irq/irq_attach_wqueue.c b/sched/irq/irq_attach_wqueue.c index 7f7b33ed9b4..cc97b3a5641 100644 --- a/sched/irq/irq_attach_wqueue.c +++ b/sched/irq/irq_attach_wqueue.c @@ -57,29 +57,6 @@ struct irq_work_info_s FAR struct kwork_wqueue_s *wqueue; /* Work queue. */ }; -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#ifdef CONFIG_ARCH_MINIMAL_VECTORTABLE -static struct irq_work_info_s -g_irq_work_vector[CONFIG_ARCH_NUSER_INTERRUPTS]; -#else -static struct irq_work_info_s g_irq_work_vector[NR_IRQS]; -#endif - -static mutex_t g_irq_wqueue_lock = NXMUTEX_INITIALIZER; -static FAR struct kwork_wqueue_s *g_irq_wqueue[CONFIG_IRQ_NWORKS]; - -#ifdef IRQ_WORK_SECTION -static aligned_data(STACK_ALIGNMENT) uint8_t -g_irq_work_stack[CONFIG_IRQ_NWORKS][CONFIG_IRQ_WORK_STACKSIZE] -locate_data(IRQ_WORK_SECTION); -#else -static aligned_data(STACK_ALIGNMENT) uint8_t -g_irq_work_stack[CONFIG_IRQ_NWORKS][CONFIG_IRQ_WORK_STACKSIZE]; -#endif - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -87,31 +64,42 @@ g_irq_work_stack[CONFIG_IRQ_NWORKS][CONFIG_IRQ_WORK_STACKSIZE]; static inline_function FAR struct kwork_wqueue_s *irq_get_wqueue(int priority) { +#ifdef IRQ_WORK_SECTION + static aligned_data(STACK_ALIGNMENT) uint8_t + irq_work_stack[CONFIG_IRQ_NWORKS][CONFIG_IRQ_WORK_STACKSIZE] + locate_data(CONFIG_IRQ_WORK_SECTION); +#else + static aligned_data(STACK_ALIGNMENT) uint8_t + irq_work_stack[CONFIG_IRQ_NWORKS][CONFIG_IRQ_WORK_STACKSIZE]; +#endif + static mutex_t irq_wqueue_lock = NXMUTEX_INITIALIZER; + static FAR struct kwork_wqueue_s *irq_wqueue[CONFIG_IRQ_NWORKS]; + FAR struct kwork_wqueue_s *queue; int wqueue_priority; int i; - nxmutex_lock(&g_irq_wqueue_lock); - for (i = 0; g_irq_wqueue[i] != NULL && i < CONFIG_IRQ_NWORKS; i++) + nxmutex_lock(&irq_wqueue_lock); + for (i = 0; irq_wqueue[i] != NULL && i < CONFIG_IRQ_NWORKS; i++) { - wqueue_priority = work_queue_priority_wq(g_irq_wqueue[i]); + wqueue_priority = work_queue_priority_wq(irq_wqueue[i]); DEBUGASSERT(wqueue_priority >= SCHED_PRIORITY_MIN && wqueue_priority <= SCHED_PRIORITY_MAX); if (wqueue_priority == priority) { - nxmutex_unlock(&g_irq_wqueue_lock); - return g_irq_wqueue[i]; + nxmutex_unlock(&irq_wqueue_lock); + return irq_wqueue[i]; } } DEBUGASSERT(i < CONFIG_IRQ_NWORKS); - queue = work_queue_create("isrwork", priority, g_irq_work_stack[i], + queue = work_queue_create("isrwork", priority, irq_work_stack[i], CONFIG_IRQ_WORK_STACKSIZE, 1); - g_irq_wqueue[i] = queue; - nxmutex_unlock(&g_irq_wqueue_lock); + irq_wqueue[i] = queue; + nxmutex_unlock(&irq_wqueue_lock); return queue; } @@ -174,6 +162,13 @@ static int irq_default_handler(int irq, FAR void *regs, FAR void *arg) int irq_attach_wqueue(int irq, xcpt_t isr, xcpt_t isrwork, FAR void *arg, int priority) { +#ifdef CONFIG_ARCH_MINIMAL_VECTORTABLE + static struct irq_work_info_s + irq_work_vector[CONFIG_ARCH_NUSER_INTERRUPTS]; +#else + static struct irq_work_info_s irq_work_vector[NR_IRQS]; +#endif + FAR struct irq_work_info_s *info; #if NR_IRQS > 0 @@ -192,7 +187,7 @@ int irq_attach_wqueue(int irq, xcpt_t isr, xcpt_t isrwork, /* If the isrwork is NULL, then the ISR is being detached. */ - info = &g_irq_work_vector[ndx]; + info = &irq_work_vector[ndx]; if (isrwork == NULL) {