Skip to content

Commit 3a23d05

Browse files
Li Nanaxboe
authored andcommitted
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 <[email protected]> Reviewed-by: Yu Kuai <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 3744668 commit 3a23d05

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

block/badblocks.c

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -905,39 +905,35 @@ static int _badblocks_set(struct badblocks *bb, sector_t s, int sectors,
905905
goto update_sectors;
906906
}
907907

908+
if (can_merge_front(bb, prev, &bad)) {
909+
len = front_merge(bb, prev, &bad);
910+
added++;
911+
hint = prev;
912+
goto update_sectors;
913+
}
914+
908915
if (overlap_front(bb, prev, &bad)) {
909-
if (can_merge_front(bb, prev, &bad)) {
910-
len = front_merge(bb, prev, &bad);
911-
added++;
912-
} else {
913-
int extra = 0;
916+
int extra = 0;
914917

915-
if (!can_front_overwrite(bb, prev, &bad, &extra)) {
916-
if (extra > 0)
917-
goto out;
918+
if (!can_front_overwrite(bb, prev, &bad, &extra)) {
919+
if (extra > 0)
920+
goto out;
918921

919-
len = min_t(sector_t,
920-
BB_END(p[prev]) - s, sectors);
921-
hint = prev;
922-
goto update_sectors;
923-
}
922+
len = min_t(sector_t,
923+
BB_END(p[prev]) - s, sectors);
924+
hint = prev;
925+
goto update_sectors;
926+
}
924927

925-
len = front_overwrite(bb, prev, &bad, extra);
926-
added++;
927-
bb->count += extra;
928+
len = front_overwrite(bb, prev, &bad, extra);
929+
added++;
930+
bb->count += extra;
928931

929-
if (can_combine_front(bb, prev, &bad)) {
930-
front_combine(bb, prev);
931-
bb->count--;
932-
}
932+
if (can_combine_front(bb, prev, &bad)) {
933+
front_combine(bb, prev);
934+
bb->count--;
933935
}
934-
hint = prev;
935-
goto update_sectors;
936-
}
937936

938-
if (can_merge_front(bb, prev, &bad)) {
939-
len = front_merge(bb, prev, &bad);
940-
added++;
941937
hint = prev;
942938
goto update_sectors;
943939
}

0 commit comments

Comments
 (0)