[PATCH] nvme-fc: fix double free of fabrics options when nvme_add_ctrl() fails
Keith Busch
kbusch at kernel.org
Tue Aug 11 08:29:38 PDT 2026
On Tue, Aug 11, 2026 at 09:53:10PM +0900, Rihyeon Kim wrote:
> It only does so on the fail_ctrl: path, though. When nvme_add_ctrl()
> fails, nvme_fc_init_ctrl() jumps to out_put_ctrl: instead, so
> nvme_fc_ctrl_free() still sees ctrl->ctrl.opts set and frees opts, and
> nvmf_create_ctrl() frees it again.
...
> diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
> index 04363b9c4489..e4d0eeccd846 100644
> --- a/drivers/nvme/host/fc.c
> +++ b/drivers/nvme/host/fc.c
> @@ -3601,6 +3601,9 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,
> nvme_uninit_ctrl(&ctrl->ctrl);
>
> out_put_ctrl:
> + /* nvme_add_ctrl() failures skip the clear in fail_ctrl: above */
> + ctrl->ctrl.opts = NULL;
> +
> /* Remove core ctrl ref. */
> nvme_put_ctrl(&ctrl->ctrl);
Can't you move the setting from the "fail_ctrl:" label to the
"out_put_ctrl:" one instead of duplicating it for both?
More information about the Linux-nvme
mailing list