Commit 8261bd48 authored by Wenwei Tao's avatar Wenwei Tao Committed by Jens Axboe

lightnvm: free memory when gennvm register fails

free allocated nvm block and gennvm lun structures when
gennvm register fails, otherwise it will cause memory leak.
Signed-off-by: default avatarMatias Bjørling <m@bjorling.me>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent c4699e70
...@@ -207,6 +207,14 @@ static int gennvm_blocks_init(struct nvm_dev *dev, struct gen_nvm *gn) ...@@ -207,6 +207,14 @@ static int gennvm_blocks_init(struct nvm_dev *dev, struct gen_nvm *gn)
return 0; return 0;
} }
static void gennvm_free(struct nvm_dev *dev)
{
gennvm_blocks_free(dev);
gennvm_luns_free(dev);
kfree(dev->mp);
dev->mp = NULL;
}
static int gennvm_register(struct nvm_dev *dev) static int gennvm_register(struct nvm_dev *dev)
{ {
struct gen_nvm *gn; struct gen_nvm *gn;
...@@ -234,16 +242,13 @@ static int gennvm_register(struct nvm_dev *dev) ...@@ -234,16 +242,13 @@ static int gennvm_register(struct nvm_dev *dev)
return 1; return 1;
err: err:
kfree(gn); gennvm_free(dev);
return ret; return ret;
} }
static void gennvm_unregister(struct nvm_dev *dev) static void gennvm_unregister(struct nvm_dev *dev)
{ {
gennvm_blocks_free(dev); gennvm_free(dev);
gennvm_luns_free(dev);
kfree(dev->mp);
dev->mp = NULL;
} }
static struct nvm_block *gennvm_get_blk(struct nvm_dev *dev, static struct nvm_block *gennvm_get_blk(struct nvm_dev *dev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment