net: thunderx: Fix unintentional sign extension issue
authorColin Ian King <colin.king@canonical.com>
Fri, 9 Apr 2021 13:07:26 +0000 (14:07 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 22 May 2021 08:40:27 +0000 (10:40 +0200)
[ Upstream commit e701a25840360706fe4cf5de0015913ca19c274b ]

The shifting of the u8 integers rq->caching by 26 bits to
the left will be promoted to a 32 bit signed int and then
sign-extended to a u64. In the event that rq->caching is
greater than 0x1f then all then all the upper 32 bits of
the u64 end up as also being set because of the int
sign-extension. Fix this by casting the u8 values to a
u64 before the 26 bit left shift.

Addresses-Coverity: ("Unintended sign extension")
Fixes: 4863dea3fab0 ("net: Adding support for Cavium ThunderX network controller")
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>
drivers/net/ethernet/cavium/thunder/nicvf_queues.c

index 747ef08829763db89b8fb1802eab9b47a0eef6b0..8f3d544bec0c9dd0e79d7d7d1e11412624e0355b 100644 (file)
@@ -537,7 +537,7 @@ static void nicvf_rcv_queue_config(struct nicvf *nic, struct queue_set *qs,
        mbx.rq.msg = NIC_MBOX_MSG_RQ_CFG;
        mbx.rq.qs_num = qs->vnic_id;
        mbx.rq.rq_num = qidx;
-       mbx.rq.cfg = (rq->caching << 26) | (rq->cq_qs << 19) |
+       mbx.rq.cfg = ((u64)rq->caching << 26) | (rq->cq_qs << 19) |
                          (rq->cq_idx << 16) | (rq->cont_rbdr_qs << 9) |
                          (rq->cont_qs_rbdr_idx << 8) |
                          (rq->start_rbdr_qs << 1) | (rq->start_qs_rbdr_idx);