Linux-NVME Archive on lore.kernel.org
 help / color / Atom feed
* [COMPILE TESTED PATCH] nvme: code cleanup nvme_identify_ns_desc()
@ 2020-02-11 22:10 Chaitanya Kulkarni
  2020-02-11 22:34 ` Keith Busch
  0 siblings, 1 reply; 2+ messages in thread
From: Chaitanya Kulkarni @ 2020-02-11 22:10 UTC (permalink / raw)
  To: hch, sagi, kbusch; +Cc: Chaitanya Kulkarni, linux-nvme

[-- Warning: decoded text below may be mangled --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 3482 bytes --]

The function nvme_identify_ns_desc() has 3 levels of nesting which make
error message to exceeded > 80 char per line which is not aligned with
the kernel code standards and rest of the NVMe subsystem code.
 
Add a helper function to move to the processing of the log when the 
command is successful by reducing the nesting and keeping the 
code < 80 char per line.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
Hi,

This is compile tested patch only, if everyone is okay I'll send
a well tested patch.

Regards,
Chaitanya
---
 drivers/nvme/host/core.c | 84 +++++++++++++++++++++++-----------------
 1 file changed, 48 insertions(+), 36 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 6ec03507da68..4dbb1622a65a 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1053,6 +1053,50 @@ static int nvme_identify_ctrl(struct nvme_ctrl *dev, struct nvme_id_ctrl **id)
 	return error;
 }
 
+static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids,
+				void *data, int pos)
+{
+	const char *warn_str = "ctrl returned bogus length:";
+	struct nvme_ns_id_desc *cur = data + pos;
+	int len;
+
+	switch (cur->nidt) {
+	case NVME_NIDT_EUI64:
+		if (cur->nidl != NVME_NIDT_EUI64_LEN) {
+			dev_warn(ctrl->device, "%s %d for NVME_NIDT_EUI64\n",
+				 warn_str, cur->nidl);
+			return -1;
+		}
+		len = NVME_NIDT_EUI64_LEN;
+		memcpy(ids->eui64, data + pos + sizeof(*cur), len);
+		break;
+	case NVME_NIDT_NGUID:
+		if (cur->nidl != NVME_NIDT_NGUID_LEN) {
+			dev_warn(ctrl->device, "%s %d for NVME_NIDT_NGUID\n",
+				 warn_str, cur->nidl);
+			return -1;
+		}
+		len = NVME_NIDT_NGUID_LEN;
+		memcpy(ids->nguid, data + pos + sizeof(*cur), len);
+		break;
+	case NVME_NIDT_UUID:
+		if (cur->nidl != NVME_NIDT_UUID_LEN) {
+			dev_warn(ctrl->device, "%s %d for NVME_NIDT_UUID\n",
+				 warn_str, cur->nidl);
+			return -1;
+		}
+		len = NVME_NIDT_UUID_LEN;
+		uuid_copy(&ids->uuid, data + pos + sizeof(*cur));
+		break;
+	default:
+		/* Skip unknown types */
+		len = cur->nidl;
+		break;
+	}
+
+	return len;
+}
+
 static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, unsigned nsid,
 		struct nvme_ns_ids *ids)
 {
@@ -1081,42 +1125,10 @@ static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, unsigned nsid,
 		if (cur->nidl == 0)
 			break;
 
-		switch (cur->nidt) {
-		case NVME_NIDT_EUI64:
-			if (cur->nidl != NVME_NIDT_EUI64_LEN) {
-				dev_warn(ctrl->device,
-					 "ctrl returned bogus length: %d for NVME_NIDT_EUI64\n",
-					 cur->nidl);
-				goto free_data;
-			}
-			len = NVME_NIDT_EUI64_LEN;
-			memcpy(ids->eui64, data + pos + sizeof(*cur), len);
-			break;
-		case NVME_NIDT_NGUID:
-			if (cur->nidl != NVME_NIDT_NGUID_LEN) {
-				dev_warn(ctrl->device,
-					 "ctrl returned bogus length: %d for NVME_NIDT_NGUID\n",
-					 cur->nidl);
-				goto free_data;
-			}
-			len = NVME_NIDT_NGUID_LEN;
-			memcpy(ids->nguid, data + pos + sizeof(*cur), len);
-			break;
-		case NVME_NIDT_UUID:
-			if (cur->nidl != NVME_NIDT_UUID_LEN) {
-				dev_warn(ctrl->device,
-					 "ctrl returned bogus length: %d for NVME_NIDT_UUID\n",
-					 cur->nidl);
-				goto free_data;
-			}
-			len = NVME_NIDT_UUID_LEN;
-			uuid_copy(&ids->uuid, data + pos + sizeof(*cur));
-			break;
-		default:
-			/* Skip unknown types */
-			len = cur->nidl;
-			break;
-		}
+		len = nvme_process_ns_desc(ctrl, ids, data, pos);
+
+		if (len < 0)
+			goto free_data;
 
 		len += sizeof(*cur);
 	}
-- 
2.22.1



[-- Attachment #2: Type: text/plain, Size: 158 bytes --]

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

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

* Re: [COMPILE TESTED PATCH] nvme: code cleanup nvme_identify_ns_desc()
  2020-02-11 22:10 [COMPILE TESTED PATCH] nvme: code cleanup nvme_identify_ns_desc() Chaitanya Kulkarni
@ 2020-02-11 22:34 ` Keith Busch
  0 siblings, 0 replies; 2+ messages in thread
From: Keith Busch @ 2020-02-11 22:34 UTC (permalink / raw)
  To: Chaitanya Kulkarni; +Cc: hch, linux-nvme, sagi

On Tue, Feb 11, 2020 at 02:10:54PM -0800, Chaitanya Kulkarni wrote:
> +static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids,
> +				void *data, int pos)
> +{
> +	const char *warn_str = "ctrl returned bogus length:";
> +	struct nvme_ns_id_desc *cur = data + pos;

<snip>

> @@ -1081,42 +1125,10 @@ static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, unsigned nsid,
>  		if (cur->nidl == 0)
>  			break;

...

> +		len = nvme_process_ns_desc(ctrl, ids, data, pos);

You pass a 'void *data' and immediately cast that to 'struct
nvme_ns_id_desc *cur'. The calling function did that previously too,
so you can just pass that 'cur' and use its type as the parameter to get a
slightly cleaner patch.

Otherwise, patch looks fine to me.

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

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-11 22:10 [COMPILE TESTED PATCH] nvme: code cleanup nvme_identify_ns_desc() Chaitanya Kulkarni
2020-02-11 22:34 ` Keith Busch

Linux-NVME Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-nvme/0 linux-nvme/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-nvme linux-nvme/ https://lore.kernel.org/linux-nvme \
		linux-nvme@lists.infradead.org
	public-inbox-index linux-nvme

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-nvme


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git