]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
KVM: use kvcalloc for array allocations
authorPaolo Bonzini <pbonzini@redhat.com>
Tue, 8 Mar 2022 09:57:39 +0000 (04:57 -0500)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 9 Mar 2022 09:36:26 +0000 (04:36 -0500)
Instead of using array_size, use a function that takes care of the
multiplication.  While at it, switch to kvcalloc since this allocation
should not be very large.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/cpuid.c

index afcdd4e693e510d912b42a9dfa741461b97e7dc8..419eb8e14f793260f97b6d91a1e3eacc74aa211d 100644 (file)
@@ -1248,8 +1248,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
        if (sanity_check_entries(entries, cpuid->nent, type))
                return -EINVAL;
 
-       array.entries = vzalloc(array_size(sizeof(struct kvm_cpuid_entry2),
-                                          cpuid->nent));
+       array.entries = kvcalloc(sizeof(struct kvm_cpuid_entry2), cpuid->nent, GFP_KERNEL);
        if (!array.entries)
                return -ENOMEM;
 
@@ -1267,7 +1266,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
                r = -EFAULT;
 
 out_free:
-       vfree(array.entries);
+       kvfree(array.entries);
        return r;
 }