Commit e2eeafc4 authored by Jiewei Ke's avatar Jiewei Ke Committed by Tomasz Zawadzki
Browse files

nvmf: check ctrlr at the beginning of nvmf_ctrlr_process_admin_cmd



In nvmf_ctrlr_process_admin_cmd, we will get the subsystem id from the
ctrlr and then decrement the sgroup's mgmt_io_outstanding for AER cases.
However, the ctrlr may be null since the host sends admin commands
before connect. To avoid nullptr reference, move the ctrlr check to the
beginning of nvmf_ctrlr_process_admin_cmd.

Fixes issue #3100.

Change-Id: I743e7a740c9cf046e5de3e8d13aa303212e883a8
Signed-off-by: default avatarJiewei Ke <jiewei@smartx.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/19435


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Community-CI: Mellanox Build Bot
parent e1602892
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -3528,6 +3528,13 @@ nvmf_ctrlr_process_admin_cmd(struct spdk_nvmf_request *req)
	struct spdk_nvmf_subsystem_poll_group *sgroup;
	int rc;

	if (ctrlr == NULL) {
		SPDK_ERRLOG("Admin command sent before CONNECT\n");
		response->status.sct = SPDK_NVME_SCT_GENERIC;
		response->status.sc = SPDK_NVME_SC_COMMAND_SEQUENCE_ERROR;
		return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
	}

	if (cmd->opc == SPDK_NVME_OPC_ASYNC_EVENT_REQUEST) {
		/* We do not want to treat AERs as outstanding commands,
		 * so decrement mgmt_io_outstanding here to offset
@@ -3538,13 +3545,6 @@ nvmf_ctrlr_process_admin_cmd(struct spdk_nvmf_request *req)
		sgroup->mgmt_io_outstanding--;
	}

	if (ctrlr == NULL) {
		SPDK_ERRLOG("Admin command sent before CONNECT\n");
		response->status.sct = SPDK_NVME_SCT_GENERIC;
		response->status.sc = SPDK_NVME_SC_COMMAND_SEQUENCE_ERROR;
		return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
	}

	assert(spdk_get_thread() == ctrlr->thread);

	if (cmd->fuse != 0) {