From 3a23d05f9c1abf8238fe48167ab5574062d1606e Mon Sep 17 00:00:00 2001 From: Li Nan Date: Thu, 27 Feb 2025 15:55:02 +0800 Subject: [PATCH] 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 Reviewed-by: Yu Kuai Link: https://lore.kernel.org/r/20250227075507.151331-8-zhengqixing@huaweicloud.com Signed-off-by: Jens Axboe --- block/badblocks.c | 52 ++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/block/badblocks.c b/block/badblocks.c index 43430bd3efa7..57e9edf9b848 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -905,39 +905,35 @@ static int _badblocks_set(struct badblocks *bb, sector_t s, int sectors, 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; }