]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
nvme: Fix potential sign extension issue in nvme_blk_rw()
authorBin Meng <bmeng.cn@gmail.com>
Sat, 2 Sep 2017 15:15:36 +0000 (08:15 -0700)
committerTom Rini <trini@konsulko.com>
Sun, 3 Sep 2017 19:30:33 +0000 (15:30 -0400)
"lbas" with type "u16" (16 bits, unsigned) is promoted in
"lbas << ns->lba_shift" to type "int" (32 bits, signed), then
sign-extended to type "unsigned long long" (64 bits, unsigned).
If "lbas << ns->lba_shift" is greater than 0x7FFFFFFF, the upper
bits of the result will all be 1.

Fix it by casting "lbas" to "u32".

Reported-by: Coverity (CID: 166730)
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
drivers/nvme/nvme.c

index 4448754acace73efd7a628d779a2225061421e97..59d54eb93ef6071b910d16b41119079651726694 100644 (file)
@@ -723,7 +723,7 @@ static ulong nvme_blk_rw(struct udevice *udev, lbaint_t blknr,
                                &c, NULL, IO_TIMEOUT);
                if (status)
                        break;
-               temp_len -= lbas << ns->lba_shift;
+               temp_len -= (u32)lbas << ns->lba_shift;
                buffer += lbas << ns->lba_shift;
        }