From 4621d75e2d6fcb0b55d6a94cf1bfebc20703174b Mon Sep 17 00:00:00 2001 From: yushuailong Date: Mon, 14 Sep 2026 20:18:04 +0800 Subject: [PATCH] sched/irq: Reject worked IRQs without a work queue. Return ENOMEM and leave the IRQ detached when no custom work queue can be created or all queue slots are occupied. Also release the queue mutex on the full-table path and avoid caching a failed queue creation. Assisted-by: OpenAI Codex Signed-off-by: yushuailong --- sched/irq/irq_attach_wqueue.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/sched/irq/irq_attach_wqueue.c b/sched/irq/irq_attach_wqueue.c index c89c11198c4..4ea2ad73551 100644 --- a/sched/irq/irq_attach_wqueue.c +++ b/sched/irq/irq_attach_wqueue.c @@ -88,7 +88,6 @@ inline_function FAR struct kwork_wqueue_s *irq_get_wqueue(int priority) if (wqueue_priority == priority) { - nxmutex_unlock(&irq_wqueue_lock); queue = irq_wqueue[i]; break; } @@ -99,10 +98,13 @@ inline_function FAR struct kwork_wqueue_s *irq_get_wqueue(int priority) queue = work_queue_create("isrwork", priority, irq_work_stack[i], CONFIG_IRQ_WORK_STACKSIZE, 1); - irq_wqueue[i] = queue; - nxmutex_unlock(&irq_wqueue_lock); + if (queue != NULL) + { + irq_wqueue[i] = queue; + } } + nxmutex_unlock(&irq_wqueue_lock); return queue; } @@ -176,6 +178,7 @@ int irq_attach_wqueue(int irq, xcpt_t isr, xcpt_t isrwork, int ret = OK; #if NR_IRQS > 0 int ndx = IRQ_TO_NDX(irq); + if (ndx < 0) { ret = ndx; @@ -196,16 +199,23 @@ int irq_attach_wqueue(int irq, xcpt_t isr, xcpt_t isrwork, } else { - info->isrwork = isrwork; - info->handler = isr; - info->arg = arg; - info->irq = irq; if (info->wqueue == NULL) { info->wqueue = irq_get_wqueue(priority); } - irq_attach(irq, irq_default_handler, info); + if (info->wqueue == NULL) + { + ret = -ENOMEM; + } + else + { + info->isrwork = isrwork; + info->handler = isr; + info->arg = arg; + info->irq = irq; + ret = irq_attach(irq, irq_default_handler, info); + } } } #endif /* NR_IRQS */