[PATCH 1/4] badblocks: goto out if find any unacked badblocks in _badblocks_check()

From: linan666
Date: Sat Dec 23 2023 - 01:40:07 EST


From: Li Nan <linan122@xxxxxxxxxx>

In _badblocks_check(), after finding any unacked badblocks, the return
value, 'first_bad' and 'bad_sectors' will not be changed anymore, and
there is no need to check other ranges. So goto out directly after
finding unacked badblocks.

Signed-off-by: Li Nan <linan122@xxxxxxxxxx>
---
block/badblocks.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/block/badblocks.c b/block/badblocks.c
index fc92d4e18aa3..ebf17a54851a 100644
--- a/block/badblocks.c
+++ b/block/badblocks.c
@@ -1274,7 +1274,7 @@ static int _badblocks_clear(struct badblocks *bb, sector_t s, int sectors)
static int _badblocks_check(struct badblocks *bb, sector_t s, int sectors,
sector_t *first_bad, int *bad_sectors)
{
- int unacked_badblocks, acked_badblocks;
+ int acked_badblocks;
int prev = -1, hint = -1, set = 0;
struct badblocks_context bad;
unsigned int seq;
@@ -1297,7 +1297,6 @@ static int _badblocks_check(struct badblocks *bb, sector_t s, int sectors,
seq = read_seqbegin(&bb->lock);

p = bb->page;
- unacked_badblocks = 0;
acked_badblocks = 0;

re_check:
@@ -1318,21 +1317,24 @@ static int _badblocks_check(struct badblocks *bb, sector_t s, int sectors,
}

if (overlap_front(bb, prev, &bad)) {
- if (BB_ACK(p[prev]))
+ if (set == 0) {
+ *first_bad = BB_OFFSET(p[prev]);
+ *bad_sectors = BB_LEN(p[prev]);
+ set = 1;
+ }
+
+ if (BB_ACK(p[prev])) {
acked_badblocks++;
- else
- unacked_badblocks++;
+ } else {
+ rv = -1;
+ goto out;
+ }

if (BB_END(p[prev]) >= (s + sectors))
len = sectors;
else
len = BB_END(p[prev]) - s;

- if (set == 0) {
- *first_bad = BB_OFFSET(p[prev]);
- *bad_sectors = BB_LEN(p[prev]);
- set = 1;
- }
goto update_sectors;
}

@@ -1355,13 +1357,12 @@ static int _badblocks_check(struct badblocks *bb, sector_t s, int sectors,

WARN_ON(sectors < 0);

- if (unacked_badblocks > 0)
- rv = -1;
- else if (acked_badblocks > 0)
+ if (acked_badblocks > 0)
rv = 1;
else
rv = 0;

+out:
if (read_seqretry(&bb->lock, seq))
goto retry;

--
2.39.2