Blob Blame History Raw
From: Christoph Hellwig <hch@lst.de>
Date: Mon, 28 Sep 2020 12:33:19 +0200
Subject: nvme: lift the check for an unallocated namespace into
 nvme_identify_ns
Patch-mainline: v5.10-rc1
Git-commit: b8b8cd013327327e757529a0725a8c754c7890e3
References: bsc#1180197

Move the check from the two callers into the common helper.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Keith Busch <kbusch@kernel.org>
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Acked-by: Daniel Wagner <dwagner@suse.de>
---
 drivers/nvme/host/core.c |   17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1381,9 +1381,16 @@ static int nvme_identify_ns(struct nvme_
 	error = nvme_submit_sync_cmd(ctrl->admin_q, &c, *id, sizeof(**id));
 	if (error) {
 		dev_warn(ctrl->device, "Identify namespace failed (%d)\n", error);
-		kfree(*id);
+		goto out_free_id;
 	}
 
+	error = -ENODEV;
+	if ((*id)->ncap == 0) /* namespace not allocated or attached */
+		goto out_free_id;
+	return 0;
+
+out_free_id:
+	kfree(*id);
 	return error;
 }
 
@@ -2167,11 +2174,6 @@ static int nvme_validate_ns(struct nvme_
 	if (ret)
 		goto out;
 
-	if (id->ncap == 0) {
-		ret = -ENODEV;
-		goto free_id;
-	}
-
 	ret = nvme_report_ns_ids(ctrl, ns->head->ns_id, id, &ids);
 	if (ret)
 		goto free_id;
@@ -3936,9 +3938,6 @@ static void nvme_alloc_ns(struct nvme_ct
 	if (ret)
 		goto out_free_queue;
 
-	if (id->ncap == 0)	/* no namespace (legacy quirk) */
-		goto out_free_id;
-
 	ret = nvme_init_ns_head(ns, nsid, id);
 	if (ret)
 		goto out_free_id;