aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2014-10-29 17:50:44 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-10-29 19:33:14 -0400
commitea5d05b34aca25c066e0699512d0ffbd8ee6ac3e (patch)
tree279314a06c4f6211997b53caef834c866f957a6f /lib
parent5a6e7599d3f8000496068b12276492311efad5ea (diff)
lib/bitmap.c: fix undefined shift in __bitmap_shift_{left|right}()
If __bitmap_shift_left() or __bitmap_shift_right() are asked to shift by a multiple of BITS_PER_LONG, they will try to shift a long value by BITS_PER_LONG bits which is undefined. Change the functions to avoid the undefined shift. Coverity id: 1192175 Coverity id: 1192174 Signed-off-by: Jan Kara <jack@suse.cz> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/bitmap.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/bitmap.c b/lib/bitmap.c
index cd250a2e14cb..b499ab6ada29 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -131,7 +131,9 @@ void __bitmap_shift_right(unsigned long *dst,
131 lower = src[off + k]; 131 lower = src[off + k];
132 if (left && off + k == lim - 1) 132 if (left && off + k == lim - 1)
133 lower &= mask; 133 lower &= mask;
134 dst[k] = upper << (BITS_PER_LONG - rem) | lower >> rem; 134 dst[k] = lower >> rem;
135 if (rem)
136 dst[k] |= upper << (BITS_PER_LONG - rem);
135 if (left && k == lim - 1) 137 if (left && k == lim - 1)
136 dst[k] &= mask; 138 dst[k] &= mask;
137 } 139 }
@@ -172,7 +174,9 @@ void __bitmap_shift_left(unsigned long *dst,
172 upper = src[k]; 174 upper = src[k];
173 if (left && k == lim - 1) 175 if (left && k == lim - 1)
174 upper &= (1UL << left) - 1; 176 upper &= (1UL << left) - 1;
175 dst[k + off] = lower >> (BITS_PER_LONG - rem) | upper << rem; 177 dst[k + off] = upper << rem;
178 if (rem)
179 dst[k + off] |= lower >> (BITS_PER_LONG - rem);
176 if (left && k + off == lim - 1) 180 if (left && k + off == lim - 1)
177 dst[k + off] &= (1UL << left) - 1; 181 dst[k + off] &= (1UL << left) - 1;
178 } 182 }