aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/bitmap.h2
-rw-r--r--lib/bitmap.c7
2 files changed, 6 insertions, 3 deletions
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 75df61d9ecfb..3399a9ecd991 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -191,7 +191,7 @@ static inline int bitmap_and(unsigned long *dst, const unsigned long *src1,
191 const unsigned long *src2, unsigned int nbits) 191 const unsigned long *src2, unsigned int nbits)
192{ 192{
193 if (small_const_nbits(nbits)) 193 if (small_const_nbits(nbits))
194 return (*dst = *src1 & *src2) != 0; 194 return (*dst = *src1 & *src2 & BITMAP_LAST_WORD_MASK(nbits)) != 0;
195 return __bitmap_and(dst, src1, src2, nbits); 195 return __bitmap_and(dst, src1, src2, nbits);
196} 196}
197 197
diff --git a/lib/bitmap.c b/lib/bitmap.c
index faaf7206d4cf..ce2ec80bf431 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -185,11 +185,14 @@ int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
185 const unsigned long *bitmap2, unsigned int bits) 185 const unsigned long *bitmap2, unsigned int bits)
186{ 186{
187 unsigned int k; 187 unsigned int k;
188 unsigned int nr = BITS_TO_LONGS(bits); 188 unsigned int lim = bits/BITS_PER_LONG;
189 unsigned long result = 0; 189 unsigned long result = 0;
190 190
191 for (k = 0; k < nr; k++) 191 for (k = 0; k < lim; k++)
192 result |= (dst[k] = bitmap1[k] & bitmap2[k]); 192 result |= (dst[k] = bitmap1[k] & bitmap2[k]);
193 if (bits % BITS_PER_LONG)
194 result |= (dst[k] = bitmap1[k] & bitmap2[k] &
195 BITMAP_LAST_WORD_MASK(bits));
193 return result != 0; 196 return result != 0;
194} 197}
195EXPORT_SYMBOL(__bitmap_and); 198EXPORT_SYMBOL(__bitmap_and);