public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: colyli@kernel.org
To: linux-block@vger.kernel.org
Cc: axboe@kernel.dk, Coly Li <colyli@kernel.org>,
	Dan Carpenter <dan.carpenter@linaro.org>
Subject: [PATCH] badblocks: Fix a nonsense WARN_ON() which checks whether a u64 variable < 0
Date: Sun,  9 Mar 2025 12:05:56 -0400	[thread overview]
Message-ID: <20250309160556.42854-1-colyli@kernel.org> (raw)

From: Coly Li <colyli@kernel.org>

In _badblocks_check(), there are lines of code like this,
1246         sectors -= len;
[snipped]
1251         WARN_ON(sectors < 0);

The WARN_ON() at line 1257 doesn't make sense because sectors is
unsigned long long type and never to be <0.

Fix it by checking directly checking whether sectors is less than len.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Coly Li <colyli@kernel.org>
---
 block/badblocks.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/block/badblocks.c b/block/badblocks.c
index 673ef068423a..ece64e76fe8f 100644
--- a/block/badblocks.c
+++ b/block/badblocks.c
@@ -1242,14 +1242,15 @@ static int _badblocks_check(struct badblocks *bb, sector_t s, sector_t sectors,
 	len = sectors;
 
 update_sectors:
+	/* This situation should never happen */
+	WARN_ON(sectors < len);
+
 	s += len;
 	sectors -= len;
 
 	if (sectors > 0)
 		goto re_check;
 
-	WARN_ON(sectors < 0);
-
 	if (unacked_badblocks > 0)
 		rv = -1;
 	else if (acked_badblocks > 0)
-- 
2.47.2


             reply	other threads:[~2025-03-09 16:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-09 16:05 colyli [this message]
2025-03-09 16:12 ` Fwd: [PATCH] badblocks: Fix a nonsense WARN_ON() which checks whether a u64 variable < 0 Coly Li
2025-03-10 13:42   ` Jens Axboe
2025-03-10 13:44     ` Coly Li
2025-03-10 13:49       ` Jens Axboe
2025-03-10 13:50         ` Coly Li
2025-03-10  2:06 ` Yu Kuai
2025-03-10 13:50 ` Jens Axboe

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=20250309160556.42854-1-colyli@kernel.org \
    --to=colyli@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=dan.carpenter@linaro.org \
    --cc=linux-block@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