Skip to content

Commit d21b3c6

Browse files
ColinIanKingsean-jc
authored andcommitted
KVM: selftests: Fix shift of 32 bit unsigned int more than 32 bits
Currrentl a 32 bit 1u value is being shifted more than 32 bits causing overflow and incorrect checking of bits 32-63. Fix this by using the BIT_ULL macro for shifting bits. Detected by cppcheck: sev_init2_tests.c:108:34: error: Shifting 32-bit value by 63 bits is undefined behaviour [shiftTooManyBits] Fixes: dfc083a ("selftests: kvm: add tests for KVM_SEV_INIT2") Signed-off-by: Colin Ian King <colin.i.king@gmail.com> Link: https://lore.kernel.org/r/20240523154102.2236133-1-colin.i.king@gmail.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent c3f38fa commit d21b3c6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tools/testing/selftests/kvm/x86_64/sev_init2_tests.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ void test_features(uint32_t vm_type, uint64_t supported_features)
105105
int i;
106106

107107
for (i = 0; i < 64; i++) {
108-
if (!(supported_features & (1u << i)))
108+
if (!(supported_features & BIT_ULL(i)))
109109
test_init2_invalid(vm_type,
110110
&(struct kvm_sev_init){ .vmsa_features = BIT_ULL(i) },
111111
"unknown feature");
112-
else if (KNOWN_FEATURES & (1u << i))
112+
else if (KNOWN_FEATURES & BIT_ULL(i))
113113
test_init2(vm_type,
114114
&(struct kvm_sev_init){ .vmsa_features = BIT_ULL(i) });
115115
}

0 commit comments

Comments
 (0)