public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/apic: KVM: Use guard() instead of mutex_lock() to simplify code
@ 2025-09-01 13:18 Liao Yuanhong
  2025-09-16  0:25 ` Sean Christopherson
  0 siblings, 1 reply; 3+ messages in thread
From: Liao Yuanhong @ 2025-09-01 13:18 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen,
	maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), H. Peter Anvin,
	open list:KERNEL VIRTUAL MACHINE FOR X86 (KVM/x86),
	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' label
and variable 'ret' anymore so remove it.

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

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index ed636c1f5e58..fa52622bcf5f 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -2683,24 +2683,20 @@ void kvm_apic_update_apicv(struct kvm_vcpu *vcpu)
 int kvm_alloc_apic_access_page(struct kvm *kvm)
 {
 	void __user *hva;
-	int ret = 0;
 
-	mutex_lock(&kvm->slots_lock);
+	guard(mutex)(&kvm->slots_lock);
 	if (kvm->arch.apic_access_memslot_enabled ||
 	    kvm->arch.apic_access_memslot_inhibited)
-		goto out;
+		return 0;
 
 	hva = __x86_set_memory_region(kvm, APIC_ACCESS_PAGE_PRIVATE_MEMSLOT,
 				      APIC_DEFAULT_PHYS_BASE, PAGE_SIZE);
-	if (IS_ERR(hva)) {
-		ret = PTR_ERR(hva);
-		goto out;
-	}
+	if (IS_ERR(hva))
+		return PTR_ERR(hva);
 
 	kvm->arch.apic_access_memslot_enabled = true;
-out:
-	mutex_unlock(&kvm->slots_lock);
-	return ret;
+
+	return 0;
 }
 EXPORT_SYMBOL_GPL(kvm_alloc_apic_access_page);
 
-- 
2.34.1


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

* Re: [PATCH] x86/apic: KVM: Use guard() instead of mutex_lock() to simplify code
  2025-09-01 13:18 [PATCH] x86/apic: KVM: Use guard() instead of mutex_lock() to simplify code Liao Yuanhong
@ 2025-09-16  0:25 ` Sean Christopherson
  2025-09-16 20:00   ` Sean Christopherson
  0 siblings, 1 reply; 3+ messages in thread
From: Sean Christopherson @ 2025-09-16  0:25 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, kvm,
	linux-kernel, Liao Yuanhong

On Mon, 01 Sep 2025 21:18:21 +0800, 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 'out' label
> and variable 'ret' anymore so remove it.

Applied to kvm-x86 misc, thanks!

[1/1] x86/apic: KVM: Use guard() instead of mutex_lock() to simplify code
      https://github.com/kvm-x86/linux/commit/50f4db196766

--
https://github.com/kvm-x86/linux/tree/next

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

* Re: [PATCH] x86/apic: KVM: Use guard() instead of mutex_lock() to simplify code
  2025-09-16  0:25 ` Sean Christopherson
@ 2025-09-16 20:00   ` Sean Christopherson
  0 siblings, 0 replies; 3+ messages in thread
From: Sean Christopherson @ 2025-09-16 20:00 UTC (permalink / raw)
  To: Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, kvm, linux-kernel,
	Liao Yuanhong

On Mon, Sep 15, 2025, Sean Christopherson wrote:
> On Mon, 01 Sep 2025 21:18:21 +0800, 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 'out' label
> > and variable 'ret' anymore so remove it.
> 
> Applied to kvm-x86 misc, thanks!
> 
> [1/1] x86/apic: KVM: Use guard() instead of mutex_lock() to simplify code
>       https://github.com/kvm-x86/linux/commit/50f4db196766

I force pushed to fixup an unrelated commit, new hash:

      https://github.com/kvm-x86/linux/commit/4319fa120f0f

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

end of thread, other threads:[~2025-09-16 20:00 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:18 [PATCH] x86/apic: KVM: Use guard() instead of mutex_lock() to simplify code Liao Yuanhong
2025-09-16  0:25 ` Sean Christopherson
2025-09-16 20:00   ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox