Commit 00de073e authored by Nina Schoetterl-Glausch's avatar Nina Schoetterl-Glausch Committed by Janosch Frank

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: 0dd714bf ("KVM: s390: selftest: memop: Add cmpxchg tests")
Signed-off-by: default avatarNina Schoetterl-Glausch <nsg@linux.ibm.com>
Link: https://lore.kernel.org/r/20240111094805.363047-1-nsg@linux.ibm.comAcked-by: default avatarJanosch Frank <frankja@linux.ibm.com>
Signed-off-by: default avatarJanosch Frank <frankja@linux.ibm.com>
Message-Id: <20240111094805.363047-1-nsg@linux.ibm.com>
parent 85a19b30
...@@ -489,6 +489,8 @@ static __uint128_t rotate(int size, __uint128_t val, int amount) ...@@ -489,6 +489,8 @@ static __uint128_t rotate(int size, __uint128_t val, int amount)
amount = (amount + bits) % bits; amount = (amount + bits) % bits;
val = cut_to_size(size, val); val = cut_to_size(size, val);
if (!amount)
return val;
return (val << (bits - amount)) | (val >> amount); return (val << (bits - amount)) | (val >> amount);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment