]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
badblocks: try can_merge_front before overlap_front
authorLi Nan <linan122@huawei.com>
Thu, 27 Feb 2025 07:55:02 +0000 (15:55 +0800)
committerJens Axboe <axboe@kernel.dk>
Thu, 6 Mar 2025 15:03:28 +0000 (08:03 -0700)
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>
block/badblocks.c

index 43430bd3efa7d11383f1d65443c7c77cb9b6fecf..57e9edf9b84879cafdd24a876ca503bc6d758b80 100644 (file)
@@ -905,39 +905,35 @@ re_insert:
                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;
        }