在 2025/02/21 16:11, Zheng Qixing 写道:
> From: Li Nan <linan122@huawei.com>
>
> 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>
> ---
> block/badblocks.c | 48 ++++++++++++++++++++++-------------------------
> 1 file changed, 22 insertions(+), 26 deletions(-)
>
LGTM
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
> diff --git a/block/badblocks.c b/block/badblocks.c
> index 87267bae6836..bb46bab7e99f 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 (can_merge_front(bb, prev, &bad)) {
> + len = front_merge(bb, prev, &bad);
> + added++;
> + hint = prev;
> + 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;
> + int extra = 0;
>
> - if (!can_front_overwrite(bb, prev, &bad, &extra)) {
> - if (extra > 0)
> - goto out;
> + 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 = 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;
> + 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_combine_front(bb, prev, &bad)) {
> + 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;
> }
>