diff --git a/source/ftl/map.c b/source/ftl/map.c index af59e45..8778d91 100644 --- a/source/ftl/map.c +++ b/source/ftl/map.c @@ -264,6 +264,9 @@ static uint32_t find_last_group(struct ftl_map *map, uint32_t block) uint32_t ngroups = UINT32_C(1) << map->log2_groups_per_block; uint32_t mid, low = 0, high = ngroups - 1; + low += block << map->log2_groups_per_block; + high += block << map->log2_groups_per_block; + while (low <= high) { mid = (low + high) / 2; @@ -272,9 +275,8 @@ static uint32_t find_last_group(struct ftl_map *map, uint32_t block) continue; } - if (((mid + 1) >= ngroups) || - is_group_erased(map, mid + 1)) - return (block << map->log2_groups_per_block) + mid; + if (is_group_erased(map, mid + 1)) + return mid; low = mid + 1; }