From: Jens Axboe Date: Wed, 28 Nov 2012 18:36:16 +0000 (+0100) Subject: bitmap: fix off-by-8 allocation error X-Git-Tag: fio-2.0.12~38^2~3 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=dbfb51e3e742a2bfd151dc46aaf9e944da92a13b;ds=sidebyside 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 --- 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;