Commit 008b7443 authored by Matias Bjørling's avatar Matias Bjørling Committed by Jens Axboe

lightnvm: prevent gennvm module unload on use

After the gennvm module has been initialized. It might be attached to
one or several devices. In that case, the module is in use. Make sure
that it can not be unloaded.
Signed-off-by: default avatarMatias Bjørling <m@bjorling.me>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent 762796bc
...@@ -219,6 +219,9 @@ static int gennvm_register(struct nvm_dev *dev) ...@@ -219,6 +219,9 @@ static int gennvm_register(struct nvm_dev *dev)
struct gen_nvm *gn; struct gen_nvm *gn;
int ret; int ret;
if (!try_module_get(THIS_MODULE))
return -ENODEV;
gn = kzalloc(sizeof(struct gen_nvm), GFP_KERNEL); gn = kzalloc(sizeof(struct gen_nvm), GFP_KERNEL);
if (!gn) if (!gn)
return -ENOMEM; return -ENOMEM;
...@@ -242,12 +245,14 @@ static int gennvm_register(struct nvm_dev *dev) ...@@ -242,12 +245,14 @@ static int gennvm_register(struct nvm_dev *dev)
return 1; return 1;
err: err:
gennvm_free(dev); gennvm_free(dev);
module_put(THIS_MODULE);
return ret; return ret;
} }
static void gennvm_unregister(struct nvm_dev *dev) static void gennvm_unregister(struct nvm_dev *dev)
{ {
gennvm_free(dev); gennvm_free(dev);
module_put(THIS_MODULE);
} }
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