Skip to content

Commit

Permalink
KVM: selftests: Fix a condition in test_hv_cpuid()
Browse files Browse the repository at this point in the history
The code is trying to check that all the padding is zeroed out and it
does this:

    entry->padding[0] == entry->padding[1] == entry->padding[2] == 0

Assume everything is zeroed correctly, then the first comparison is
true, the next comparison is false and false is equal to zero so the
overall condition is true.  This bug doesn't affect run time very
badly, but the code should instead just check that all three paddings
are zero individually.

Also the error message was copy and pasted from an earlier error and it
wasn't correct.

Fixes: 7edcb73 ("KVM: selftests: Add hyperv_cpuid test")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
Dan Carpenter authored and Paolo Bonzini committed May 24, 2019
1 parent 2eb06c3 commit be7fcf1
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ static void test_hv_cpuid(struct kvm_cpuid2 *hv_cpuid_entries,
TEST_ASSERT(entry->flags == 0,
".flags field should be zero");

TEST_ASSERT(entry->padding[0] == entry->padding[1]
== entry->padding[2] == 0,
".index field should be zero");
TEST_ASSERT(!entry->padding[0] && !entry->padding[1] &&
!entry->padding[2], "padding should be zero");

/*
* If needed for debug:
Expand Down

0 comments on commit be7fcf1

Please sign in to comment.