This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new d7bb8da6954 sched/irq: Fix potential deadlock in irqchain_detach
d7bb8da6954 is described below
commit d7bb8da6954d6034b56f656e472ad5eacb1494d8
Author: pangzhen1 <[email protected]>
AuthorDate: Wed Sep 3 15:11:20 2025 +0800
sched/irq: Fix potential deadlock in irqchain_detach
Release g_irqchainlock before calling irq_detach to avoid holding two locks
simultaneously, which can cause thread deadlock.
The irqchain_detach function was calling irq_detach while holding
g_irqchainlock,
and irq_detach attempts to acquire g_irqlock. This lock ordering violation
could
lead to deadlock in multithreaded scenarios.
Fix:
- Move spin_unlock_irqrestore(&g_irqchainlock, flags) before irq_detach call
- Ensure locks are released in proper order to prevent circular wait
This is part of the irq_chain_lock feature for safer IRQ chain handling.
Signed-off-by: pangzhen1 <[email protected]>
---
sched/irq/irq_chain.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/sched/irq/irq_chain.c b/sched/irq/irq_chain.c
index bd9b43ff5e0..757ca963d8e 100644
--- a/sched/irq/irq_chain.c
+++ b/sched/irq/irq_chain.c
@@ -257,13 +257,14 @@ int irqchain_detach(int irq, xcpt_t isr, FAR void *arg)
break;
}
}
+
+ spin_unlock_irqrestore(&g_irqchainlock, flags);
}
else
{
+ spin_unlock_irqrestore(&g_irqchainlock, flags);
ret = irq_detach(irq);
}
-
- spin_unlock_irqrestore(&g_irqchainlock, flags);
}
return ret;