summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColy Li <colyli@kernel.org>2025-03-09 12:05:56 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-05-29 11:02:24 +0200
commit75ae2a35536111c557952f809323e5fe1674aa09 (patch)
tree4074cae67b5de8ce42109eb3e91a725f1ddb02bd
parent7bd6061b0a44b924d7c3e2525662c1bb0c6ce400 (diff)
badblocks: Fix a nonsense WARN_ON() which checks whether a u64 variable < 0
[ Upstream commit 7e76336e14de9a2b67af96012ddd46c5676cf340 ] 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> Reviewed-by: Yu Kuai <yukuai3@huawei.com> Link: https://lore.kernel.org/r/20250309160556.42854-1-colyli@kernel.org Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--block/badblocks.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/block/badblocks.c b/block/badblocks.c
index db4ec8b9b2a8..a9709771a101 100644
--- a/block/badblocks.c
+++ b/block/badblocks.c
@@ -1349,14 +1349,15 @@ re_check:
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)