Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1283414 > unrolled thread

[PATCH] bitops.h: correctly handle rol32 with 0 byte shift

Started bySasha Levin <sasha.levin@oracle.com>
First post2015-12-03 23:10 +0100
Last post2015-12-03 23:10 +0100
Articles 1 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH] bitops.h: correctly handle rol32 with 0 byte shift Sasha Levin <sasha.levin@oracle.com> - 2015-12-03 23:10 +0100

#1283414 — [PATCH] bitops.h: correctly handle rol32 with 0 byte shift

FromSasha Levin <sasha.levin@oracle.com>
Date2015-12-03 23:10 +0100
Subject[PATCH] bitops.h: correctly handle rol32 with 0 byte shift
Message-ID<qBKeB-2ve-1@gated-at.bofh.it>
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.

Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
---
 include/linux/bitops.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 2b8ed12..7047a06 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -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;
 }
 
 /**
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web