]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commit
liquidio: Fix unintented sign extension of a left shift of a u16
authorColin Ian King <colin.king@canonical.com>
Wed, 7 Apr 2021 10:12:48 +0000 (11:12 +0100)
committerKelsey Skunberg <kelsey.skunberg@canonical.com>
Mon, 24 May 2021 23:46:36 +0000 (17:46 -0600)
commitb6b0f09e6f5dda1438ee46a31c174b30f40ea2aa
tree282c47061309329ab04c79c39905a46cee2f3b57
parent909a1e43a209d396a0ee4f142369e463fa4231f3
liquidio: Fix unintented sign extension of a left shift of a u16

BugLink: https://bugs.launchpad.net/bugs/1929455
[ Upstream commit 298b58f00c0f86868ea717426beb5c1198772f81 ]

The macro CN23XX_PEM_BAR1_INDEX_REG is being used to shift oct->pcie_port
(a u16) left 24 places. There are two subtle issues here, first the
shift gets promoted to an signed int and then sign extended to a u64.
If oct->pcie_port is 0x80 or more then the upper bits get sign extended
to 1. Secondly shfiting a u16 24 bits will lead to an overflow so it
needs to be cast to a u64 for all the bits to not overflow.

It is entirely possible that the u16 port value is never large enough
for this to fail, but it is useful to fix unintended overflows such
as this.

Fix this by casting the port parameter to the macro to a u64 before
the shift.

Addresses-Coverity: ("Unintended sign extension")
Fixes: 5bc67f587ba7 ("liquidio: CN23XX register definitions")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
drivers/net/ethernet/cavium/liquidio/cn23xx_pf_regs.h