linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] octeontx2-pf: Fix unintentional sign extension issue
@ 2020-11-18 13:05 Colin King
  2020-11-20 19:10 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2020-11-18 13:05 UTC (permalink / raw)
  To: Sunil Goutham, Geetha sowjanya, Subbaraya Sundeep, hariprasad,
	David S . Miller, Jakub Kicinski, Naveen Mamindlapalli,
	Tomasz Duszynski, netdev
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The shifting of the u16 result from ntohs(proto) by 16 bits to the
left will be promoted to a 32 bit signed int and then sign-extended
to a u64.  In the event that the top bit of the return from ntohs(proto)
is set then all then all the upper 32 bits of a 64 bit long end up as
also being set because of the sign-extension. Fix this by casting to
a u64 long before the shift.

Addresses-Coverity: ("Unintended sign extension")
Fixes: f0c2982aaf98 ("octeontx2-pf: Add support for SR-IOV management function")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
index 4c82f60f3cf3..634d60655a74 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
@@ -2084,7 +2084,7 @@ static int otx2_do_set_vf_vlan(struct otx2_nic *pf, int vf, u16 vlan, u8 qos,
 	vtag_req->vtag_size = VTAGSIZE_T4;
 	vtag_req->cfg_type = 0; /* tx vlan cfg */
 	vtag_req->tx.cfg_vtag0 = 1;
-	vtag_req->tx.vtag0 = (ntohs(proto) << 16) | vlan;
+	vtag_req->tx.vtag0 = ((u64)ntohs(proto) << 16) | vlan;
 
 	err = otx2_sync_mbox_msg(&pf->mbox);
 	if (err)
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH][next] octeontx2-pf: Fix unintentional sign extension issue
  2020-11-18 13:05 [PATCH][next] octeontx2-pf: Fix unintentional sign extension issue Colin King
@ 2020-11-20 19:10 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2020-11-20 19:10 UTC (permalink / raw)
  To: Colin King
  Cc: sgoutham, gakula, sbhatta, hkelam, davem, kuba, naveenm,
	tduszynski, netdev, kernel-janitors, linux-kernel

Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

On Wed, 18 Nov 2020 13:05:20 +0000 you wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The shifting of the u16 result from ntohs(proto) by 16 bits to the
> left will be promoted to a 32 bit signed int and then sign-extended
> to a u64.  In the event that the top bit of the return from ntohs(proto)
> is set then all then all the upper 32 bits of a 64 bit long end up as
> also being set because of the sign-extension. Fix this by casting to
> a u64 long before the shift.
> 
> [...]

Here is the summary with links:
  - [next] octeontx2-pf: Fix unintentional sign extension issue
    https://git.kernel.org/netdev/net-next/c/583b273dea75

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-11-20 19:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-18 13:05 [PATCH][next] octeontx2-pf: Fix unintentional sign extension issue Colin King
2020-11-20 19:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).