]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
lightnvm: refactor spin_unlock in gennvm_get_blk
authorWenwei Tao <ww.tao0320@gmail.com>
Sun, 6 Dec 2015 10:25:45 +0000 (11:25 +0100)
committerJens Axboe <axboe@fb.com>
Mon, 7 Dec 2015 16:14:19 +0000 (09:14 -0700)
The spin_unlock is duplicated multiple times. Jump to a single unlock
to improve the code flow.

Signed-off-by: Wenwei Tao <ww.tao0320@gmail.com>
Signed-off-by: Matias Bjørling <m@bjorling.me>
Signed-off-by: Jens Axboe <axboe@fb.com>
drivers/lightnvm/gennvm.c

index 35dde84b71e97a6e530c2058ca0b68cf574424b2..ce6025487a5cb3e2bd8a0190667e17b22a7219a6 100644 (file)
@@ -262,14 +262,11 @@ static struct nvm_block *gennvm_get_blk(struct nvm_dev *dev,
        if (list_empty(&lun->free_list)) {
                pr_err_ratelimited("gennvm: lun %u have no free pages available",
                                                                lun->vlun.id);
-               spin_unlock(&vlun->lock);
                goto out;
        }
 
-       while (!is_gc && lun->vlun.nr_free_blocks < lun->reserved_blocks) {
-               spin_unlock(&vlun->lock);
+       if (!is_gc && lun->vlun.nr_free_blocks < lun->reserved_blocks)
                goto out;
-       }
 
        blk = list_first_entry(&lun->free_list, struct nvm_block, list);
        list_move_tail(&blk->list, &lun->used_list);
@@ -278,8 +275,8 @@ static struct nvm_block *gennvm_get_blk(struct nvm_dev *dev,
        lun->vlun.nr_free_blocks--;
        lun->vlun.nr_inuse_blocks++;
 
-       spin_unlock(&vlun->lock);
 out:
+       spin_unlock(&vlun->lock);
        return blk;
 }