]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: fix kvm_mmu_memory_cache allocation warning
authorArnd Bergmann <arnd@arndb.de>
Mon, 12 Feb 2024 11:24:10 +0000 (12:24 +0100)
committerSean Christopherson <seanjc@google.com>
Fri, 23 Feb 2024 01:02:26 +0000 (17:02 -0800)
gcc-14 notices that the arguments to kvmalloc_array() are mixed up:

arch/x86/kvm/../../../virt/kvm/kvm_main.c: In function '__kvm_mmu_topup_memory_cache':
arch/x86/kvm/../../../virt/kvm/kvm_main.c:424:53: error: 'kvmalloc_array' sizes specified with 'sizeof' in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
  424 |                 mc->objects = kvmalloc_array(sizeof(void *), capacity, gfp);
      |                                                     ^~~~
arch/x86/kvm/../../../virt/kvm/kvm_main.c:424:53: note: earlier argument should specify number of elements, later size of each element

The code still works correctly, but the incorrect order prevents the compiler
from properly tracking the object sizes.

Fixes: 837f66c71207 ("KVM: Allow for different capacities in kvm_mmu_memory_cache structs")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20240212112419.1186065-1-arnd@kernel.org
Signed-off-by: Sean Christopherson <seanjc@google.com>
virt/kvm/kvm_main.c

index 8f03b56dafbdab27b0f5085c3ac7e82cc6531f99..4c48f61cae35a9c3db68b77d0091bf00773e9de2 100644 (file)
@@ -421,7 +421,7 @@ int __kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, int capacity,
                if (WARN_ON_ONCE(!capacity))
                        return -EIO;
 
-               mc->objects = kvmalloc_array(sizeof(void *), capacity, gfp);
+               mc->objects = kvmalloc_array(capacity, sizeof(void *), gfp);
                if (!mc->objects)
                        return -ENOMEM;