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: 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: aa511ff8218b ("badblocks: switch to the improved badblock handling code")
Signed-off-by: Li Nan <linan122@huawei.com>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/20250227075507.151331-9-zhengqixing@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Li Nan and committed by
Jens Axboe
9ec65dec 3a23d05f

+2 -2
+2 -2
block/badblocks.c
··· 892 892 len = insert_at(bb, 0, &bad); 893 893 bb->count++; 894 894 added++; 895 - hint = 0; 895 + hint = ++prev; 896 896 goto update_sectors; 897 897 } 898 898 ··· 947 947 len = insert_at(bb, prev + 1, &bad); 948 948 bb->count++; 949 949 added++; 950 - hint = prev + 1; 950 + hint = ++prev; 951 951 952 952 update_sectors: 953 953 s += len;