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 <pangzhen1@xiaomi.com>
This commit is contained in:
pangzhen1
2025-09-03 15:11:20 +08:00
committed by Alan C. Assis
parent 1b22f8c65b
commit d7bb8da695
+3 -2
View File
@@ -257,13 +257,14 @@ int irqchain_detach(int irq, xcpt_t isr, FAR void *arg)
break; break;
} }
} }
spin_unlock_irqrestore(&g_irqchainlock, flags);
} }
else else
{ {
spin_unlock_irqrestore(&g_irqchainlock, flags);
ret = irq_detach(irq); ret = irq_detach(irq);
} }
spin_unlock_irqrestore(&g_irqchainlock, flags);
} }
return ret; return ret;