Commit d1877cc7 authored by Chaitanya Kulkarni's avatar Chaitanya Kulkarni Committed by Keith Busch
Browse files

nvme-fc: release admin tagset if init fails



nvme_fabrics creates an NVMe/FC controller in following path:

    nvmf_dev_write()
      -> nvmf_create_ctrl()
        -> nvme_fc_create_ctrl()
          -> nvme_fc_init_ctrl()

nvme_fc_init_ctrl() allocates the admin blk-mq resources right after
nvme_add_ctrl() succeeds.  If any of the subsequent steps fail (changing
the controller state, scheduling connect work, etc.), we jump to the
fail_ctrl path, which tears down the controller references but never
frees the admin queue/tag set.  The leaked blk-mq allocations match the
kmemleak report seen during blktests nvme/fc.

Check ctrl->ctrl.admin_tagset in the fail_ctrl path and call
nvme_remove_admin_tag_set() when it is set so that all admin queue
allocations are reclaimed whenever controller setup aborts.

Reported-by: default avatarYi Zhang <yi.zhang@redhat.com>
Reviewed-by: default avatarJustin Tee <justin.tee@broadcom.com>
Signed-off-by: default avatarChaitanya Kulkarni <ckulkarnilinux@gmail.com>
Signed-off-by: default avatarKeith Busch <kbusch@kernel.org>
parent 7d3fa7e9
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -3587,6 +3587,8 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,

	ctrl->ctrl.opts = NULL;

	if (ctrl->ctrl.admin_tagset)
		nvme_remove_admin_tag_set(&ctrl->ctrl);
	/* initiate nvme ctrl ref counting teardown */
	nvme_uninit_ctrl(&ctrl->ctrl);