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


Groups > linux.kernel > #1276576

[PATCH] lightnvm: missing nvm_lock acquire

From Wenwei Tao <ww.tao0320@gmail.com>
Newsgroups linux.kernel
Subject [PATCH] lightnvm: missing nvm_lock acquire
Date 2015-11-24 16:30 +0100
Message-ID <qynHD-1tb-105@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


To avoid race conditions, traverse dev, media manager,
and targeet lists and also register, unregister entries
to/from them, should be always under the nvm_lock control.

Signed-off-by: Wenwei Tao <ww.tao0320@gmail.com>
---
 drivers/lightnvm/core.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index f659e60..39aec3a 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -333,19 +333,19 @@ EXPORT_SYMBOL(nvm_register);
 
 void nvm_unregister(char *disk_name)
 {
+	down_write(&nvm_lock);
 	struct nvm_dev *dev = nvm_find_nvm_dev(disk_name);
 
 	if (!dev) {
 		pr_err("nvm: could not find device %s to unregister\n",
 								disk_name);
+		up_write(&nvm_lock);
 		return;
 	}
 
-	nvm_exit(dev);
-
-	down_write(&nvm_lock);
 	list_del(&dev->devices);
 	up_write(&nvm_lock);
+	nvm_exit(dev);
 }
 EXPORT_SYMBOL(nvm_unregister);
 
@@ -365,12 +365,15 @@ static int nvm_create_target(struct nvm_dev *dev,
 	void *targetdata;
 	int ret = 0;
 
+	down_write(&nvm_lock);
 	if (!dev->mt) {
 		/* register with device with a supported NVM manager */
 		list_for_each_entry(mt, &nvm_mgrs, list) {
 			ret = mt->register_mgr(dev);
-			if (ret < 0)
+			if (ret < 0) {
+				up_write(&nvm_lock);
 				return ret; /* initialization failed */
+			}
 			if (ret > 0) {
 				dev->mt = mt;
 				break; /* successfully initialized */
@@ -379,6 +382,7 @@ static int nvm_create_target(struct nvm_dev *dev,
 
 		if (!ret) {
 			pr_info("nvm: no compatible nvm manager found.\n");
+			up_write(&nvm_lock);
 			return -ENODEV;
 		}
 	}
@@ -386,10 +390,10 @@ static int nvm_create_target(struct nvm_dev *dev,
 	tt = nvm_find_target_type(create->tgttype);
 	if (!tt) {
 		pr_err("nvm: target type %s not found\n", create->tgttype);
+		up_write(&nvm_lock);
 		return -EINVAL;
 	}
 
-	down_write(&nvm_lock);
 	list_for_each_entry(t, &dev->online_targets, list) {
 		if (!strcmp(create->tgtname, t->disk->disk_name)) {
 			pr_err("nvm: target name already exists.\n");
@@ -472,8 +476,9 @@ static int __nvm_configure_create(struct nvm_ioctl_create *create)
 {
 	struct nvm_dev *dev;
 	struct nvm_ioctl_create_simple *s;
-
+	down_write(&nvm_lock);
 	dev = nvm_find_nvm_dev(create->dev);
+	up_write(&nvm_lock);
 	if (!dev) {
 		pr_err("nvm: device not found\n");
 		return -EINVAL;
@@ -532,7 +537,9 @@ static int nvm_configure_show(const char *val)
 		return -EINVAL;
 	}
 
+	down_write(&nvm_lock);
 	dev = nvm_find_nvm_dev(devname);
+	up_write(&nvm_lock);
 	if (!dev) {
 		pr_err("nvm: device not found\n");
 		return -EINVAL;
-- 
1.9.1

--
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 | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] lightnvm: missing nvm_lock acquire Wenwei Tao <ww.tao0320@gmail.com> - 2015-11-24 16:30 +0100
  Re: [PATCH] lightnvm: missing nvm_lock acquire kbuild test robot <lkp@intel.com> - 2015-11-24 16:40 +0100
  Re: [PATCH] lightnvm: missing nvm_lock acquire Matias <mb@lightnvm.io> - 2015-11-24 19:40 +0100
    Re: [PATCH] lightnvm: missing nvm_lock acquire Wenwei Tao <ww.tao0320@gmail.com> - 2015-11-25 10:00 +0100
      Re: [PATCH] lightnvm: missing nvm_lock acquire Matias Bjørling <mb@lightnvm.io> - 2015-11-25 12:30 +0100
      Re: [PATCH] lightnvm: missing nvm_lock acquire Matias Bjørling <mb@lightnvm.io> - 2015-11-25 12:40 +0100
        Re: [PATCH] lightnvm: missing nvm_lock acquire Wenwei Tao <ww.tao0320@gmail.com> - 2015-11-25 14:20 +0100
          Re: [PATCH] lightnvm: missing nvm_lock acquire Wenwei Tao <ww.tao0320@gmail.com> - 2015-11-25 15:20 +0100
            Re: [PATCH] lightnvm: missing nvm_lock acquire Matias Bjørling <mb@lightnvm.io> - 2015-11-25 15:30 +0100

csiph-web