lightnvm: pblk: ensure right bad block calculation
authorJavier González <javier@cnexlabs.com>
Fri, 13 Oct 2017 12:46:27 +0000 (14:46 +0200)
committerJens Axboe <axboe@kernel.dk>
Fri, 13 Oct 2017 14:34:57 +0000 (08:34 -0600)
Make sure that the variable controlling block threshold for allocating
extra metadata sectors in case of a line with bad blocks does not get a
negative value. Otherwise, the line will be marked as corrupted and
wasted.

Signed-off-by: Javier González <javier@cnexlabs.com>
Signed-off-by: Matias Bjørling <m@bjorling.me>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/lightnvm/pblk-init.c

index 3c37491860537f11c397dda2dc5932a7231c7d6d..c7239c41ba40f55bdad0d00a156375672d993b5b 100644 (file)
@@ -710,7 +710,7 @@ add_emeta_page:
                goto add_emeta_page;
        }
 
-       lm->emeta_bb = geo->nr_luns - i;
+       lm->emeta_bb = geo->nr_luns > i ? geo->nr_luns - i : 0;
 
        lm->min_blk_line = 1;
        if (geo->nr_luns > 1)