[PATCH 05/10] block/badblocks: fix ack set fail in badblocks_set

From: linan666
Date: Fri Apr 28 2023 - 04:52:23 EST


From: Li Nan <linan122@xxxxxxxxxx>

If we try to set ack for a BB_MAX_LEN badblocks, it will return
0(success) but did not set ack at all in badblocks_set(). Check ack
before setting to fix it, and do not set badblocks already exist.

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

diff --git a/block/badblocks.c b/block/badblocks.c
index 11e3a3ae2c72..c11eb869f2f3 100644
--- a/block/badblocks.c
+++ b/block/badblocks.c
@@ -219,18 +219,18 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
if (e < s + sectors)
e = s + sectors;
if (e - a <= BB_MAX_LEN) {
- p[lo] = BB_MAKE(a, e-a, ack);
s = e;
} else {
/* does not all fit in one range,
* make p[lo] maximal
*/
- if (BB_LEN(p[lo]) != BB_MAX_LEN)
- p[lo] = BB_MAKE(a, BB_MAX_LEN, ack);
s = a + BB_MAX_LEN;
}
+ if (s - a != BB_LEN(p[lo]) || ack != BB_ACK(p[lo])) {
+ p[lo] = BB_MAKE(a, s - a, ack);
+ changed = true;
+ }
sectors = e - s;
- changed = true;
}
}
if (sectors && hi < bb->count) {
--
2.31.1