qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 07/17] hw/block/nvme: fix endian conversion


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH v2 07/17] hw/block/nvme: fix endian conversion
Date: Mon, 21 Sep 2020 17:51:16 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0

On 9/18/20 10:36 PM, Klaus Jensen wrote:
> From: Klaus Jensen <k.jensen@samsung.com>
> 
> The raw NLB field is a 16 bit value, so use le16_to_cpu instead of
> le32_to_cpu and cast to uint32_t before incrementing the value to not
> wrap around.
> 
> Signed-off-by: Klaus Jensen <k.jensen@samsung.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>  hw/block/nvme.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/block/nvme.c b/hw/block/nvme.c
> index 62db87460413..32267a3e4782 100644
> --- a/hw/block/nvme.c
> +++ b/hw/block/nvme.c
> @@ -645,7 +645,7 @@ static uint16_t nvme_write_zeroes(NvmeCtrl *n, 
> NvmeRequest *req)
>      NvmeRwCmd *rw = (NvmeRwCmd *)&req->cmd;
>      NvmeNamespace *ns = req->ns;
>      uint64_t slba = le64_to_cpu(rw->slba);
> -    uint32_t nlb  = le16_to_cpu(rw->nlb) + 1;
> +    uint32_t nlb = (uint32_t)le16_to_cpu(rw->nlb) + 1;
>      uint64_t offset = nvme_l2b(ns, slba);
>      uint32_t count = nvme_l2b(ns, nlb);
>      uint16_t status;
> @@ -669,7 +669,7 @@ static uint16_t nvme_rw(NvmeCtrl *n, NvmeRequest *req)
>  {
>      NvmeRwCmd *rw = (NvmeRwCmd *)&req->cmd;
>      NvmeNamespace *ns = req->ns;
> -    uint32_t nlb  = le32_to_cpu(rw->nlb) + 1;
> +    uint32_t nlb = (uint32_t)le16_to_cpu(rw->nlb) + 1;
>      uint64_t slba = le64_to_cpu(rw->slba);
>  
>      uint64_t data_size = nvme_l2b(ns, nlb);
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]