From 36c0dce6d17613490b044cebc652cf20edbd3411 Mon Sep 17 00:00:00 2001 From: yushuailong Date: Mon, 14 Sep 2026 20:19:08 +0800 Subject: [PATCH] sched/irq: Cancel queued work before detaching worked IRQs. Remove pending IRQ work before clearing its callback state, and guard the worker callback against a concurrent detach. This prevents detached worked IRQs from invoking a NULL function pointer. Assisted-by: OpenAI Codex Signed-off-by: yushuailong --- sched/irq/irq_attach_wqueue.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sched/irq/irq_attach_wqueue.c b/sched/irq/irq_attach_wqueue.c index 4ea2ad73551..2585c2a972c 100644 --- a/sched/irq/irq_attach_wqueue.c +++ b/sched/irq/irq_attach_wqueue.c @@ -115,8 +115,12 @@ inline_function FAR struct kwork_wqueue_s *irq_get_wqueue(int priority) static void irq_work_handler(FAR void *arg) { FAR struct irq_work_info_s *info = arg; + xcpt_t isrwork = info->isrwork; - info->isrwork(info->irq, NULL, info->arg); + if (isrwork != NULL) + { + isrwork(info->irq, NULL, info->arg); + } } static int irq_default_handler(int irq, FAR void *context, FAR void *arg) @@ -192,6 +196,11 @@ int irq_attach_wqueue(int irq, xcpt_t isr, xcpt_t isrwork, if (isrwork == NULL) { irq_detach(irq); + if (info->wqueue != NULL) + { + work_cancel_wq(info->wqueue, &info->work); + } + info->isrwork = NULL; info->handler = NULL; info->arg = NULL;