[v1,02/18] KVM: selftests/kvm_util: use vm->vcpus[] when create vm with vcpus

Message ID 20221024113445.1022147-3-wei.w.wang@intel.com
State New
Headers
Series KVM selftests code consolidation and cleanup |

Commit Message

Wang, Wei W Oct. 24, 2022, 11:34 a.m. UTC
  The kvm_vm struct has been changed to maintain vcpus via an array of
vcpu pointers, there is no need to require users to allocate and pass
in another vcpu array when create the vm.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
---
 tools/testing/selftests/kvm/lib/kvm_util.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
  

Patch

diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index 941f6c3ea9dc..1f69f5ca8356 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -371,12 +371,10 @@  struct kvm_vm *__vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus
 	struct kvm_vm *vm;
 	int i;
 
-	TEST_ASSERT(!nr_vcpus || vcpus, "Must provide vCPU array");
-
 	vm = __vm_create(mode, nr_vcpus, extra_mem_pages);
 
 	for (i = 0; i < nr_vcpus; ++i)
-		vcpus[i] = vm_vcpu_add(vm, i, guest_code);
+		vm->vcpus[i] = vm_vcpu_add(vm, i, guest_code);
 
 	return vm;
 }
@@ -385,13 +383,12 @@  struct kvm_vm *__vm_create_with_one_vcpu(struct kvm_vcpu **vcpu,
 					 uint64_t extra_mem_pages,
 					 void *guest_code)
 {
-	struct kvm_vcpu *vcpus[1];
 	struct kvm_vm *vm;
 
 	vm = __vm_create_with_vcpus(VM_MODE_DEFAULT, 1, extra_mem_pages,
-				    guest_code, vcpus);
+				    guest_code, NULL);
 
-	*vcpu = vcpus[0];
+	*vcpu = vm->vcpus[0];
 	return vm;
 }