diff mbox series

[04/10] block/badblocks: fix the bug of reverse order

Message ID 20230428085020.2283981-5-linan666@huaweicloud.com (mailing list archive)
State New, archived
Headers show
Series block/badblocks: fix badblocks setting error | expand

Commit Message

Li Nan April 28, 2023, 8:50 a.m. UTC
From: Li Nan <linan122@huawei.com>

Order of badblocks will be reversed if we set a large area at once. 'hi'
remains unchanged while adding continuous badblocks is wrong, the next
setting is greater than 'hi', it should be added to the next position.
Let 'hi' +1 each cycle.

  # echo 0 2048 > bad_blocks
  # cat bad_blocks
    1536 512
    1024 512
    512 512
    0 512

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 mbox series

Patch

diff --git a/block/badblocks.c b/block/badblocks.c
index f34351b59414..11e3a3ae2c72 100644
--- a/block/badblocks.c
+++ b/block/badblocks.c
@@ -320,6 +320,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;
 		}
 	}