aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/nvme/host/fabrics.c17
-rw-r--r--drivers/nvme/host/fabrics.h2
-rw-r--r--drivers/nvme/host/fc.c1
-rw-r--r--drivers/nvme/host/rdma.c1
-rw-r--r--drivers/nvme/target/loop.c1
5 files changed, 18 insertions, 4 deletions
diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
index 76b4fe6816a0..2f68befd31bf 100644
--- a/drivers/nvme/host/fabrics.c
+++ b/drivers/nvme/host/fabrics.c
@@ -492,7 +492,7 @@ EXPORT_SYMBOL_GPL(nvmf_should_reconnect);
492 */ 492 */
493int nvmf_register_transport(struct nvmf_transport_ops *ops) 493int nvmf_register_transport(struct nvmf_transport_ops *ops)
494{ 494{
495 if (!ops->create_ctrl) 495 if (!ops->create_ctrl || !ops->module)
496 return -EINVAL; 496 return -EINVAL;
497 497
498 down_write(&nvmf_transports_rwsem); 498 down_write(&nvmf_transports_rwsem);
@@ -868,32 +868,41 @@ nvmf_create_ctrl(struct device *dev, const char *buf, size_t count)
868 goto out_unlock; 868 goto out_unlock;
869 } 869 }
870 870
871 if (!try_module_get(ops->module)) {
872 ret = -EBUSY;
873 goto out_unlock;
874 }
875
871 ret = nvmf_check_required_opts(opts, ops->required_opts); 876 ret = nvmf_check_required_opts(opts, ops->required_opts);
872 if (ret) 877 if (ret)
873 goto out_unlock; 878 goto out_module_put;
874 ret = nvmf_check_allowed_opts(opts, NVMF_ALLOWED_OPTS | 879 ret = nvmf_check_allowed_opts(opts, NVMF_ALLOWED_OPTS |
875 ops->allowed_opts | ops->required_opts); 880 ops->allowed_opts | ops->required_opts);
876 if (ret) 881 if (ret)
877 goto out_unlock; 882 goto out_module_put;
878 883
879 ctrl = ops->create_ctrl(dev, opts); 884 ctrl = ops->create_ctrl(dev, opts);
880 if (IS_ERR(ctrl)) { 885 if (IS_ERR(ctrl)) {
881 ret = PTR_ERR(ctrl); 886 ret = PTR_ERR(ctrl);
882 goto out_unlock; 887 goto out_module_put;
883 } 888 }
884 889
885 if (strcmp(ctrl->subsys->subnqn, opts->subsysnqn)) { 890 if (strcmp(ctrl->subsys->subnqn, opts->subsysnqn)) {
886 dev_warn(ctrl->device, 891 dev_warn(ctrl->device,
887 "controller returned incorrect NQN: \"%s\".\n", 892 "controller returned incorrect NQN: \"%s\".\n",
888 ctrl->subsys->subnqn); 893 ctrl->subsys->subnqn);
894 module_put(ops->module);
889 up_read(&nvmf_transports_rwsem); 895 up_read(&nvmf_transports_rwsem);
890 nvme_delete_ctrl_sync(ctrl); 896 nvme_delete_ctrl_sync(ctrl);
891 return ERR_PTR(-EINVAL); 897 return ERR_PTR(-EINVAL);
892 } 898 }
893 899
900 module_put(ops->module);
894 up_read(&nvmf_transports_rwsem); 901 up_read(&nvmf_transports_rwsem);
895 return ctrl; 902 return ctrl;
896 903
904out_module_put:
905 module_put(ops->module);
897out_unlock: 906out_unlock:
898 up_read(&nvmf_transports_rwsem); 907 up_read(&nvmf_transports_rwsem);
899out_free_opts: 908out_free_opts:
diff --git a/drivers/nvme/host/fabrics.h b/drivers/nvme/host/fabrics.h
index 9ba614953607..25b19f722f5b 100644
--- a/drivers/nvme/host/fabrics.h
+++ b/drivers/nvme/host/fabrics.h
@@ -108,6 +108,7 @@ struct nvmf_ctrl_options {
108 * fabric implementation of NVMe fabrics. 108 * fabric implementation of NVMe fabrics.
109 * @entry: Used by the fabrics library to add the new 109 * @entry: Used by the fabrics library to add the new
110 * registration entry to its linked-list internal tree. 110 * registration entry to its linked-list internal tree.
111 * @module: Transport module reference
111 * @name: Name of the NVMe fabric driver implementation. 112 * @name: Name of the NVMe fabric driver implementation.
112 * @required_opts: sysfs command-line options that must be specified 113 * @required_opts: sysfs command-line options that must be specified
113 * when adding a new NVMe controller. 114 * when adding a new NVMe controller.
@@ -126,6 +127,7 @@ struct nvmf_ctrl_options {
126 */ 127 */
127struct nvmf_transport_ops { 128struct nvmf_transport_ops {
128 struct list_head entry; 129 struct list_head entry;
130 struct module *module;
129 const char *name; 131 const char *name;
130 int required_opts; 132 int required_opts;
131 int allowed_opts; 133 int allowed_opts;
diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
index 0a8af4daef89..2a7a9a75105d 100644
--- a/drivers/nvme/host/fc.c
+++ b/drivers/nvme/host/fc.c
@@ -3381,6 +3381,7 @@ nvme_fc_create_ctrl(struct device *dev, struct nvmf_ctrl_options *opts)
3381 3381
3382static struct nvmf_transport_ops nvme_fc_transport = { 3382static struct nvmf_transport_ops nvme_fc_transport = {
3383 .name = "fc", 3383 .name = "fc",
3384 .module = THIS_MODULE,
3384 .required_opts = NVMF_OPT_TRADDR | NVMF_OPT_HOST_TRADDR, 3385 .required_opts = NVMF_OPT_TRADDR | NVMF_OPT_HOST_TRADDR,
3385 .allowed_opts = NVMF_OPT_RECONNECT_DELAY | NVMF_OPT_CTRL_LOSS_TMO, 3386 .allowed_opts = NVMF_OPT_RECONNECT_DELAY | NVMF_OPT_CTRL_LOSS_TMO,
3386 .create_ctrl = nvme_fc_create_ctrl, 3387 .create_ctrl = nvme_fc_create_ctrl,
diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c
index 37af56596be6..75d6956eb380 100644
--- a/drivers/nvme/host/rdma.c
+++ b/drivers/nvme/host/rdma.c
@@ -2006,6 +2006,7 @@ out_free_ctrl:
2006 2006
2007static struct nvmf_transport_ops nvme_rdma_transport = { 2007static struct nvmf_transport_ops nvme_rdma_transport = {
2008 .name = "rdma", 2008 .name = "rdma",
2009 .module = THIS_MODULE,
2009 .required_opts = NVMF_OPT_TRADDR, 2010 .required_opts = NVMF_OPT_TRADDR,
2010 .allowed_opts = NVMF_OPT_TRSVCID | NVMF_OPT_RECONNECT_DELAY | 2011 .allowed_opts = NVMF_OPT_TRSVCID | NVMF_OPT_RECONNECT_DELAY |
2011 NVMF_OPT_HOST_TRADDR | NVMF_OPT_CTRL_LOSS_TMO, 2012 NVMF_OPT_HOST_TRADDR | NVMF_OPT_CTRL_LOSS_TMO,
diff --git a/drivers/nvme/target/loop.c b/drivers/nvme/target/loop.c
index 1e21b286f299..fdfcc961029f 100644
--- a/drivers/nvme/target/loop.c
+++ b/drivers/nvme/target/loop.c
@@ -686,6 +686,7 @@ static struct nvmet_fabrics_ops nvme_loop_ops = {
686 686
687static struct nvmf_transport_ops nvme_loop_transport = { 687static struct nvmf_transport_ops nvme_loop_transport = {
688 .name = "loop", 688 .name = "loop",
689 .module = THIS_MODULE,
689 .create_ctrl = nvme_loop_create_ctrl, 690 .create_ctrl = nvme_loop_create_ctrl,
690}; 691};
691 692