]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: s390: Return failure in case of failure in kvm_s390_set_cmma_bits()
authorClaudio Imbrenda <imbrenda@linux.ibm.com>
Tue, 23 Jun 2026 15:33:30 +0000 (17:33 +0200)
committerClaudio Imbrenda <imbrenda@linux.ibm.com>
Wed, 24 Jun 2026 08:08:57 +0000 (10:08 +0200)
If the allocation of the bits array failed, kvm_s390_set_cmma_bits()
would return 0 instead of an error code.

Rework the function to use the __free() macros and thus simplify the
code flow; when the above mentioned allocation fails, simply return
-ENOMEM.

Fixes: e38c884df921 ("KVM: s390: Switch to new gmap")
Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Message-ID: <20260623153331.233784-10-imbrenda@linux.ibm.com>

arch/s390/kvm/kvm-s390.c

index 9ad6bd4edbce335062f5921cd17e846262b4dcf1..3b26c909ad0fca4712288f9f38f1c776bb537438 100644 (file)
@@ -2313,8 +2313,8 @@ static int kvm_s390_get_cmma_bits(struct kvm *kvm,
 static int kvm_s390_set_cmma_bits(struct kvm *kvm,
                                  const struct kvm_s390_cmma_log *args)
 {
-       struct kvm_s390_mmu_cache *mc;
-       u8 *bits = NULL;
+       struct kvm_s390_mmu_cache *mc __free(kvm_s390_mmu_cache) = NULL;
+       u8 *bits __free(kvfree) = NULL;
        int r = 0;
 
        if (!kvm->arch.use_cmma)
@@ -2334,18 +2334,16 @@ static int kvm_s390_set_cmma_bits(struct kvm *kvm,
                return -ENOMEM;
        bits = vmalloc(array_size(sizeof(*bits), args->count));
        if (!bits)
-               goto out;
+               return -ENOMEM;
 
        r = copy_from_user(bits, (void __user *)args->values, args->count);
-       if (r) {
-               r = -EFAULT;
-               goto out;
-       }
+       if (r)
+               return -EFAULT;
 
        do {
                r = kvm_s390_mmu_cache_topup(mc);
                if (r)
-                       break;
+                       return r;
                scoped_guard(read_lock, &kvm->mmu_lock) {
                        r = dat_set_cmma_bits(mc, kvm->arch.gmap->asce, args->start_gfn,
                                              args->count, args->mask, bits);
@@ -2353,9 +2351,7 @@ static int kvm_s390_set_cmma_bits(struct kvm *kvm,
        } while (r == -ENOMEM);
 
        set_bit(GMAP_FLAG_USES_CMM, &kvm->arch.gmap->flags);
-out:
-       kvm_s390_free_mmu_cache(mc);
-       vfree(bits);
+
        return r;
 }