Skip to content

Commit

Permalink
lightnvm: prevent gennvm module unload on use
Browse files Browse the repository at this point in the history
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: Matias Bjørling <m@bjorling.me>
Signed-off-by: Jens Axboe <axboe@fb.com>
  • Loading branch information
Matias Bjørling authored and Jens Axboe committed Dec 7, 2015
1 parent 762796b commit 008b744
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/lightnvm/gennvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ static int gennvm_register(struct nvm_dev *dev)
struct gen_nvm *gn;
int ret;

if (!try_module_get(THIS_MODULE))
return -ENODEV;

gn = kzalloc(sizeof(struct gen_nvm), GFP_KERNEL);
if (!gn)
return -ENOMEM;
Expand All @@ -242,12 +245,14 @@ static int gennvm_register(struct nvm_dev *dev)
return 1;
err:
gennvm_free(dev);
module_put(THIS_MODULE);
return ret;
}

static void gennvm_unregister(struct nvm_dev *dev)
{
gennvm_free(dev);
module_put(THIS_MODULE);
}

static struct nvm_block *gennvm_get_blk(struct nvm_dev *dev,
Expand Down

0 comments on commit 008b744

Please sign in to comment.