linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/1] A few code cleanups
@ 2019-11-26 22:26 Edmund Nadolski
  2019-11-26 22:26 ` [PATCH v2 1/1] nvme: remove unused return code from nvme_alloc_ns Edmund Nadolski
  0 siblings, 1 reply; 3+ messages in thread
From: Edmund Nadolski @ 2019-11-26 22:26 UTC (permalink / raw)
  To: edmund.nadolski, linux-nvme, kbusch

This patchset adds a few simple cleanups to the nvme code.

v2:
 Emit informational message when an error occurs.

Edmund Nadolski (1):
  nvme: remove unused return code from nvme_alloc_ns

 drivers/nvme/host/core.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

-- 
2.20.1

_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 1/1] nvme: remove unused return code from nvme_alloc_ns
  2019-11-26 22:26 [PATCH v2 0/1] A few code cleanups Edmund Nadolski
@ 2019-11-26 22:26 ` Edmund Nadolski
  2019-11-27  7:51   ` Christoph Hellwig
  0 siblings, 1 reply; 3+ messages in thread
From: Edmund Nadolski @ 2019-11-26 22:26 UTC (permalink / raw)
  To: edmund.nadolski, linux-nvme, kbusch

The return code of nvme_alloc_ns is never used, so change it
to void. Emit an informative message if an error occurs.

Signed-off-by: Edmund Nadolski <edmund.nadolski@intel.com>
---
 drivers/nvme/host/core.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index e6ee34376c5e..69c407d3d9ba 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3486,17 +3486,17 @@ static int nvme_setup_streams_ns(struct nvme_ctrl *ctrl, struct nvme_ns *ns)
 	return 0;
 }
 
-static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
+static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
 {
 	struct nvme_ns *ns;
 	struct gendisk *disk;
 	struct nvme_id_ns *id;
 	char disk_name[DISK_NAME_LEN];
-	int node = ctrl->numa_node, flags = GENHD_FL_EXT_DEVT, ret;
+	int node = ctrl->numa_node, flags = GENHD_FL_EXT_DEVT, ret = -ENOMEM;
 
 	ns = kzalloc_node(sizeof(*ns), GFP_KERNEL, node);
 	if (!ns)
-		return -ENOMEM;
+		goto out;
 
 	ns->queue = blk_mq_init_queue(ctrl->tagset);
 	if (IS_ERR(ns->queue)) {
@@ -3525,10 +3525,8 @@ static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
 	if (ret)
 		goto out_free_queue;
 
-	if (id->ncap == 0) {
-		ret = -EINVAL;
+	if (id->ncap == 0)
 		goto out_free_id;
-	}
 
 	ret = nvme_init_ns_head(ns, nsid, id);
 	if (ret)
@@ -3571,7 +3569,7 @@ static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
 	nvme_fault_inject_init(&ns->fault_inject, ns->disk->disk_name);
 	kfree(id);
 
-	return 0;
+	return;
  out_put_disk:
 	put_disk(ns->disk);
  out_unlink_ns:
@@ -3585,9 +3583,9 @@ static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
 	blk_cleanup_queue(ns->queue);
  out_free_ns:
 	kfree(ns);
-	if (ret > 0)
-		ret = blk_status_to_errno(nvme_error_status(ret));
-	return ret;
+ out:
+	dev_warn(ctrl->device, "could not allocate %sns.\n",
+		(ret == -ENOMEM) ? "memory for " : "" );
 }
 
 static void nvme_ns_remove(struct nvme_ns *ns)
-- 
2.20.1


_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 1/1] nvme: remove unused return code from nvme_alloc_ns
  2019-11-26 22:26 ` [PATCH v2 1/1] nvme: remove unused return code from nvme_alloc_ns Edmund Nadolski
@ 2019-11-27  7:51   ` Christoph Hellwig
  0 siblings, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2019-11-27  7:51 UTC (permalink / raw)
  To: Edmund Nadolski; +Cc: kbusch, linux-nvme

I think this needs some tweaks..

>  	ns = kzalloc_node(sizeof(*ns), GFP_KERNEL, node);
>  	if (!ns)
> -		return -ENOMEM;
> +		goto out;

kmalloc failures already always leave a trace, so we can just return
here.

>  	ns->queue = blk_mq_init_queue(ctrl->tagset);
>  	if (IS_ERR(ns->queue)) {
> @@ -3525,10 +3525,8 @@ static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
>  	if (ret)
>  		goto out_free_queue;
>  
> -	if (id->ncap == 0) {
> -		ret = -EINVAL;
> +	if (id->ncap == 0)
>  		goto out_free_id;
> -	}

ncap == 0 means there is no namespace, this is a quirk dating back
to NVMe 1.0 where the driver has to do a sequential scan.  So we don't
need a warning here either.

So looking at this a bit more I'm not even sure we need warning messages
contrary to my previous advice, as the only obvious error that is not
a memory allocation is the command execution in nvme_identify_ns,
and the lightnvm registration which both already log warnings.

_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-11-27  7:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-26 22:26 [PATCH v2 0/1] A few code cleanups Edmund Nadolski
2019-11-26 22:26 ` [PATCH v2 1/1] nvme: remove unused return code from nvme_alloc_ns Edmund Nadolski
2019-11-27  7:51   ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).