Skip to content

Commit 9ec65de

Browse files
Li Nanaxboe
authored andcommitted
badblocks: fix merge issue when new badblocks align with pre+1
There is a merge issue when adding badblocks as follow: echo 0 10 > bad_blocks echo 30 10 > bad_blocks echo 20 10 > bad_blocks cat bad_blocks 0 10 20 10 //should be merged with (30 10) 30 10 In this case, if new badblocks does not intersect with prev, it is added by insert_at(). If there is an intersection with prev+1, the merge will be processed in the next re_insert loop. However, when the end of the new badblocks is exactly equal to the offset of prev+1, no further re_insert loop occurs, and the two badblocks are not merge. Fix it by inc prev, badblocks can be merged during the subsequent code. Fixes: aa511ff ("badblocks: switch to the improved badblock handling code") Signed-off-by: Li Nan <[email protected]> Reviewed-by: Yu Kuai <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 3a23d05 commit 9ec65de

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

block/badblocks.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ static int _badblocks_set(struct badblocks *bb, sector_t s, int sectors,
892892
len = insert_at(bb, 0, &bad);
893893
bb->count++;
894894
added++;
895-
hint = 0;
895+
hint = ++prev;
896896
goto update_sectors;
897897
}
898898

@@ -947,7 +947,7 @@ static int _badblocks_set(struct badblocks *bb, sector_t s, int sectors,
947947
len = insert_at(bb, prev + 1, &bad);
948948
bb->count++;
949949
added++;
950-
hint = prev + 1;
950+
hint = ++prev;
951951

952952
update_sectors:
953953
s += len;

0 commit comments

Comments
 (0)