From: Richard Lyu <richard.lyu@suse.com>
To: Thomas Gleixner <tglx@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Richard Lyu <richard.lyu@suse.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH] x86/apic/msi: Use guard(mutex) in dmar_get_irq_domain()
Date: Wed, 11 Mar 2026 22:59:45 +0800 [thread overview]
Message-ID: <20260311145944.85399-1-richard.lyu@suse.com> (raw)
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@suse.com>
---
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@linux.intel.com>
* 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
next reply other threads:[~2026-03-11 14:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-11 14:59 Richard Lyu [this message]
2026-03-11 15:03 ` [PATCH] x86/apic/msi: Use guard(mutex) in dmar_get_irq_domain() Dave Hansen
2026-03-11 15:15 ` Richard Lyu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260311145944.85399-1-richard.lyu@suse.com \
--to=richard.lyu@suse.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox