All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/sgx: Use guard() instead of mutex_lock() to simplify code
@ 2025-09-01 13:22 Liao Yuanhong
  2025-09-01 18:42 ` Dave Hansen
  0 siblings, 1 reply; 3+ messages in thread
From: Liao Yuanhong @ 2025-09-01 13:22 UTC (permalink / raw)
  To: Jarkko Sakkinen, Dave Hansen, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	H. Peter Anvin, open list:INTEL SGX,
	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 'err_out'
label anymore so remove it.

Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
---
 arch/x86/kernel/cpu/sgx/ioctl.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/cpu/sgx/ioctl.c b/arch/x86/kernel/cpu/sgx/ioctl.c
index 66f1efa16fbb..b61faa1aed7f 100644
--- a/arch/x86/kernel/cpu/sgx/ioctl.c
+++ b/arch/x86/kernel/cpu/sgx/ioctl.c
@@ -501,7 +501,7 @@ static int sgx_encl_init(struct sgx_encl *encl, struct sgx_sigstruct *sigstruct,
 
 	sha256(sigstruct->modulus, SGX_MODULUS_SIZE, (u8 *)mrsigner);
 
-	mutex_lock(&encl->lock);
+	guard(mutex)(&encl->lock);
 
 	/*
 	 * ENCLS[EINIT] is interruptible because it has such a high latency,
@@ -534,7 +534,7 @@ static int sgx_encl_init(struct sgx_encl *encl, struct sgx_sigstruct *sigstruct,
 
 		if (signal_pending(current)) {
 			ret = -ERESTARTSYS;
-			goto err_out;
+			return ret;
 		}
 	}
 
@@ -550,8 +550,6 @@ static int sgx_encl_init(struct sgx_encl *encl, struct sgx_sigstruct *sigstruct,
 		set_bit(SGX_ENCL_INITIALIZED, &encl->flags);
 	}
 
-err_out:
-	mutex_unlock(&encl->lock);
 	return ret;
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-09-02  9:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-01 13:22 [PATCH] x86/sgx: Use guard() instead of mutex_lock() to simplify code Liao Yuanhong
2025-09-01 18:42 ` Dave Hansen
2025-09-02  9:11   ` Jarkko Sakkinen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.