badblocks: try can_merge_front before overlap_front

Regardless of whether overlap_front() returns true or false,
can_merge_front() will be executed first. Therefore, move
can_merge_front() in front of can_merge_front() to simplify code.

Signed-off-by: Li Nan <linan122@huawei.com>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/20250227075507.151331-8-zhengqixing@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Li Nan 2025-02-27 15:55:02 +08:00 committed by Jens Axboe
parent 37446680df
commit 3a23d05f9c
1 changed files with 24 additions and 28 deletions

View File

@ -905,39 +905,35 @@ re_insert:
goto update_sectors;
}
if (overlap_front(bb, prev, &bad)) {
if (can_merge_front(bb, prev, &bad)) {
len = front_merge(bb, prev, &bad);
added++;
} else {
int extra = 0;
if (!can_front_overwrite(bb, prev, &bad, &extra)) {
if (extra > 0)
goto out;
len = min_t(sector_t,
BB_END(p[prev]) - s, sectors);
hint = prev;
goto update_sectors;
}
len = front_overwrite(bb, prev, &bad, extra);
added++;
bb->count += extra;
if (can_combine_front(bb, prev, &bad)) {
front_combine(bb, prev);
bb->count--;
}
}
if (can_merge_front(bb, prev, &bad)) {
len = front_merge(bb, prev, &bad);
added++;
hint = prev;
goto update_sectors;
}
if (can_merge_front(bb, prev, &bad)) {
len = front_merge(bb, prev, &bad);
if (overlap_front(bb, prev, &bad)) {
int extra = 0;
if (!can_front_overwrite(bb, prev, &bad, &extra)) {
if (extra > 0)
goto out;
len = min_t(sector_t,
BB_END(p[prev]) - s, sectors);
hint = prev;
goto update_sectors;
}
len = front_overwrite(bb, prev, &bad, extra);
added++;
bb->count += extra;
if (can_combine_front(bb, prev, &bad)) {
front_combine(bb, prev);
bb->count--;
}
hint = prev;
goto update_sectors;
}