mirror of
https://github.com/torvalds/linux.git
synced 2026-05-28 17:13:52 +02:00
KVM: SEV: use mutex guard in sev_mem_enc_unregister_region()
Simplify the error paths in sev_mem_enc_unregister_region() by using a mutex guard, allowing early return instead of using gotos. Signed-off-by: Carlos López <clopez@suse.de> Link: https://patch.msgid.link/20260120201013.3931334-7-clopez@suse.de Link: https://patch.msgid.link/20260310234829.2608037-19-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
parent
63e56d8425
commit
84841f3941
|
|
@ -2811,35 +2811,25 @@ int sev_mem_enc_unregister_region(struct kvm *kvm,
|
|||
struct kvm_enc_region *range)
|
||||
{
|
||||
struct enc_region *region;
|
||||
int ret;
|
||||
|
||||
/* If kvm is mirroring encryption context it isn't responsible for it */
|
||||
if (is_mirroring_enc_context(kvm))
|
||||
return -EINVAL;
|
||||
|
||||
mutex_lock(&kvm->lock);
|
||||
guard(mutex)(&kvm->lock);
|
||||
|
||||
if (!sev_guest(kvm)) {
|
||||
ret = -ENOTTY;
|
||||
goto failed;
|
||||
}
|
||||
if (!sev_guest(kvm))
|
||||
return -ENOTTY;
|
||||
|
||||
region = find_enc_region(kvm, range);
|
||||
if (!region) {
|
||||
ret = -EINVAL;
|
||||
goto failed;
|
||||
}
|
||||
if (!region)
|
||||
return -EINVAL;
|
||||
|
||||
sev_writeback_caches(kvm);
|
||||
|
||||
__unregister_enc_region_locked(kvm, region);
|
||||
|
||||
mutex_unlock(&kvm->lock);
|
||||
return 0;
|
||||
|
||||
failed:
|
||||
mutex_unlock(&kvm->lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sev_vm_copy_enc_context_from(struct kvm *kvm, unsigned int source_fd)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user