Skip to content

Commit 146e843

Browse files
Coly Liaxboe
authored andcommitted
badblocks: avoid checking invalid range in badblocks_check()
If prev_badblocks() returns '-1', it means no valid badblocks record before the checking range. It doesn't make sense to check whether the input checking range is overlapped with the non-existed invalid front range. This patch checkes whether 'prev >= 0' is true before calling overlap_front(), to void such invalid operations. Fixes: 3ea3354 ("badblocks: improve badblocks_check() for multiple ranges handling") Reported-and-tested-by: Ira Weiny <[email protected]> Signed-off-by: Coly Li <[email protected]> Link: https://lore.kernel.org/nvdimm/[email protected]/ Cc: Dan Williams <[email protected]> Cc: Geliang Tang <[email protected]> Cc: Hannes Reinecke <[email protected]> Cc: Jens Axboe <[email protected]> Cc: NeilBrown <[email protected]> Cc: Vishal L Verma <[email protected]> Cc: Xiao Ni <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 13d822b commit 146e843

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

block/badblocks.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,12 +1312,14 @@ static int _badblocks_check(struct badblocks *bb, sector_t s, int sectors,
13121312
prev = prev_badblocks(bb, &bad, hint);
13131313

13141314
/* start after all badblocks */
1315-
if ((prev + 1) >= bb->count && !overlap_front(bb, prev, &bad)) {
1315+
if ((prev >= 0) &&
1316+
((prev + 1) >= bb->count) && !overlap_front(bb, prev, &bad)) {
13161317
len = sectors;
13171318
goto update_sectors;
13181319
}
13191320

1320-
if (overlap_front(bb, prev, &bad)) {
1321+
/* Overlapped with front badblocks record */
1322+
if ((prev >= 0) && overlap_front(bb, prev, &bad)) {
13211323
if (BB_ACK(p[prev]))
13221324
acked_badblocks++;
13231325
else

0 commit comments

Comments
 (0)