Skip to content

Commit cfac1d0

Browse files
Villemoestorvalds
authored andcommitted
lib: bitmap: yet another simplification in __bitmap_shift_right
If left is 0, we can just let mask be ~0UL, so that anding with it is a no-op. Conveniently, BITMAP_LAST_WORD_MASK provides precisely what we need, and we can eliminate left. 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>
1 parent 97fb8e9 commit cfac1d0

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎lib/bitmap.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ EXPORT_SYMBOL(__bitmap_complement);
113113
void __bitmap_shift_right(unsigned long *dst, const unsigned long *src,
114114
unsigned shift, unsigned nbits)
115115
{
116-
unsigned k, lim = BITS_TO_LONGS(nbits), left = nbits % BITS_PER_LONG;
116+
unsigned k, lim = BITS_TO_LONGS(nbits);
117117
unsigned off = shift/BITS_PER_LONG, rem = shift % BITS_PER_LONG;
118-
unsigned long mask = (1UL << left) - 1;
118+
unsigned long mask = BITMAP_LAST_WORD_MASK(nbits);
119119
for (k = 0; off + k < lim; ++k) {
120120
unsigned long upper, lower;
121121

@@ -127,12 +127,12 @@ void __bitmap_shift_right(unsigned long *dst, const unsigned long *src,
127127
upper = 0;
128128
else {
129129
upper = src[off + k + 1];
130-
if (off + k + 1 == lim - 1 && left)
130+
if (off + k + 1 == lim - 1)
131131
upper &= mask;
132132
upper <<= (BITS_PER_LONG - rem);
133133
}
134134
lower = src[off + k];
135-
if (left && off + k == lim - 1)
135+
if (off + k == lim - 1)
136136
lower &= mask;
137137
lower >>= rem;
138138
dst[k] = lower | upper;

0 commit comments

Comments
 (0)