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 <ira.weiny@intel.com> Signed-off-by: Coly Li <colyli@suse.de> Link: https://lore.kernel.org/nvdimm/3035e75a-9be0-4bc3-8d4a-6e52c207f277@leemhuis.info/ Cc: Dan Williams <dan.j.williams@intel.com> Cc: Geliang Tang <geliang.tang@suse.com> Cc: Hannes Reinecke <hare@suse.de> Cc: Jens Axboe <axboe@kernel.dk> Cc: NeilBrown <neilb@suse.de> Cc: Vishal L Verma <vishal.l.verma@intel.com> Cc: Xiao Ni <xni@redhat.com> Link: https://lore.kernel.org/r/20231224002820.20234-1-colyli@suse.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 13d822b commit 146e843

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

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)