From: sashiko-bot@kernel.org
To: zhanghao <zh_exit@163.com>
Cc: linux-raid@vger.kernel.org, yukuai@fygo.io
Subject: Re: [PATCH] md/raid5: fix inverted condition in rdev_set_badblocks call
Date: Sat, 17 Oct 2026 07:49:11 +0000 [thread overview]
Message-ID: <sashiko-outbox-175372@kernel.org> (raw)
In-Reply-To: <20261017074343.59513-1-zh_exit@163.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] md/raid5: missing md_error() in raid5_end_read_request() when not setting badblocks
--
commit 3b60bf439402ec230798b452291264b5f0962518
Author: zhanghao <zh_exit@163.com>
md/raid5: fix inverted condition in rdev_set_badblocks call
This commit fixes an inverted condition in raid5_end_read_request() so that
rdev_set_badblocks() is called when set_bad and In_sync are set.
> diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
> index b91545ce090de..d5e226c6cc68a 100644
> --- a/drivers/md/raid5.c
> +++ b/drivers/md/raid5.c
> @@ -2834,7 +2834,7 @@ static void raid5_end_read_request(struct bio * bi)
> else {
> clear_bit(R5_ReadError, &sh->dev[i].flags);
> clear_bit(R5_ReWrite, &sh->dev[i].flags);
> - if (!(set_bad && test_bit(In_sync, &rdev->flags)))
> + if (set_bad && test_bit(In_sync, &rdev->flags))
> rdev_set_badblocks(rdev, sh->sector,
> RAID5_STRIPE_SECTORS(conf), 0);
> }
[Severity: High]
Does this need an else branch calling md_error(conf->mddev, rdev)?
Prior to commit fd4d44c14ff6 ("md: mark rdev Faulty when badblocks setting
fails"), the non-retry branch in raid5_end_read_request() had:
if (!(set_bad && test_bit(In_sync, &rdev->flags) &&
rdev_set_badblocks(rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), 0)))
md_error(conf->mddev, rdev);
That called md_error() both when rdev_set_badblocks() failed and when
!(set_bad && test_bit(In_sync, &rdev->flags)) was true. Since
rdev_set_badblocks() only calls md_error() when it is actually invoked and
badblocks_set() fails, omitting the else branch leaves the cases where
!(set_bad && test_bit(In_sync, &rdev->flags)) holds without calling
md_error().
Specifically, in raid5_end_read_request(), retry == 0 and
!(set_bad && test_bit(In_sync, &rdev->flags)) occurs when:
1. A read error happens on a replacement device (R5_ReadRepl is set, leaving
set_bad = 0 and retry = 0).
2. Consecutive read errors exceed max_nr_stripes (atomic_read(&rdev->read_errors)
> max_nr_stripes, which logs "Too many read errors, failing device" with
set_bad = 0 and retry = 0).
3. An uncorrectable read error or failed R5_ReWrite sets set_bad = 1 on a
device where In_sync is not set.
In these paths, R5_ReadError and R5_ReWrite are cleared while R5_UPTODATE
remains clear, and neither Faulty nor a badblock is recorded on rdev. When
handle_stripe() -> analyse_stripe() runs again, will it continue to treat
rdev as healthy and re-issue the failing read in an infinite loop?
Should this be:
if (set_bad && test_bit(In_sync, &rdev->flags))
rdev_set_badblocks(rdev, sh->sector,
RAID5_STRIPE_SECTORS(conf), 0);
else
md_error(conf->mddev, rdev);
instead?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261017074343.59513-1-zh_exit@163.com?part=1
next prev parent reply other threads:[~2026-10-17 7:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-17 7:43 [PATCH] md/raid5: fix inverted condition in rdev_set_badblocks call zhanghao
2026-10-17 7:49 ` sashiko-bot [this message]
2026-10-17 8:37 ` [PATCH v2] " zhanghao
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=sashiko-outbox-175372@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=yukuai@fygo.io \
--cc=zh_exit@163.com \
/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