Skip to contentSkip to conversation

KVM: selftests: kvm_binary_stats_test: Fix index expressions

PATCH In review Andrew Jones 2 participants 2 messages Jun 14, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: selftests: kvm_binary_stats_test: Fix index expressions

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.

---

Applies to kvm/queue

 tools/testing/selftests/kvm/kvm_binary_stats_test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/kvm/kvm_binary_stats_test.c +2 -2
index 1baabf955d63..3c2d06b61442 100644
@@ -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)
Signature · 1 line
2.34.3
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Andrew Jones

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.

---

Thanks! I had done this locally but lost track of it when updating kvm/queue.