Skip to content

Commit 75ae2a3

Browse files
Coly Ligregkh
authored andcommitted
badblocks: Fix a nonsense WARN_ON() which checks whether a u64 variable < 0
[ Upstream commit 7e76336 ] 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>
1 parent 7bd6061 commit 75ae2a3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

block/badblocks.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,14 +1349,15 @@ static int _badblocks_check(struct badblocks *bb, sector_t s, int sectors,
13491349
len = sectors;
13501350

13511351
update_sectors:
1352+
/* This situation should never happen */
1353+
WARN_ON(sectors < len);
1354+
13521355
s += len;
13531356
sectors -= len;
13541357

13551358
if (sectors > 0)
13561359
goto re_check;
13571360

1358-
WARN_ON(sectors < 0);
1359-
13601361
if (unacked_badblocks > 0)
13611362
rv = -1;
13621363
else if (acked_badblocks > 0)

0 commit comments

Comments
 (0)