sched/irq: functions should have exactly one exit point

According to MISRA C-2004 Rule 14.7, Every function must have exactly one entry point and one exit point.

Signed-off-by: pangzhen1 <pangzhen1@xiaomi.com>
This commit is contained in:
pangzhen1
2025-08-11 21:00:59 +08:00
committed by Xiang Xiao
parent 165f1cc063
commit a665cd795a
3 changed files with 96 additions and 92 deletions
+12 -11
View File
@@ -113,19 +113,22 @@ int ndx_to_irq(int ndx)
int irq_attach(int irq, xcpt_t isr, FAR void *arg) int irq_attach(int irq, xcpt_t isr, FAR void *arg)
{ {
int ret = OK;
#if NR_IRQS > 0 #if NR_IRQS > 0
int ret = -EINVAL; int ndx = -EINVAL;
irqstate_t flags;
if (irq >= 0 && irq < NR_IRQS) if (irq >= 0 && irq < NR_IRQS)
{ {
int ndx = IRQ_TO_NDX(irq); ndx = IRQ_TO_NDX(irq);
irqstate_t flags; }
if (ndx < 0) if (ndx < 0)
{ {
return ndx; ret = ndx;
} }
else
{
/* If the new ISR is NULL, then the ISR is being detached. /* If the new ISR is NULL, then the ISR is being detached.
* In this case, disable the ISR and direct any interrupts * In this case, disable the ISR and direct any interrupts
* to the unexpected interrupt handler. * to the unexpected interrupt handler.
@@ -166,10 +169,10 @@ int irq_attach(int irq, xcpt_t isr, FAR void *arg)
{ {
ret = irqchain_attach(ndx, isr, arg); ret = irqchain_attach(ndx, isr, arg);
spin_unlock_irqrestore(&g_irqlock, flags); spin_unlock_irqrestore(&g_irqlock, flags);
return ret;
} }
else
#endif #endif
{
/* Save the new ISR and its argument in the table. */ /* Save the new ISR and its argument in the table. */
g_irqvector[ndx].handler = isr; g_irqvector[ndx].handler = isr;
@@ -181,11 +184,9 @@ int irq_attach(int irq, xcpt_t isr, FAR void *arg)
#endif #endif
spin_unlock_irqrestore(&g_irqlock, flags); spin_unlock_irqrestore(&g_irqlock, flags);
ret = OK;
} }
}
#endif /* NR_IRQS */
return ret; return ret;
#else
return OK;
#endif
} }
+14 -17
View File
@@ -145,6 +145,7 @@ static int isr_thread_main(int argc, FAR char *argv[])
int irq_attach_thread(int irq, xcpt_t isr, xcpt_t isrthread, FAR void *arg, int irq_attach_thread(int irq, xcpt_t isr, xcpt_t isrthread, FAR void *arg,
int priority, int stack_size) int priority, int stack_size)
{ {
int ret = OK;
#if NR_IRQS > 0 #if NR_IRQS > 0
static pid_t irq_thread_pid[NR_IRQS]; static pid_t irq_thread_pid[NR_IRQS];
@@ -154,36 +155,32 @@ int irq_attach_thread(int irq, xcpt_t isr, xcpt_t isrthread, FAR void *arg,
char arg3[32]; /* isrthread */ char arg3[32]; /* isrthread */
char arg4[32]; /* arg */ char arg4[32]; /* arg */
pid_t pid; pid_t pid;
int ndx; int ndx = -EINVAL;
if (irq < 0 || irq >= NR_IRQS) if (irq >= 0 && irq < NR_IRQS)
{ {
return -EINVAL; ndx = IRQ_TO_NDX(irq);
} }
ndx = IRQ_TO_NDX(irq);
if (ndx < 0) if (ndx < 0)
{ {
return ndx; ret = ndx;
} }
else if(isrthread == NULL)
{
/* If the isrthread is NULL, then the ISR is being detached. */ /* If the isrthread is NULL, then the ISR is being detached. */
if (isrthread == NULL)
{
irq_detach(irq); irq_detach(irq);
DEBUGASSERT(irq_thread_pid[ndx] != 0); DEBUGASSERT(irq_thread_pid[ndx] != 0);
kthread_delete(irq_thread_pid[ndx]); kthread_delete(irq_thread_pid[ndx]);
irq_thread_pid[ndx] = 0; irq_thread_pid[ndx] = 0;
return OK;
} }
else if(irq_thread_pid[ndx] != 0)
if (irq_thread_pid[ndx] != 0)
{ {
return -EINVAL; ret = -EINVAL;
} }
else
{
snprintf(arg1, sizeof(arg1), "%d", irq); snprintf(arg1, sizeof(arg1), "%d", irq);
snprintf(arg2, sizeof(arg2), "%p", isr); snprintf(arg2, sizeof(arg2), "%p", isr);
snprintf(arg3, sizeof(arg3), "%p", isrthread); snprintf(arg3, sizeof(arg3), "%p", isrthread);
@@ -198,12 +195,12 @@ int irq_attach_thread(int irq, xcpt_t isr, xcpt_t isrthread, FAR void *arg,
isr_thread_main, argv); isr_thread_main, argv);
if (pid < 0) if (pid < 0)
{ {
return pid; ret = pid;
} }
irq_thread_pid[ndx] = pid; irq_thread_pid[ndx] = pid;
}
#endif /* NR_IRQS */ #endif /* NR_IRQS */
return OK; return ret;
} }
+19 -13
View File
@@ -75,7 +75,7 @@ inline_function FAR struct kwork_wqueue_s *irq_get_wqueue(int priority)
static mutex_t irq_wqueue_lock = NXMUTEX_INITIALIZER; static mutex_t irq_wqueue_lock = NXMUTEX_INITIALIZER;
static FAR struct kwork_wqueue_s *irq_wqueue[CONFIG_IRQ_NWORKS]; static FAR struct kwork_wqueue_s *irq_wqueue[CONFIG_IRQ_NWORKS];
FAR struct kwork_wqueue_s *queue; FAR struct kwork_wqueue_s *queue = NULL;
int wqueue_priority; int wqueue_priority;
int i; int i;
@@ -89,17 +89,22 @@ inline_function FAR struct kwork_wqueue_s *irq_get_wqueue(int priority)
if (wqueue_priority == priority) if (wqueue_priority == priority)
{ {
nxmutex_unlock(&irq_wqueue_lock); nxmutex_unlock(&irq_wqueue_lock);
return irq_wqueue[i]; queue = irq_wqueue[i];
break;
} }
} }
DEBUGASSERT(i < CONFIG_IRQ_NWORKS); DEBUGASSERT(i < CONFIG_IRQ_NWORKS);
if (queue == NULL)
{
queue = work_queue_create("isrwork", priority, irq_work_stack[i], queue = work_queue_create("isrwork", priority, irq_work_stack[i],
CONFIG_IRQ_WORK_STACKSIZE, 1); CONFIG_IRQ_WORK_STACKSIZE, 1);
irq_wqueue[i] = queue; irq_wqueue[i] = queue;
nxmutex_unlock(&irq_wqueue_lock); nxmutex_unlock(&irq_wqueue_lock);
}
return queue; return queue;
} }
@@ -170,21 +175,21 @@ int irq_attach_wqueue(int irq, xcpt_t isr, xcpt_t isrwork,
#endif #endif
FAR struct irq_work_info_s *info; FAR struct irq_work_info_s *info;
int ret = OK;
#if NR_IRQS > 0 #if NR_IRQS > 0
int ndx; int ndx = -EINVAL;
if (irq < 0 || irq >= NR_IRQS) if (irq >= 0 && irq < NR_IRQS)
{ {
return -EINVAL; ndx = IRQ_TO_NDX(irq);
} }
ndx = IRQ_TO_NDX(irq);
if (ndx < 0) if (ndx < 0)
{ {
return ndx; ret = ndx;
} }
else
{
/* If the isrwork is NULL, then the ISR is being detached. */ /* If the isrwork is NULL, then the ISR is being detached. */
info = &irq_work_vector[ndx]; info = &irq_work_vector[ndx];
@@ -196,9 +201,9 @@ int irq_attach_wqueue(int irq, xcpt_t isr, xcpt_t isrwork,
info->handler = NULL; info->handler = NULL;
info->arg = NULL; info->arg = NULL;
info->wqueue = NULL; info->wqueue = NULL;
return OK;
} }
else
{
info->isrwork = isrwork; info->isrwork = isrwork;
info->handler = isr; info->handler = isr;
info->arg = arg; info->arg = arg;
@@ -209,8 +214,9 @@ int irq_attach_wqueue(int irq, xcpt_t isr, xcpt_t isrwork,
} }
irq_attach(irq, irq_default_handler, info); irq_attach(irq, irq_default_handler, info);
}
}
#endif /* NR_IRQS */ #endif /* NR_IRQS */
return OK; return ret;
} }