From: colyli@fnnas.com
To: linux-raid@vger.kernel.org
Cc: Coly Li <colyli@fnnas.com>
Subject: [PATCH] md: don't add empty badblocks record table in super_1_load()
Date: Mon, 6 Oct 2025 00:21:59 +0800 [thread overview]
Message-ID: <20251005162159.25864-1-colyli@fnnas.com> (raw)
From: Coly Li <colyli@fnnas.com>
In super_1_load() when badblocks table is loaded from component disk,
current code adds all records including empty ones into in-memory
badblocks table. Because empty record's sectors count is 0, calling
badblocks_set() with parameter sectors=0 will return -EINVAL. This isn't
expected behavior and adding a correct component disk into the array
will incorrectly fail.
This patch fixes the issue by checking the badblock record before call-
ing badblocks_set(). If this badblock record is empty (bb == 0), then
skip this one and continue to try next bad record.
Signed-off-by: Coly Li <colyli@fnnas.com>
---
drivers/md/md.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 41c476b40c7a..b4b5799b4f9f 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1873,9 +1873,14 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
bbp = (__le64 *)page_address(rdev->bb_page);
rdev->badblocks.shift = sb->bblog_shift;
for (i = 0 ; i < (sectors << (9-3)) ; i++, bbp++) {
- u64 bb = le64_to_cpu(*bbp);
- int count = bb & (0x3ff);
- u64 sector = bb >> 10;
+ u64 bb, sector;
+ int count;
+
+ bb = le64_to_cpu(*bbp);
+ if (bb == 0)
+ continue;
+ count = bb & (0x3ff);
+ sector = bb >> 10;
sector <<= sb->bblog_shift;
count <<= sb->bblog_shift;
if (bb + 1 == 0)
--
2.47.3
next reply other threads:[~2025-10-05 16:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-05 16:21 colyli [this message]
2025-10-05 17:35 ` [PATCH] md: don't add empty badblocks record table in super_1_load() Paul Menzel
2025-10-06 1:06 ` Coly Li
2025-10-06 2:08 ` Yu Kuai
2025-10-06 2:47 ` Coly Li
2025-10-09 2:18 ` Li Nan
2025-10-09 2:59 ` Coly Li
2025-10-09 3:54 ` Li Nan
2025-10-09 4:20 ` Coly Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251005162159.25864-1-colyli@fnnas.com \
--to=colyli@fnnas.com \
--cc=linux-raid@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox