[PATCH] nvme: fix command ID wraparound handling
Neil Armstrong
neil.armstrong at linaro.org
Tue May 19 11:42:59 CEST 2026
On 5/18/26 08:08, Prashant Kamble wrote:
> 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.
>
> Signed-off-by: Prashant Kamble <prashant.kamble223 at gmail.com>
> ---
> drivers/nvme/nvme.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/nvme/nvme.c b/drivers/nvme/nvme.c
> index 2b14437f69c..4f9473367d3 100644
> --- a/drivers/nvme/nvme.c
> +++ b/drivers/nvme/nvme.c
> @@ -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)
Reviewed-by: Neil Armstrong <neil.armstrong at linaro.org>
Thanks,
Neil
More information about the U-Boot
mailing list