From: Jens Axboe Date: Wed, 23 Jan 2013 17:15:05 +0000 (-0700) Subject: axmap: fix bug in axmap_find_first_free() X-Git-Tag: fio-2.0.14~102 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=55348b420e618b1c5c50106261437fe948ef2132 axmap: fix bug in axmap_find_first_free() If the map is completely full, we could return an invalid value for the first free bit. So check if we actually found a match, return failure if we didn't. Signed-off-by: Jens Axboe --- diff --git a/lib/axmap.c b/lib/axmap.c index d9ad30bf..7351e297 100644 --- a/lib/axmap.c +++ b/lib/axmap.c @@ -309,7 +309,7 @@ static uint64_t axmap_find_first_free(struct axmap *axmap, unsigned int level, uint64_t index) { unsigned long j; - int i; + int i, found = 0; /* * Start at the bottom, then converge towards first free bit at the top @@ -331,11 +331,12 @@ static uint64_t axmap_find_first_free(struct axmap *axmap, unsigned int level, * free bit at the next higher level */ index = (j << UNIT_SHIFT) + ffz(al->map[j]); + found = 1; break; } } - return index; + return found ? index : (uint64_t) -1ULL; } uint64_t axmap_first_free(struct axmap *axmap)