[PATCH] x86/apic/msi: Use guard(mutex) in dmar_get_irq_domain()
From: Richard Lyu
Date: Wed Mar 11 2026 - 11:06:19 EST
The dmar_get_irq_domain() function uses a mutex to protect the
initialization of the dmar_domain. Using guard(mutex) simplifies the
control flow, removes the need for a 'out' label, and ensures the
lock is automatically released regardless of the return path.
Signed-off-by: Richard Lyu <richard.lyu@xxxxxxxx>
---
arch/x86/kernel/apic/msi.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kernel/apic/msi.c b/arch/x86/kernel/apic/msi.c
index 66bc5d3e79db..3f10b35f7c79 100644
--- a/arch/x86/kernel/apic/msi.c
+++ b/arch/x86/kernel/apic/msi.c
@@ -7,7 +7,9 @@
* Jiang Liu <jiang.liu@xxxxxxxxxxxxxxx>
* Convert to hierarchical irqdomain
*/
+#include <linux/cleanup.h>
#include <linux/mm.h>
+#include <linux/mutex.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/pci.h>
@@ -346,9 +348,9 @@ static struct irq_domain *dmar_get_irq_domain(void)
static DEFINE_MUTEX(dmar_lock);
struct fwnode_handle *fn;
- mutex_lock(&dmar_lock);
+ guard(mutex)(&dmar_lock);
if (dmar_domain)
- goto out;
+ return dmar_domain;
fn = irq_domain_alloc_named_fwnode("DMAR-MSI");
if (fn) {
@@ -357,8 +359,6 @@ static struct irq_domain *dmar_get_irq_domain(void)
if (!dmar_domain)
irq_domain_free_fwnode(fn);
}
-out:
- mutex_unlock(&dmar_lock);
return dmar_domain;
}
--
2.51.0