lib: bitmap: add missing mask in bitmap_shift_right
authorRasmus Villemoes <linux@rasmusvillemoes.dk>
Wed, 6 Aug 2014 23:10:20 +0000 (16:10 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 7 Aug 2014 01:01:27 +0000 (18:01 -0700)
There is no guarantee that *src does not contain garbage bits outside
the lower nbits, so we need to mask it before the shift-and-assign.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/bitmap.h

index 2100378333569ad8e33de0f9f16c82f605d1010f..75df61d9ecfb786665a20cf44ae00e1e2a44d50a 100644 (file)
@@ -284,7 +284,7 @@ static inline void bitmap_shift_right(unsigned long *dst,
                        const unsigned long *src, int n, int nbits)
 {
        if (small_const_nbits(nbits))
-               *dst = *src >> n;
+               *dst = (*src & BITMAP_LAST_WORD_MASK(nbits)) >> n;
        else
                __bitmap_shift_right(dst, src, n, nbits);
 }