linux-kernel.vger.kernel.org archive mirror
 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

* Re: [PATCH] x86/sgx: Use guard() instead of mutex_lock() to simplify code
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Hansen @ 2025-09-01 18:42 UTC (permalink / raw)
  To: Liao Yuanhong, 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)

On 9/1/25 06:22, Liao Yuanhong wrote:
> 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.

I don't plan on applying patches like this. Yes, they marginally
simplify the code, but they do it at the cost of code churn and adding
new bugs. In other words, they're not worth it.



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

* Re: [PATCH] x86/sgx: Use guard() instead of mutex_lock() to simplify code
  2025-09-01 18:42 ` Dave Hansen
@ 2025-09-02  9:11   ` Jarkko Sakkinen
  0 siblings, 0 replies; 3+ messages in thread
From: Jarkko Sakkinen @ 2025-09-02  9:11 UTC (permalink / raw)
  To: Dave Hansen
  Cc: Liao Yuanhong, 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)

On Mon, Sep 01, 2025 at 11:42:15AM -0700, Dave Hansen wrote:
> On 9/1/25 06:22, Liao Yuanhong wrote:
> > 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.
> 
> I don't plan on applying patches like this. Yes, they marginally
> simplify the code, but they do it at the cost of code churn and adding
> new bugs. In other words, they're not worth it.

+1

It has no effect on generated code.

BR, Jarkko

^ permalink raw reply	[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 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).