diff mbox series

[2/4] badblocks: optimize _badblocks_check()

Message ID 20231223063728.3229446-3-linan666@huaweicloud.com (mailing list archive)
State New, archived
Headers show
Series badblocks: bugfix and cleanup of _badblocks_check() | expand

Commit Message

Li Nan Dec. 23, 2023, 6:37 a.m. UTC
From: Li Nan <linan122@huawei.com>

Check badblocks_empty earlier, and goto out if check range starts after
all badblocks or badblocks is empty since no badblocks intersect with
check range.

Clean up redundant check '(prev + 1) < bb->count'. If it is true, it
will enter the earlier branch.

Signed-off-by: Li Nan <linan122@huawei.com>
---
 block/badblocks.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/block/badblocks.c b/block/badblocks.c
index ebf17a54851a..054d05b93641 100644
--- a/block/badblocks.c
+++ b/block/badblocks.c
@@ -1296,6 +1296,11 @@  static int _badblocks_check(struct badblocks *bb, sector_t s, int sectors,
 retry:
 	seq = read_seqbegin(&bb->lock);
 
+	if (badblocks_empty(bb)) {
+		len = sectors;
+		goto out;
+	}
+
 	p = bb->page;
 	acked_badblocks = 0;
 
@@ -1303,17 +1308,12 @@  static int _badblocks_check(struct badblocks *bb, sector_t s, int sectors,
 	bad.start = s;
 	bad.len = sectors;
 
-	if (badblocks_empty(bb)) {
-		len = sectors;
-		goto update_sectors;
-	}
-
 	prev = prev_badblocks(bb, &bad, hint);
 
 	/* start after all badblocks */
 	if ((prev + 1) >= bb->count && !overlap_front(bb, prev, &bad)) {
 		len = sectors;
-		goto update_sectors;
+		goto out;
 	}
 
 	if (overlap_front(bb, prev, &bad)) {
@@ -1339,7 +1339,7 @@  static int _badblocks_check(struct badblocks *bb, sector_t s, int sectors,
 	}
 
 	/* Not front overlap, but behind overlap */
-	if ((prev + 1) < bb->count && overlap_behind(bb, &bad, prev + 1)) {
+	if (overlap_behind(bb, &bad, prev + 1)) {
 		len = BB_OFFSET(p[prev + 1]) - bad.start;
 		hint = prev + 1;
 		goto update_sectors;