linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/ldt: Use guard() instead of mutex_lock() to simplify code
@ 2025-09-01 13:19 Liao Yuanhong
  0 siblings, 0 replies; only message in thread
From: Liao Yuanhong @ 2025-09-01 13:19 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), H. Peter Anvin,
	open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)
  Cc: Liao Yuanhong

Using guard(mutex) instead of mutex_lock/mutex_unlock pair. Simplifies the
error handling to just return in case of error. No need for the
'out_unlock' label anymore so remove it. Similarly, the variable 'ret' does
not need to be initialized to 0.

Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
---
 arch/x86/kernel/ldt.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
index 0f19ef355f5f..4dd29d521928 100644
--- a/arch/x86/kernel/ldt.c
+++ b/arch/x86/kernel/ldt.c
@@ -451,20 +451,18 @@ static void free_ldt_struct(struct ldt_struct *ldt)
 int ldt_dup_context(struct mm_struct *old_mm, struct mm_struct *mm)
 {
 	struct ldt_struct *new_ldt;
-	int retval = 0;
+	int retval;
 
 	if (!old_mm)
 		return 0;
 
-	mutex_lock(&old_mm->context.lock);
+	guard(mutex)(&old_mm->context.lock);
 	if (!old_mm->context.ldt)
-		goto out_unlock;
+		return 0;
 
 	new_ldt = alloc_ldt_struct(old_mm->context.ldt->nr_entries);
-	if (!new_ldt) {
-		retval = -ENOMEM;
-		goto out_unlock;
-	}
+	if (!new_ldt)
+		return -ENOMEM;
 
 	memcpy(new_ldt->entries, old_mm->context.ldt->entries,
 	       new_ldt->nr_entries * LDT_ENTRY_SIZE);
@@ -474,12 +472,10 @@ int ldt_dup_context(struct mm_struct *old_mm, struct mm_struct *mm)
 	if (retval) {
 		free_ldt_pgtables(mm);
 		free_ldt_struct(new_ldt);
-		goto out_unlock;
+		return retval;
 	}
 	mm->context.ldt = new_ldt;
 
-out_unlock:
-	mutex_unlock(&old_mm->context.lock);
 	return retval;
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2025-09-01 13:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-01 13:19 [PATCH] x86/ldt: Use guard() instead of mutex_lock() to simplify code Liao Yuanhong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).