Thread (7 messages) 7 messages, 2 authors, 2021-05-18
STALE1897d

[PATCH 1/4] nvme: calculate data offset once for ns-desc

From: Chaitanya Kulkarni <hidden>
Date: 2021-05-18 05:06:44
Subsystem: nvm express driver, the rest · Maintainers: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg, Linus Torvalds

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 <redacted>
---
 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


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help