nvme: code cleanup nvme_identify_ns_desc()
authorChaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Wed, 19 Feb 2020 16:14:31 +0000 (08:14 -0800)
committerKeith Busch <kbusch@kernel.org>
Wed, 25 Mar 2020 19:45:25 +0000 (04:45 +0900)
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 the processing of the log when the
command is successful by reducing the nesting and keeping the
code < 80 char per line.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
drivers/nvme/host/core.c

index 720840ca875c6fe5b91777453bf072df11b75ea9..c4dbc852b5e9325c7305d38e42933bf7aa45e959 100644 (file)
@@ -1055,6 +1055,43 @@ 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,
+               struct nvme_ns_id_desc *cur)
+{
+       const char *warn_str = "ctrl returned bogus length:";
+       void *data = cur;
+
+       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;
+               }
+               memcpy(ids->eui64, data + sizeof(*cur), NVME_NIDT_EUI64_LEN);
+               return NVME_NIDT_EUI64_LEN;
+       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;
+               }
+               memcpy(ids->nguid, data + sizeof(*cur), NVME_NIDT_NGUID_LEN);
+               return NVME_NIDT_NGUID_LEN;
+       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;
+               }
+               uuid_copy(&ids->uuid, data + sizeof(*cur));
+               return NVME_NIDT_UUID_LEN;
+       default:
+               /* Skip unknown types */
+               return cur->nidl;
+       }
+}
+
 static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, unsigned nsid,
                struct nvme_ns_ids *ids)
 {
@@ -1083,42 +1120,9 @@ 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, cur);
+               if (len < 0)
+                       goto free_data;
 
                len += sizeof(*cur);
        }