Skip to content

Commit 00de073

Browse files
Nina Schoetterl-Glauschfrankjaa
authored andcommitted
KVM: s390: selftest: memop: Fix undefined behavior
If an integer's type has x bits, shifting the integer left by x or more is undefined behavior. This can happen in the rotate function when attempting to do a rotation of the whole value by 0. Fixes: 0dd714b ("KVM: s390: selftest: memop: Add cmpxchg tests") Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com> Link: https://lore.kernel.org/r/20240111094805.363047-1-nsg@linux.ibm.com Acked-by: Janosch Frank <frankja@linux.ibm.com> Signed-off-by: Janosch Frank <frankja@linux.ibm.com> Message-Id: <20240111094805.363047-1-nsg@linux.ibm.com>
1 parent 85a19b3 commit 00de073

File tree

1 file changed

+2
-0
lines changed
  • tools/testing/selftests/kvm/s390x

1 file changed

+2
-0
lines changed

tools/testing/selftests/kvm/s390x/memop.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ static __uint128_t rotate(int size, __uint128_t val, int amount)
489489

490490
amount = (amount + bits) % bits;
491491
val = cut_to_size(size, val);
492+
if (!amount)
493+
return val;
492494
return (val << (bits - amount)) | (val >> amount);
493495
}
494496

0 commit comments

Comments
 (0)