Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <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>

authored by

Coly Li and committed by
Jens Axboe
7e76336e fc0e982b

+3 -2
+3 -2
block/badblocks.c
··· 1242 1242 len = sectors; 1243 1243 1244 1244 update_sectors: 1245 + /* This situation should never happen */ 1246 + WARN_ON(sectors < len); 1247 + 1245 1248 s += len; 1246 1249 sectors -= len; 1247 1250 1248 1251 if (sectors > 0) 1249 1252 goto re_check; 1250 - 1251 - WARN_ON(sectors < 0); 1252 1253 1253 1254 if (unacked_badblocks > 0) 1254 1255 rv = -1;