Skip to contentSkip to conversation

bitops.h: correctly handle rol32 with 0 byte shift

PATCH Superseded Sasha Levin 1 participant 1 message Dec 3, 2015 Bitops API

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bitops.h: correctly handle rol32 with 0 byte shift

rol on a 32 bit integer with a shift of 32 or more is undefined and the result is arch-dependent. Avoid this by handling the trivial case of roling by 0 correctly.

---
 include/linux/bitops.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/bitops.h +1 -1
index 2b8ed12..7047a06 100644
@@ -107,7 +107,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
  */
 static inline __u32 rol32(__u32 word, unsigned int shift)
 {
-	return (word << shift) | (word >> (32 - shift));
+	return shift ? (word << shift) | (word >> (32 - shift)) : word;
 }
 
 /**
Signature · 1 line
1.7.10.4