aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYury Norov <yury.norov@gmail.com>2015-04-16 15:44:00 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-04-17 09:03:56 -0400
commit2afe27c718b669b551895595873611ac39cc31e3 (patch)
tree69c4b547b6dc2332514757c7a93e2fce1c6692ff
parentd48502eacd8934b79c3e62f7858c79fa6422398b (diff)
lib/bitmap.c: bitmap_[empty,full]: remove code duplication
bitmap_empty() has its own implementation. But it's clearly as simple as: find_first_bit(src, nbits) == nbits The same is true for 'bitmap_full'. Signed-off-by: Yury Norov <yury.norov@gmail.com> Cc: George Spelvin <linux@horizon.com> Cc: Alexey Klimov <klimov.linux@gmail.com> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--include/linux/bitmap.h8
-rw-r--r--lib/bitmap.c30
2 files changed, 4 insertions, 34 deletions
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index be4fa5ddf36c..ea17cca9e685 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -283,16 +283,16 @@ static inline int bitmap_empty(const unsigned long *src, unsigned nbits)
283{ 283{
284 if (small_const_nbits(nbits)) 284 if (small_const_nbits(nbits))
285 return ! (*src & BITMAP_LAST_WORD_MASK(nbits)); 285 return ! (*src & BITMAP_LAST_WORD_MASK(nbits));
286 else 286
287 return __bitmap_empty(src, nbits); 287 return find_first_bit(src, nbits) == nbits;
288} 288}
289 289
290static inline int bitmap_full(const unsigned long *src, unsigned int nbits) 290static inline int bitmap_full(const unsigned long *src, unsigned int nbits)
291{ 291{
292 if (small_const_nbits(nbits)) 292 if (small_const_nbits(nbits))
293 return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits)); 293 return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits));
294 else 294
295 return __bitmap_full(src, nbits); 295 return find_first_zero_bit(src, nbits) == nbits;
296} 296}
297 297
298static inline int bitmap_weight(const unsigned long *src, unsigned int nbits) 298static inline int bitmap_weight(const unsigned long *src, unsigned int nbits)
diff --git a/lib/bitmap.c b/lib/bitmap.c
index d456f4c15a9f..64c0926f5dd8 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -42,36 +42,6 @@
42 * for the best explanations of this ordering. 42 * for the best explanations of this ordering.
43 */ 43 */
44 44
45int __bitmap_empty(const unsigned long *bitmap, unsigned int bits)
46{
47 unsigned int k, lim = bits/BITS_PER_LONG;
48 for (k = 0; k < lim; ++k)
49 if (bitmap[k])
50 return 0;
51
52 if (bits % BITS_PER_LONG)
53 if (bitmap[k] & BITMAP_LAST_WORD_MASK(bits))
54 return 0;
55
56 return 1;
57}
58EXPORT_SYMBOL(__bitmap_empty);
59
60int __bitmap_full(const unsigned long *bitmap, unsigned int bits)
61{
62 unsigned int k, lim = bits/BITS_PER_LONG;
63 for (k = 0; k < lim; ++k)
64 if (~bitmap[k])
65 return 0;
66
67 if (bits % BITS_PER_LONG)
68 if (~bitmap[k] & BITMAP_LAST_WORD_MASK(bits))
69 return 0;
70
71 return 1;
72}
73EXPORT_SYMBOL(__bitmap_full);
74
75int __bitmap_equal(const unsigned long *bitmap1, 45int __bitmap_equal(const unsigned long *bitmap1,
76 const unsigned long *bitmap2, unsigned int bits) 46 const unsigned long *bitmap2, unsigned int bits)
77{ 47{