Skip to content

Commit ad95a61

Browse files
ChaitanayaKulkarnikeithbusch
authored andcommitted
nvme: code cleanup nvme_identify_ns_desc()
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 <[email protected]> Signed-off-by: Chaitanya Kulkarni <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent 2289145 commit ad95a61

File tree

1 file changed

+40
-36
lines changed

1 file changed

+40
-36
lines changed

drivers/nvme/host/core.c

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,43 @@ static int nvme_identify_ctrl(struct nvme_ctrl *dev, struct nvme_id_ctrl **id)
10551055
return error;
10561056
}
10571057

1058+
static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids,
1059+
struct nvme_ns_id_desc *cur)
1060+
{
1061+
const char *warn_str = "ctrl returned bogus length:";
1062+
void *data = cur;
1063+
1064+
switch (cur->nidt) {
1065+
case NVME_NIDT_EUI64:
1066+
if (cur->nidl != NVME_NIDT_EUI64_LEN) {
1067+
dev_warn(ctrl->device, "%s %d for NVME_NIDT_EUI64\n",
1068+
warn_str, cur->nidl);
1069+
return -1;
1070+
}
1071+
memcpy(ids->eui64, data + sizeof(*cur), NVME_NIDT_EUI64_LEN);
1072+
return NVME_NIDT_EUI64_LEN;
1073+
case NVME_NIDT_NGUID:
1074+
if (cur->nidl != NVME_NIDT_NGUID_LEN) {
1075+
dev_warn(ctrl->device, "%s %d for NVME_NIDT_NGUID\n",
1076+
warn_str, cur->nidl);
1077+
return -1;
1078+
}
1079+
memcpy(ids->nguid, data + sizeof(*cur), NVME_NIDT_NGUID_LEN);
1080+
return NVME_NIDT_NGUID_LEN;
1081+
case NVME_NIDT_UUID:
1082+
if (cur->nidl != NVME_NIDT_UUID_LEN) {
1083+
dev_warn(ctrl->device, "%s %d for NVME_NIDT_UUID\n",
1084+
warn_str, cur->nidl);
1085+
return -1;
1086+
}
1087+
uuid_copy(&ids->uuid, data + sizeof(*cur));
1088+
return NVME_NIDT_UUID_LEN;
1089+
default:
1090+
/* Skip unknown types */
1091+
return cur->nidl;
1092+
}
1093+
}
1094+
10581095
static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, unsigned nsid,
10591096
struct nvme_ns_ids *ids)
10601097
{
@@ -1083,42 +1120,9 @@ static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, unsigned nsid,
10831120
if (cur->nidl == 0)
10841121
break;
10851122

1086-
switch (cur->nidt) {
1087-
case NVME_NIDT_EUI64:
1088-
if (cur->nidl != NVME_NIDT_EUI64_LEN) {
1089-
dev_warn(ctrl->device,
1090-
"ctrl returned bogus length: %d for NVME_NIDT_EUI64\n",
1091-
cur->nidl);
1092-
goto free_data;
1093-
}
1094-
len = NVME_NIDT_EUI64_LEN;
1095-
memcpy(ids->eui64, data + pos + sizeof(*cur), len);
1096-
break;
1097-
case NVME_NIDT_NGUID:
1098-
if (cur->nidl != NVME_NIDT_NGUID_LEN) {
1099-
dev_warn(ctrl->device,
1100-
"ctrl returned bogus length: %d for NVME_NIDT_NGUID\n",
1101-
cur->nidl);
1102-
goto free_data;
1103-
}
1104-
len = NVME_NIDT_NGUID_LEN;
1105-
memcpy(ids->nguid, data + pos + sizeof(*cur), len);
1106-
break;
1107-
case NVME_NIDT_UUID:
1108-
if (cur->nidl != NVME_NIDT_UUID_LEN) {
1109-
dev_warn(ctrl->device,
1110-
"ctrl returned bogus length: %d for NVME_NIDT_UUID\n",
1111-
cur->nidl);
1112-
goto free_data;
1113-
}
1114-
len = NVME_NIDT_UUID_LEN;
1115-
uuid_copy(&ids->uuid, data + pos + sizeof(*cur));
1116-
break;
1117-
default:
1118-
/* Skip unknown types */
1119-
len = cur->nidl;
1120-
break;
1121-
}
1123+
len = nvme_process_ns_desc(ctrl, ids, cur);
1124+
if (len < 0)
1125+
goto free_data;
11221126

11231127
len += sizeof(*cur);
11241128
}

0 commit comments

Comments
 (0)