diff options
author | Rasmus Villemoes <linux@rasmusvillemoes.dk> | 2015-02-13 17:36:13 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-02-14 00:21:35 -0500 |
commit | dba94c2553da1928303c2a6c6410247c88cafc1d (patch) | |
tree | f6721644e3f883db6d2edccffad73756941b8c00 /lib | |
parent | cfac1d080a00544e5cecd2d7c9ebe3d6a5cc18e6 (diff) |
lib: bitmap: change bitmap_shift_left to take unsigned parameters
gcc can generate slightly better code for stuff like "nbits %
BITS_PER_LONG" when it knows nbits is not negative. Since negative size
bitmaps or shift amounts don't make sense, change these parameters of
bitmap_shift_right to unsigned.
If off >= lim (which requires shift >= nbits), k is initialized with a
large positive value, but since I've let k continue to be signed, the loop
will never run and dst will be zeroed as expected. Inside the loop, k is
guaranteed to be non-negative, so the fact that it is promoted to unsigned
in the various expressions it appears in is harmless.
Also use "shift" and "nbits" consistently for the parameter names.
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>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bitmap.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/bitmap.c b/lib/bitmap.c index db88512c3451..74bdf3601245 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c | |||
@@ -148,18 +148,19 @@ EXPORT_SYMBOL(__bitmap_shift_right); | |||
148 | * @dst : destination bitmap | 148 | * @dst : destination bitmap |
149 | * @src : source bitmap | 149 | * @src : source bitmap |
150 | * @shift : shift by this many bits | 150 | * @shift : shift by this many bits |
151 | * @bits : bitmap size, in bits | 151 | * @nbits : bitmap size, in bits |
152 | * | 152 | * |
153 | * Shifting left (multiplying) means moving bits in the LS -> MS | 153 | * Shifting left (multiplying) means moving bits in the LS -> MS |
154 | * direction. Zeros are fed into the vacated LS bit positions | 154 | * direction. Zeros are fed into the vacated LS bit positions |
155 | * and those MS bits shifted off the top are lost. | 155 | * and those MS bits shifted off the top are lost. |
156 | */ | 156 | */ |
157 | 157 | ||
158 | void __bitmap_shift_left(unsigned long *dst, | 158 | void __bitmap_shift_left(unsigned long *dst, const unsigned long *src, |
159 | const unsigned long *src, int shift, int bits) | 159 | unsigned int shift, unsigned int nbits) |
160 | { | 160 | { |
161 | int k, lim = BITS_TO_LONGS(bits), left = bits % BITS_PER_LONG; | 161 | int k; |
162 | int off = shift/BITS_PER_LONG, rem = shift % BITS_PER_LONG; | 162 | unsigned int lim = BITS_TO_LONGS(nbits), left = nbits % BITS_PER_LONG; |
163 | unsigned int off = shift/BITS_PER_LONG, rem = shift % BITS_PER_LONG; | ||
163 | for (k = lim - off - 1; k >= 0; --k) { | 164 | for (k = lim - off - 1; k >= 0; --k) { |
164 | unsigned long upper, lower; | 165 | unsigned long upper, lower; |
165 | 166 | ||