Skip to content

Commit 0b76e82

Browse files
committed
KVM: TDX: Use guard() to acquire kvm->lock in tdx_vm_ioctl()
Use guard() in tdx_vm_ioctl() to tidy up the code a small amount, but more importantly to minimize the diff of a future change, which will use guard-like semantics to acquire and release multiple locks. No functional change intended. Reviewed-by: Rick Edgecombe <rick.p.edgecombe@intel.com> Reviewed-by: Kai Huang <kai.huang@intel.com> Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com> Reviewed-by: Yan Zhao <yan.y.zhao@intel.com> Tested-by: Yan Zhao <yan.y.zhao@intel.com> Tested-by: Kai Huang <kai.huang@intel.com> Link: https://patch.msgid.link/20251030200951.3402865-25-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 94428e3 commit 0b76e82

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

arch/x86/kvm/vmx/tdx.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2816,7 +2816,7 @@ int tdx_vm_ioctl(struct kvm *kvm, void __user *argp)
28162816
if (r)
28172817
return r;
28182818

2819-
mutex_lock(&kvm->lock);
2819+
guard(mutex)(&kvm->lock);
28202820

28212821
switch (tdx_cmd.id) {
28222822
case KVM_TDX_CAPABILITIES:
@@ -2829,15 +2829,12 @@ int tdx_vm_ioctl(struct kvm *kvm, void __user *argp)
28292829
r = tdx_td_finalize(kvm, &tdx_cmd);
28302830
break;
28312831
default:
2832-
r = -EINVAL;
2833-
goto out;
2832+
return -EINVAL;
28342833
}
28352834

28362835
if (copy_to_user(argp, &tdx_cmd, sizeof(struct kvm_tdx_cmd)))
2837-
r = -EFAULT;
2836+
return -EFAULT;
28382837

2839-
out:
2840-
mutex_unlock(&kvm->lock);
28412838
return r;
28422839
}
28432840

0 commit comments

Comments
 (0)