[v1] net/i40e: fix coverity issue

Message ID 20220223064147.3512888-1-stevex.yang@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Qi Zhang
Headers
Series [v1] net/i40e: fix coverity issue |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

Steve Yang Feb. 23, 2022, 6:41 a.m. UTC
  Cast 1 to type uint64_t to avoid overflow.

CID 375812 (#1 of 1):
Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
overflow_before_widen: Potentially overflowing expression 1 << 2 * i + 1
with type int (32 bits, signed) is evaluated using 32-bit arithmetic, and
then used in a context that expects an expression of type uint64_t
(64 bits, unsigned).

Coverity issue: 375812
Fixes: 5fec01c35c49 ("net/i40e: support Linux VF to configure IRQ link list")

Signed-off-by: Steve Yang <stevex.yang@intel.com>
---
 drivers/net/i40e/i40e_pf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Ferruh Yigit Feb. 23, 2022, 10:28 a.m. UTC | #1
On 2/23/2022 6:41 AM, Steve Yang wrote:
> Cast 1 to type uint64_t to avoid overflow.
> 
> CID 375812 (#1 of 1):
> Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
> overflow_before_widen: Potentially overflowing expression 1 << 2 * i + 1
> with type int (32 bits, signed) is evaluated using 32-bit arithmetic, and
> then used in a context that expects an expression of type uint64_t
> (64 bits, unsigned).
> 
> Coverity issue: 375812
> Fixes: 5fec01c35c49 ("net/i40e: support Linux VF to configure IRQ link list")
> 
> Signed-off-by: Steve Yang <stevex.yang@intel.com>

Hi Steve,

Can you please describe what is actually done in the
patch title?
Fixing a static tool warning is not descriptive enough.
  

Patch

diff --git a/drivers/net/i40e/i40e_pf.c b/drivers/net/i40e/i40e_pf.c
index 2435a8a070..39e0c021a4 100644
--- a/drivers/net/i40e/i40e_pf.c
+++ b/drivers/net/i40e/i40e_pf.c
@@ -604,7 +604,7 @@  i40e_pf_config_irq_link_list(struct i40e_pf_vf *vf,
 	tempmap = vvm->txq_map;
 	for (i = 0; i < sizeof(vvm->txq_map) * BITS_PER_CHAR; i++) {
 		if (tempmap & 0x1)
-			linklistmap |= (1 << (2 * i + 1));
+			linklistmap |= ((uint64_t)1 << (2 * i + 1));
 		tempmap >>= 1;
 	}