Skip to content

Commit 4319fa1

Browse files
LiaoYuanhong-vivosean-jc
authored andcommitted
KVM: x86: Use guard() instead of mutex_lock() to simplify code
Use guard(mutex) instead of mutex_lock/mutex_unlock pair to simplify the error handling when allocating the APIC access page. No functional change intended. Signed-off-by: Liao Yuanhong <[email protected]> Link: https://lore.kernel.org/r/[email protected] [sean: add blank link to isolate guard(), tweak changelog] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 06dc910 commit 4319fa1

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

arch/x86/kvm/lapic.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2747,24 +2747,21 @@ void kvm_apic_update_apicv(struct kvm_vcpu *vcpu)
27472747
int kvm_alloc_apic_access_page(struct kvm *kvm)
27482748
{
27492749
void __user *hva;
2750-
int ret = 0;
27512750

2752-
mutex_lock(&kvm->slots_lock);
2751+
guard(mutex)(&kvm->slots_lock);
2752+
27532753
if (kvm->arch.apic_access_memslot_enabled ||
27542754
kvm->arch.apic_access_memslot_inhibited)
2755-
goto out;
2755+
return 0;
27562756

27572757
hva = __x86_set_memory_region(kvm, APIC_ACCESS_PAGE_PRIVATE_MEMSLOT,
27582758
APIC_DEFAULT_PHYS_BASE, PAGE_SIZE);
2759-
if (IS_ERR(hva)) {
2760-
ret = PTR_ERR(hva);
2761-
goto out;
2762-
}
2759+
if (IS_ERR(hva))
2760+
return PTR_ERR(hva);
27632761

27642762
kvm->arch.apic_access_memslot_enabled = true;
2765-
out:
2766-
mutex_unlock(&kvm->slots_lock);
2767-
return ret;
2763+
2764+
return 0;
27682765
}
27692766
EXPORT_SYMBOL_GPL(kvm_alloc_apic_access_page);
27702767

0 commit comments

Comments
 (0)