]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: selftests: kvm_binary_stats_test: Fix index expressions
authorAndrew Jones <drjones@redhat.com>
Tue, 14 Jun 2022 08:10:41 +0000 (10:10 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 14 Jun 2022 16:43:53 +0000 (12:43 -0400)
kvm_binary_stats_test accepts two arguments, the number of vms
and number of vcpus. If these inputs are not equal then the
test would likely crash for one reason or another due to using
miscalculated indices for the vcpus array. Fix the index
expressions by swapping the use of i and j.

Signed-off-by: Andrew Jones <drjones@redhat.com>
Message-Id: <20220614081041.2571511-1-drjones@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/kvm_binary_stats_test.c

index 1baabf955d634dc3dc86b8d23a9b11852026867e..3c2d06b61442e43ad49c25a5496cf37da9e102f0 100644 (file)
@@ -225,14 +225,14 @@ int main(int argc, char *argv[])
        for (i = 0; i < max_vm; ++i) {
                vms[i] = vm_create_barebones();
                for (j = 0; j < max_vcpu; ++j)
-                       vcpus[j * max_vcpu + i] = __vm_vcpu_add(vms[i], j);
+                       vcpus[i * max_vcpu + j] = __vm_vcpu_add(vms[i], j);
        }
 
        /* Check stats read for every VM and VCPU */
        for (i = 0; i < max_vm; ++i) {
                vm_stats_test(vms[i]);
                for (j = 0; j < max_vcpu; ++j)
-                       vcpu_stats_test(vcpus[j * max_vcpu + i]);
+                       vcpu_stats_test(vcpus[i * max_vcpu + j]);
        }
 
        for (i = 0; i < max_vm; ++i)