axmap: use 64-bit type for number of bits
authorJens Axboe <axboe@kernel.dk>
Mon, 17 Sep 2018 03:30:39 +0000 (21:30 -0600)
committerJens Axboe <axboe@kernel.dk>
Mon, 17 Sep 2018 03:30:39 +0000 (21:30 -0600)
For huge devices, we can overflow on a 32-bit build of fio.

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

index 03e712f53be7a7623f90b12a3eecf57d73fc6f62..767a73177d3f0b7e58837441f7d46fece03652b2 100644 (file)
@@ -110,7 +110,7 @@ void axmap_free(struct axmap *axmap)
 }
 
 /* Allocate memory for a set that can store the numbers 0 .. @nr_bits - 1. */
-struct axmap *axmap_new(unsigned long nr_bits)
+struct axmap *axmap_new(uint64_t nr_bits)
 {
        struct axmap *axmap;
        unsigned int i, levels;
@@ -135,13 +135,14 @@ struct axmap *axmap_new(unsigned long nr_bits)
        for (i = 0; i < axmap->nr_levels; i++) {
                struct axmap_level *al = &axmap->levels[i];
 
+               nr_bits = (nr_bits + BLOCKS_PER_UNIT - 1) >> UNIT_SHIFT;
+
                al->level = i;
-               al->map_size = (nr_bits + BLOCKS_PER_UNIT - 1) >> UNIT_SHIFT;
+               al->map_size = nr_bits;
                al->map = malloc(al->map_size * sizeof(unsigned long));
                if (!al->map)
                        goto free_levels;
 
-               nr_bits = (nr_bits + BLOCKS_PER_UNIT - 1) >> UNIT_SHIFT;
        }
 
        axmap_reset(axmap);
index 55349d8731f2e4edfcc01f7aad025e309782acf6..aa5976898c114fb8870865db753200a6140cc978 100644 (file)
@@ -5,7 +5,7 @@
 #include "types.h"
 
 struct axmap;
-struct axmap *axmap_new(unsigned long nr_bits);
+struct axmap *axmap_new(uint64_t nr_bits);
 void axmap_free(struct axmap *bm);
 
 void axmap_set(struct axmap *axmap, uint64_t bit_nr);