Commit 3a23d05f authored by Li Nan's avatar Li Nan Committed by Jens Axboe
Browse files

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: default avatarLi Nan <linan122@huawei.com>
Reviewed-by: default avatarYu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/20250227075507.151331-8-zhengqixing@huaweicloud.com


Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 37446680
Loading
Loading
Loading
Loading
+22 −26
Original line number Diff line number Diff line
@@ -905,11 +905,14 @@ 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 {
		hint = prev;
		goto update_sectors;
	}

	if (overlap_front(bb, prev, &bad)) {
		int extra = 0;

		if (!can_front_overwrite(bb, prev, &bad, &extra)) {
@@ -930,14 +933,7 @@ static int _badblocks_set(struct badblocks *bb, sector_t s, int sectors,
			front_combine(bb, prev);
			bb->count--;
		}
		}
		hint = prev;
		goto update_sectors;
	}

	if (can_merge_front(bb, prev, &bad)) {
		len = front_merge(bb, prev, &bad);
		added++;
		hint = prev;
		goto update_sectors;
	}