Skip to contentSkip to conversation

nvme: fix command ID wraparound handling

PATCH In review Prashant Kamble 2 participants 3 messages May 18 – May 20

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: fix command ID wraparound handling

nvme_get_cmd_id() returns 0 after cmdid reaches USHRT_MAX, but fails to reset cmdid itself. As a result, all subsequent calls keep returning 0 indefinitely.

Reset cmdid when wraparound occurs so command IDs continue incrementing correctly.

---
 drivers/nvme/nvme.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/nvme/nvme.c +4 -1
index 2b14437f69c..4f9473367d3 100644
@@ -112,7 +112,10 @@ static __le16 nvme_get_cmd_id(void)
 {
 	static unsigned short cmdid;
 
-	return cpu_to_le16((cmdid < USHRT_MAX) ? cmdid++ : 0);
+	if (cmdid >= USHRT_MAX)
+		cmdid = 0;
+
+	return cpu_to_le16(cmdid++);
 }
 
 static u16 nvme_read_completion_status(struct nvme_queue *nvmeq, u16 index)
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Prashant Kamble

nvme_get_cmd_id() returns 0 after cmdid reaches USHRT_MAX, but fails to reset cmdid itself. As a result, all subsequent calls keep returning 0 indefinitely.

Reset cmdid when wraparound occurs so command IDs continue incrementing correctly.

---
  drivers/nvme/nvme.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/nvme/nvme.c +0 -0
index 2b14437f69c..4f9473367d3 100644
@@ -112,7 +112,10 @@ static __le16 nvme_get_cmd_id(void)
  {

drivers/nvme/nvme.c static __le16 nvme_get_cmd_id(void) · line 121

Quoted 10 lines
drivers/nvme/nvme.c +4 -1
  	static unsigned short cmdid;
 
-	return cpu_to_le16((cmdid < USHRT_MAX) ? cmdid++ : 0);
+	if (cmdid >= USHRT_MAX)
+		cmdid = 0;
+
+	return cpu_to_le16(cmdid++);
  }
 
  static u16 nvme_read_completion_status(struct nvme_queue *nvmeq, u16 index)

Thanks,
Neil

#2 lore raw
In reply to Prashant Kamble

Hi,

Quoted 8 lines · Prashant Kamble

nvme_get_cmd_id() returns 0 after cmdid reaches USHRT_MAX, but fails to reset cmdid itself. As a result, all subsequent calls keep returning 0 indefinitely.

Reset cmdid when wraparound occurs so command IDs continue incrementing correctly.

[...]

Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-ufs (u-boot-nvme-fixes)

[1/1] nvme: fix command ID wraparound handling

      https://source.denx.de/u-boot/custodians/u-boot-ufs/-/commit/d6eb327828a384c3bf325de05633a77f66688f53
Signature · 1 line
Neil