Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 0dd714bfd200 ("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>

authored by

Nina Schoetterl-Glausch and committed by
Janosch Frank
00de073e 85a19b30

+2
+2
tools/testing/selftests/kvm/s390x/memop.c
··· 489 489 490 490 amount = (amount + bits) % bits; 491 491 val = cut_to_size(size, val); 492 + if (!amount) 493 + return val; 492 494 return (val << (bits - amount)) | (val >> amount); 493 495 } 494 496