From: Keith Busch Date: Wed, 26 Aug 2020 17:53:04 +0000 (-0700) Subject: nvme: fix controller instance leak X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=192f6c29bb28bfd0a17e6ad331d09f1ec84143d0;p=linux.git nvme: fix controller instance leak If the driver has to unbind from the controller for an early failure before the subsystem has been set up, there won't be a subsystem holding the controller's instance, so the controller needs to free its own instance in this case. Fixes: 733e4b69d508d ("nvme: Assign subsys instance from first ctrl") Signed-off-by: Keith Busch Reviewed-by: Chaitanya Kulkarni Reviewed-by: Christoph Hellwig Signed-off-by: Sagi Grimberg --- diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index e406c3cf55bc1..d6186208abf9a 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -4394,7 +4394,7 @@ static void nvme_free_ctrl(struct device *dev) struct nvme_subsystem *subsys = ctrl->subsys; struct nvme_cel *cel, *next; - if (subsys && ctrl->instance != subsys->instance) + if (!subsys || ctrl->instance != subsys->instance) ida_simple_remove(&nvme_instance_ida, ctrl->instance); list_for_each_entry_safe(cel, next, &ctrl->cels, entry) {