]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: SEV: use mutex guard in sev_mem_enc_unregister_region()
authorCarlos López <clopez@suse.de>
Tue, 10 Mar 2026 23:48:26 +0000 (16:48 -0700)
committerSean Christopherson <seanjc@google.com>
Thu, 9 Apr 2026 19:00:22 +0000 (12:00 -0700)
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>
arch/x86/kvm/svm/sev.c

index b7bc69f8b0f9752e10f36cd41161f100a8076791..1cb9aa9f748cf86daa496533b80174c909b9b2ac 100644 (file)
@@ -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)