[PATCH 1/4] nvme: calculate data offset once for ns-desc
Chaitanya Kulkarni
chaitanya.kulkarni at wdc.com
Mon May 17 22:05:54 PDT 2021
Calculate the data buffer offset only once instead of repeating the
calculation for all the nidt values when processing the ns-desc.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
---
drivers/nvme/host/core.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 762125f2905f..f8a3a36eba86 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1302,6 +1302,7 @@ static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids,
{
const char *warn_str = "ctrl returned bogus length:";
void *data = cur;
+ void *buf = data + sizeof(*cur);
switch (cur->nidt) {
case NVME_NIDT_EUI64:
@@ -1310,7 +1311,7 @@ static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids,
warn_str, cur->nidl);
return -1;
}
- memcpy(ids->eui64, data + sizeof(*cur), NVME_NIDT_EUI64_LEN);
+ memcpy(ids->eui64, buf, NVME_NIDT_EUI64_LEN);
return NVME_NIDT_EUI64_LEN;
case NVME_NIDT_NGUID:
if (cur->nidl != NVME_NIDT_NGUID_LEN) {
@@ -1318,7 +1319,7 @@ static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids,
warn_str, cur->nidl);
return -1;
}
- memcpy(ids->nguid, data + sizeof(*cur), NVME_NIDT_NGUID_LEN);
+ memcpy(ids->nguid, buf, NVME_NIDT_NGUID_LEN);
return NVME_NIDT_NGUID_LEN;
case NVME_NIDT_UUID:
if (cur->nidl != NVME_NIDT_UUID_LEN) {
@@ -1326,7 +1327,7 @@ static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids,
warn_str, cur->nidl);
return -1;
}
- uuid_copy(&ids->uuid, data + sizeof(*cur));
+ uuid_copy(&ids->uuid, buf);
return NVME_NIDT_UUID_LEN;
case NVME_NIDT_CSI:
if (cur->nidl != NVME_NIDT_CSI_LEN) {
@@ -1334,7 +1335,7 @@ static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids,
warn_str, cur->nidl);
return -1;
}
- memcpy(&ids->csi, data + sizeof(*cur), NVME_NIDT_CSI_LEN);
+ memcpy(&ids->csi, buf, NVME_NIDT_CSI_LEN);
*csi_seen = true;
return NVME_NIDT_CSI_LEN;
default:
--
2.22.1
More information about the Linux-nvme
mailing list