Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1284844

[PATCH 8/9] lightnvm: prevent gennvm module unload on use

From Matias Bjørling <m@bjorling.me>
Newsgroups linux.kernel
Subject [PATCH 8/9] lightnvm: prevent gennvm module unload on use
Date 2015-12-06 11:30 +0100
Message-ID <qCEJQ-5Hj-23@gated-at.bofh.it> (permalink)
References <qCEJP-5Hj-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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>
---
 drivers/lightnvm/gennvm.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/lightnvm/gennvm.c b/drivers/lightnvm/gennvm.c
index 52b513a..f434e89 100644
--- a/drivers/lightnvm/gennvm.c
+++ b/drivers/lightnvm/gennvm.c
@@ -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;
@@ -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,
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/9] Fixes for LightNVM Matias Bjørling <m@bjorling.me> - 2015-12-06 11:30 +0100
  [PATCH 5/9] lightnvm: comments on constants Matias Bjørling <m@bjorling.me> - 2015-12-06 11:30 +0100
  [PATCH 7/9] lightnvm: fix media mgr registration Matias Bjørling <m@bjorling.me> - 2015-12-06 11:30 +0100
  [PATCH 8/9] lightnvm: prevent gennvm module unload on use Matias Bjørling <m@bjorling.me> - 2015-12-06 11:30 +0100
  Re: [PATCH 0/9] Fixes for LightNVM Jens Axboe <axboe@fb.com> - 2015-12-07 17:20 +0100
    Re: [PATCH 0/9] Fixes for LightNVM Matias Bjørling <m@bjorling.me> - 2015-12-07 19:00 +0100

csiph-web