From: Coly Li Date: Sun, 9 Mar 2025 16:05:56 +0000 (-0400) Subject: badblocks: Fix a nonsense WARN_ON() which checks whether a u64 variable < 0 X-Git-Tag: v6.15-rc1~166^2~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7e76336e14de9a2b67af96012ddd46c5676cf340;p=thirdparty%2Flinux.git badblocks: Fix a nonsense WARN_ON() which checks whether a u64 variable < 0 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 Signed-off-by: Coly Li Reviewed-by: Yu Kuai Link: https://lore.kernel.org/r/20250309160556.42854-1-colyli@kernel.org Signed-off-by: Jens Axboe --- diff --git a/block/badblocks.c b/block/badblocks.c index 673ef068423a6..ece64e76fe8ff 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -1242,14 +1242,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)