bitmap: fix off-by-8 allocation error
authorJens Axboe <axboe@kernel.dk>
Wed, 28 Nov 2012 18:36:16 +0000 (19:36 +0100)
committerJens Axboe <axboe@kernel.dk>
Wed, 28 Nov 2012 18:36:16 +0000 (19:36 +0100)
Was multiplying by the bit-size, not the byte-size. No algorithmic
changes, we never used the 7/8ths of the memory at the end...

Signed-off-by: Jens Axboe <axboe@kernel.dk>
lib/bitmap.c

index f04004520167d2efb4f4871d133db2b275973da0..51b91d9c30d8d40d4f354d1bd92f225f9765ef14 100644 (file)
@@ -9,10 +9,8 @@
 #include "../minmax.h"
 
 #if BITS_PER_LONG == 64
-#define UNIT_SIZE              8
 #define UNIT_SHIFT             6
 #elif BITS_PER_LONG == 32
-#define UNIT_SIZE              4
 #define UNIT_SHIFT             5
 #else
 #error "Number of arch bits unknown"
@@ -50,7 +48,7 @@ void bitmap_reset(struct bitmap *bitmap)
        for (i = 0; i < bitmap->nr_levels; i++) {
                struct bitmap_level *bl = &bitmap->levels[i];
 
-               memset(bl->map, 0, bl->map_size * UNIT_SIZE);
+               memset(bl->map, 0, bl->map_size * sizeof(unsigned long));
        }
 }
 
@@ -93,7 +91,7 @@ struct bitmap *bitmap_new(unsigned long nr_bits)
 
                bl->level = i;
                bl->map_size = (nr_bits + BLOCKS_PER_UNIT - 1) >> UNIT_SHIFT;
-               bl->map = smalloc(bl->map_size << UNIT_SHIFT);
+               bl->map = smalloc(bl->map_size * sizeof(unsigned long));
                if (!bl->map)
                        goto err;