Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Li Nan and committed by
Jens Axboe
3a23d05f 37446680

+24 -28
+24 -28
block/badblocks.c
··· 905 905 goto update_sectors; 906 906 } 907 907 908 - 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; 914 - 915 - if (!can_front_overwrite(bb, prev, &bad, &extra)) { 916 - if (extra > 0) 917 - goto out; 918 - 919 - len = min_t(sector_t, 920 - BB_END(p[prev]) - s, sectors); 921 - hint = prev; 922 - goto update_sectors; 923 - } 924 - 925 - len = front_overwrite(bb, prev, &bad, extra); 926 - added++; 927 - bb->count += extra; 928 - 929 - if (can_combine_front(bb, prev, &bad)) { 930 - front_combine(bb, prev); 931 - bb->count--; 932 - } 933 - } 908 + if (can_merge_front(bb, prev, &bad)) { 909 + len = front_merge(bb, prev, &bad); 910 + added++; 934 911 hint = prev; 935 912 goto update_sectors; 936 913 } 937 914 938 - if (can_merge_front(bb, prev, &bad)) { 939 - len = front_merge(bb, prev, &bad); 915 + if (overlap_front(bb, prev, &bad)) { 916 + int extra = 0; 917 + 918 + if (!can_front_overwrite(bb, prev, &bad, &extra)) { 919 + if (extra > 0) 920 + goto out; 921 + 922 + len = min_t(sector_t, 923 + BB_END(p[prev]) - s, sectors); 924 + hint = prev; 925 + goto update_sectors; 926 + } 927 + 928 + len = front_overwrite(bb, prev, &bad, extra); 940 929 added++; 930 + bb->count += extra; 931 + 932 + if (can_combine_front(bb, prev, &bad)) { 933 + front_combine(bb, prev); 934 + bb->count--; 935 + } 936 + 941 937 hint = prev; 942 938 goto update_sectors; 943 939 }