Skip to content

Commit 955997e

Browse files
Nikolay Borisovsean-jc
authored andcommitted
KVM: x86: Use mutex guards to eliminate __kvm_x86_vendor_init()
Use the recently introduced guard(mutex) infrastructure acquire and automatically release vendor_module_lock when the guard goes out of scope. Drop the inner __kvm_x86_vendor_init(), its sole purpose was to simplify releasing vendor_module_lock in error paths. No functional change intended. Signed-off-by: Nikolay Borisov <[email protected]> Reviewed-by: Kai Huang <[email protected]> Link: https://lore.kernel.org/r/[email protected] [sean: rewrite changelog] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 41bccc9 commit 955997e

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

arch/x86/kvm/x86.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9632,11 +9632,13 @@ static void kvm_x86_check_cpu_compat(void *ret)
96329632
*(int *)ret = kvm_x86_check_processor_compatibility();
96339633
}
96349634

9635-
static int __kvm_x86_vendor_init(struct kvm_x86_init_ops *ops)
9635+
int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops)
96369636
{
96379637
u64 host_pat;
96389638
int r, cpu;
96399639

9640+
guard(mutex)(&vendor_module_lock);
9641+
96409642
if (kvm_x86_ops.hardware_enable) {
96419643
pr_err("already loaded vendor module '%s'\n", kvm_x86_ops.name);
96429644
return -EEXIST;
@@ -9766,17 +9768,6 @@ static int __kvm_x86_vendor_init(struct kvm_x86_init_ops *ops)
97669768
kmem_cache_destroy(x86_emulator_cache);
97679769
return r;
97689770
}
9769-
9770-
int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops)
9771-
{
9772-
int r;
9773-
9774-
mutex_lock(&vendor_module_lock);
9775-
r = __kvm_x86_vendor_init(ops);
9776-
mutex_unlock(&vendor_module_lock);
9777-
9778-
return r;
9779-
}
97809771
EXPORT_SYMBOL_GPL(kvm_x86_vendor_init);
97819772

97829773
void kvm_x86_vendor_exit(void)

0 commit comments

Comments
 (0)