[PATCH V2] nvme: fix crash and memory leak during invalid cdev teardown

Maurizio Lombardi mlombard at arkamax.eu
Mon Jun 8 08:32:46 PDT 2026


On Mon Jun 8, 2026 at 12:04 PM CEST, Maurizio Lombardi wrote:
> In the NVMe multipath code, if nvme_add_ns_head_cdev() fails during
> nvme_mpath_set_live(), the error is ignored. However, during teardown,
> nvme_remove_head() unconditionally calls nvme_cdev_del(). This teardown
> asymmetry leads to a kernel panic if the character device was never
> successfully initialized.
>
> +	name = kasprintf(GFP_KERNEL, "ng%dn%d", ns->ctrl->instance,
> +			 ns->head->instance);

Please disregard this patch; I should just use snprintf(), and it would be much simpler.

Maurizio



More information about the Linux-nvme mailing list