lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20250901131955.649000-1-liaoyuanhong@vivo.com>
Date: Mon,  1 Sep 2025 21:19:53 +0800
From: Liao Yuanhong <liaoyuanhong@...o.com>
To: Thomas Gleixner <tglx@...utronix.de>,
	Ingo Molnar <mingo@...hat.com>,
	Borislav Petkov <bp@...en8.de>,
	Dave Hansen <dave.hansen@...ux.intel.com>,
	x86@...nel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)),
	"H. Peter Anvin" <hpa@...or.com>,
	linux-kernel@...r.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT))
Cc: Liao Yuanhong <liaoyuanhong@...o.com>
Subject: [PATCH] x86/ldt: Use guard() instead of mutex_lock() to simplify code

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@...o.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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ