[v2,06/11] block/badblocks: fix ack set fail in badblocks_set

Message ID 20230504124828.679770-7-linan666@huaweicloud.com
State New
Headers
Series block/badblocks: fix badblocks setting error |

Commit Message

Li Nan May 4, 2023, 12:48 p.m. UTC
  From: Li Nan <linan122@huawei.com>

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@huawei.com>
---
 block/badblocks.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
  

Patch

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) {