mirror of
https://github.com/torvalds/linux.git
synced 2026-09-25 21:21:09 -04:00
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: 0dd714bfd2 ("KVM: s390: selftest: memop: Add cmpxchg tests")
Signed-off-by: Nina Schoetterl-Glausch <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Acked-by: Janosch Frank <[email protected]>
Signed-off-by: Janosch Frank <[email protected]>
Message-Id: <[email protected]>
This commit is contained in:
committed by
Janosch Frank
parent
85a19b3054
commit
00de073e24
@@ -489,6 +489,8 @@ static __uint128_t rotate(int size, __uint128_t val, int amount)
|
||||
|
||||
amount = (amount + bits) % bits;
|
||||
val = cut_to_size(size, val);
|
||||
if (!amount)
|
||||
return val;
|
||||
return (val << (bits - amount)) | (val >> amount);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user