summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2018-09-16 21:30:39 -0600
committerJens Axboe <axboe@kernel.dk>2018-09-16 21:30:39 -0600
commit604d3f5bd9f2b985568593c23f8292cbc7f4044c (patch)
treea1e863b9b81d67bdc84aff3df41be592bbbc715d /lib
parent84a815f5535cc9ac56e6c45926f0a2f4fe7c4b3f (diff)
downloadfio-604d3f5bd9f2b985568593c23f8292cbc7f4044c.tar.gz
fio-604d3f5bd9f2b985568593c23f8292cbc7f4044c.tar.bz2
axmap: use 64-bit type for number of bits
For huge devices, we can overflow on a 32-bit build of fio. Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'lib')
-rw-r--r--lib/axmap.c7
-rw-r--r--lib/axmap.h2
2 files changed, 5 insertions, 4 deletions
diff --git a/lib/axmap.c b/lib/axmap.c
index 03e712f5..767a7317 100644
--- a/lib/axmap.c
+++ b/lib/axmap.c
@@ -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);
diff --git a/lib/axmap.h b/lib/axmap.h
index 55349d87..aa597689 100644
--- a/lib/axmap.h
+++ b/lib/axmap.h
@@ -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);