From a3c9ab66c8501bb7daee8b65390fe987841685bf Mon Sep 17 00:00:00 2001 From: JinYu Date: Fri, 18 Jan 2019 00:00:39 +0800 Subject: [PATCH] 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 Reviewed-on: https://review.gerrithub.io/c/440858 Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: Changpeng Liu Reviewed-by: Shuhei Matsumoto Reviewed-by: Ben Walker Reviewed-by: Darek Stojaczyk --- lib/nvmf/ctrlr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/nvmf/ctrlr.c b/lib/nvmf/ctrlr.c index a62f54f3d..94832f3b9 100644 --- a/lib/nvmf/ctrlr.c +++ b/lib/nvmf/ctrlr.c @@ -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;