selftests: kvm: avoid uninitialized variable warning
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 15 Feb 2021 16:42:01 +0000 (11:42 -0500)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 15 Feb 2021 16:42:45 +0000 (11:42 -0500)
The variable in practice will never be uninitialized, because the
loop will always go through at least one iteration.

In case it would not, make vcpu_get_cpuid report an assertion
failure.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/lib/x86_64/processor.c

index de0c761..a8906e6 100644 (file)
@@ -720,7 +720,8 @@ struct kvm_cpuid2 *vcpu_get_cpuid(struct kvm_vm *vm, uint32_t vcpuid)
 {
        struct vcpu *vcpu = vcpu_find(vm, vcpuid);
        struct kvm_cpuid2 *cpuid;
-       int rc, max_ent;
+       int max_ent;
+       int rc = -1;
 
        TEST_ASSERT(vcpu != NULL, "vcpu not found, vcpuid: %u", vcpuid);