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 <axboe@kernel.dk>
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
* 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)