nvmf/ctrlr: free ctrlr->qpair_mask when failure to create ctrlr

Fix potential bug. In _spdk_nvmf_subsystem_add_ctrlr(), befor free(
ctrlr) we should free ctrlr->qpair_mask. Because we set qpair->ctrlr
= NULL, when destroy qpair the qpair_mask is not released. For the same
reason, req->qpair->ctlr = ctrlr is placed at the bottom of the function.

Change-Id: I38e268b532ff3ce87721c02f15ac4f674856d103
Signed-off-by: JinYu <jin.yu@intel.com>
Reviewed-on: https://review.gerrithub.io/c/440858
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
This commit is contained in:
JinYu 2019-01-18 00:00:39 +08:00 committed by Changpeng Liu
parent cf73fb2f1f
commit a3c9ab66c8

View File

@ -135,6 +135,7 @@ _spdk_nvmf_subsystem_add_ctrlr(void *ctx)
if (spdk_nvmf_subsystem_add_ctrlr(ctrlr->subsys, ctrlr)) {
SPDK_ERRLOG("Unable to add controller to subsystem\n");
spdk_bit_array_free(&ctrlr->qpair_mask);
free(ctrlr);
qpair->ctrlr = NULL;
rsp->status.sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR;
@ -160,7 +161,6 @@ spdk_nvmf_ctrlr_create(struct spdk_nvmf_subsystem *subsystem,
return NULL;
}
req->qpair->ctrlr = ctrlr;
ctrlr->subsys = subsystem;
ctrlr->thread = req->qpair->group->thread;
@ -211,6 +211,7 @@ spdk_nvmf_ctrlr_create(struct spdk_nvmf_subsystem *subsystem,
SPDK_DEBUGLOG(SPDK_LOG_NVMF, "cc 0x%x\n", ctrlr->vcprop.cc.raw);
SPDK_DEBUGLOG(SPDK_LOG_NVMF, "csts 0x%x\n", ctrlr->vcprop.csts.raw);
req->qpair->ctrlr = ctrlr;
spdk_thread_send_msg(subsystem->thread, _spdk_nvmf_subsystem_add_ctrlr, req);
return ctrlr;