lightnvm: pblk: add lock protection to list operations
authorHua Su <suhua.tanke@gmail.com>
Tue, 11 Dec 2018 19:16:18 +0000 (20:16 +0100)
committerJens Axboe <axboe@kernel.dk>
Tue, 11 Dec 2018 19:22:34 +0000 (12:22 -0700)
Protect the list_add on the pblk_line_init_bb() error
path in case this code is used for some other purpose
in the future.

Signed-off-by: Hua Su <suhua.tanke@gmail.com>
Reviewed-by: Javier González <javier@cnexlabs.com>
Signed-off-by: Matias Bjørling <mb@lightnvm.io>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/lightnvm/pblk-core.c

index 6581c35f51ee89882695840e7a394934c145f772..44c5dc0469122d4aee54b924e432e049a86b6bc5 100644 (file)
@@ -1295,15 +1295,22 @@ int pblk_line_recov_alloc(struct pblk *pblk, struct pblk_line *line)
 
        ret = pblk_line_alloc_bitmaps(pblk, line);
        if (ret)
-               return ret;
+               goto fail;
 
        if (!pblk_line_init_bb(pblk, line, 0)) {
-               list_add(&line->list, &l_mg->free_list);
-               return -EINTR;
+               ret = -EINTR;
+               goto fail;
        }
 
        pblk_rl_free_lines_dec(&pblk->rl, line, true);
        return 0;
+
+fail:
+       spin_lock(&l_mg->free_lock);
+       list_add(&line->list, &l_mg->free_list);
+       spin_unlock(&l_mg->free_lock);
+
+       return ret;
 }
 
 void pblk_line_recov_close(struct pblk *pblk, struct pblk_line *line)