diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index af94d067ac140d..a55c2a774b9c45 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2040,6 +2040,13 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns, if (ret) return ret; + if (id->ncap == 0) { + /* namespace not allocated or attached */ + info->is_removed = true; + ret = -ENODEV; + goto error; + } + blk_mq_freeze_queue(ns->disk->queue); lbaf = nvme_lbaf_index(id->flbas); ns->lba_shift = id->lbaf[lbaf].ds; @@ -2101,6 +2108,8 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns, set_bit(NVME_NS_READY, &ns->flags); ret = 0; } + +error: kfree(id); return ret; }