lkml.org 
[lkml]   [2023]   [Jun]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v4 4/4] block/badblocks: fix the bug of reverse order
Date
From: Li Nan <linan122@huawei.com>

Badblocks are arranged from small to large, but order of badblocks will
be reversed if we set a large area at once as below:
$ echo 0 2048 > bad_blocks
$ cat bad_blocks
1536 512
1024 512
512 512
0 512

Actually, it should be:
$ echo 0 2048 > bad_blocks
$ cat bad_blocks
0 512
512 512
1024 512
1536 512

'hi' remains unchanged while setting continuous badblocks is wrong, the
next badblocks is greater than 'p[hi]', and it should be added to
'p[hi+1]'. Let 'hi' +1 each cycle.

(0 512) 0 512
|_________| |_________|
p[hi] p[hi]

(512 512) (0 512) fix 0 512 1024
|_________|_________| ===> |_________|_________|
p[hi] p[hi+1]

(1024 512)(512 512) (0 512) 0 512 1024 1536
|_________|_________|_________| |_________|_________|_________|
p[hi] p[hi+2]

...

Fixes: 9e0e252a048b ("badblocks: Add core badblock management code")
Signed-off-by: Li Nan <linan122@huawei.com>
---
block/badblocks.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/block/badblocks.c b/block/badblocks.c
index c1745b76d8f1..b79d37a4bf0e 100644
--- a/block/badblocks.c
+++ b/block/badblocks.c
@@ -301,6 +301,7 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
p[hi] = BB_MAKE(s, this_sectors, acknowledged);
sectors -= this_sectors;
s += this_sectors;
+ hi++;
changed = true;
}
}
--
2.39.2
\
 
 \ /
  Last update: 2023-06-26 10:10    [W:0.095 / U:0.172 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site