Skip to contentSkip to conversation

net/i40e: fix coverity issue

PATCH In review Steve Yang 4 participants 9 messages Feb 23, 2022 – Feb 25, 2022 Network drivers

lore
Share & tools
lore

Steve Yang

author
#0 lore raw

PATCH 1/1 net/i40e: fix coverity issue

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")
---
 drivers/net/i40e/i40e_pf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/i40e/i40e_pf.c +1 -1
index 2435a8a070..39e0c021a4 100644
@@ -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;
 	}
 
Signature · 1 line
2.27.0
#1 lore raw
Quoted 9 lines · Steve Yang

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).

Quoted 4 lines

Coverity issue: 375812

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

Hi Steve,

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

author
#2 lore raw

PATCH v2 1/1 net/i40e: fix unintentional integer overflow

In reply to Steve Yang

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")

---
v2: update commit message.

---
 drivers/net/i40e/i40e_pf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/i40e/i40e_pf.c +1 -1
index 2435a8a070..39e0c021a4 100644
@@ -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;
 	}
 
Signature · 1 line
2.27.0
Acked-by on v2 1/1 Applied
#3 lore raw

RE: [PATCH v2] net/i40e: fix unintentional integer overflow

Quoted 19 lines

-----Original Message-----
From: Steve Yang <[email protected]>
Sent: Thursday, February 24, 2022 9:17 AM
To: [email protected]
Cc: Yigit, Ferruh <[email protected]>; Xing, Beilei <[email protected]>; Yang, SteveX <[email protected]>; [email protected]
Subject: [PATCH v2] net/i40e: fix unintentional integer overflow

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).

Quoted 8 lines

Coverity issue: 375812

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

---
v2: update commit message.

Applied to dpdk-next-net-intel.

Thanks
Qi

#4 lore raw

Re: [PATCH v2] net/i40e: fix unintentional integer overflow

In reply to Steve Yang
Quoted 26 lines · On Thu, 24 Feb 2022 01:17:22 +0000 Steve Yang <[email protected]> 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")

---
v2: update commit message.

---
 drivers/net/i40e/i40e_pf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/i40e/i40e_pf.c +0 -0
index 2435a8a070..39e0c021a4 100644

drivers/net/i40e/i40e_pf.c i40e_pf_config_irq_link_list(struct i40e_pf_vf *vf, · line 607

Quoted 5 lines
drivers/net/i40e/i40e_pf.c +1 -1
@@ -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));

Could be RTE_BIT64(2 * i + 1) instead?

#5 lore raw

RE: [PATCH v2] net/i40e: fix unintentional integer overflow

Quoted 36 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Thursday, February 24, 2022 12:11 PM
To: Yang, SteveX <[email protected]>
Cc: [email protected]; Yigit, Ferruh <[email protected]>; Xing, Beilei <[email protected]>; [email protected]
Subject: Re: [PATCH v2] net/i40e: fix unintentional integer overflow

Quoted 23 lines · On Thu, 24 Feb 2022 01:17:22 +0000 Steve Yang <[email protected]> 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")
Cc: [email protected]

---
v2: update commit message.

---
 drivers/net/i40e/i40e_pf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

drivers/net/i40e/i40e_pf.c i40e_pf_config_irq_link_list(struct i40e_pf_vf *vf, · line 607

Quoted 10 lines
drivers/net/i40e/i40e_pf.c +1 -1
index 2435a8a070..39e0c021a4 100644
@@ -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));

Could be RTE_BIT64(2 * i + 1) instead?

Thanks Stephen, excellent suggestion.
Current code exist lots of similar nonstandard bit expression, I think it maybe better to start a new patch series to change them.

#6 lore raw

Re: [PATCH v2] net/i40e: fix unintentional integer overflow

Quoted 49 lines · SteveX
Quoted 36 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Thursday, February 24, 2022 12:11 PM
To: Yang, SteveX <[email protected]>
Cc: [email protected]; Yigit, Ferruh <[email protected]>; Xing, Beilei <[email protected]>; [email protected]
Subject: Re: [PATCH v2] net/i40e: fix unintentional integer overflow

Quoted 23 lines · On Thu, 24 Feb 2022 01:17:22 +0000 Steve Yang <[email protected]> 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")
Cc: [email protected]

---
v2: update commit message.

---
  drivers/net/i40e/i40e_pf.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

drivers/net/i40e/i40e_pf.c i40e_pf_config_irq_link_list(struct i40e_pf_vf *vf, · line 607

Quoted 10 lines
drivers/net/i40e/i40e_pf.c +1 -1
index 2435a8a070..39e0c021a4 100644
@@ -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));

Could be RTE_BIT64(2 * i + 1) instead?

Quoted 3 lines

Thanks Stephen, excellent suggestion.
Current code exist lots of similar nonstandard bit expression, I think it maybe better to start a new patch series to change them.

Hi Steve,

Why not fix this instance in this patch, it is a simple change?

Later a clenaup patch can be optional on its own time, but better to get this fix in this release.

author
#7 lore raw

PATCH v3 1/1 net/i40e: fix unintentional integer overflow

In reply to Steve Yang

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")

---
v2: update commit message;
v3: use RTE_BIT64() to set bit;

---
 drivers/net/i40e/i40e_pf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/i40e/i40e_pf.c +2 -2
index 2435a8a070..15d9ff868f 100644
@@ -597,14 +597,14 @@ i40e_pf_config_irq_link_list(struct i40e_pf_vf *vf,
 	tempmap = vvm->rxq_map;
 	for (i = 0; i < sizeof(vvm->rxq_map) * BITS_PER_CHAR; i++) {
 		if (tempmap & 0x1)
-			linklistmap |= (1 << (2 * i));
+			linklistmap |= RTE_BIT64(2 * i);
 		tempmap >>= 1;
 	}
 
 	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 |= RTE_BIT64(2 * i + 1);
 		tempmap >>= 1;
 	}
 
Signature · 1 line
2.27.0
Reviewed-by on v3 1/1 Applied
#8 lore raw

Re: [PATCH v3] net/i40e: fix unintentional integer overflow

Quoted 10 lines · Steve Yang

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

Quoted 8 lines
Fixes 5fec01c35c49 ("net/i40e: support Linux VF to configure IRQ link list")

---
v2: update commit message;
v3: use RTE_BIT64() to set bit;

Applied to dpdk-next-net/main, thanks.