From dbfb51e3e742a2bfd151dc46aaf9e944da92a13b Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 28 Nov 2012 19:36:16 +0100 Subject: [PATCH] bitmap: fix off-by-8 allocation error 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 --- lib/bitmap.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/bitmap.c b/lib/bitmap.c index f0400452..51b91d9c 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -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; -- 2.25.1