ftl: fix find_last_group() to use proper group offsets

This commit is contained in:
S.J.R. van Schaik 2017-08-01 15:51:50 +02:00
parent 51da9338ea
commit e6c1197d07

View file

@ -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;
}