net/i40e: fix coverity issue
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
--- drivers/net/i40e/i40e_pf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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 )); tempmap >>=1 ; }
Signature · 1 line
2.27.0
Quoted 9 lines · Steve Yang
Cast 1 to type
uint64_tto 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 typeuint64_t(64 bits, unsigned).
Quoted 4 lines
Coverity issue: 375812
Fixes 5fec01c35c49 ("net/i40e: support Linux VF to configure IRQ link list")Signed-off-by Steve Yang <[email protected]>
Hi Steve,
Can you please describe what is actually done in the patch title?
Fixing a static tool warning is not descriptive enough.
PATCH v2 1/1 net/i40e: fix unintentional integer overflow
In reply to Steve YangCast 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
---
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
@@ -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
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 overflowCast 1 to type
uint64_tto 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 typeuint64_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.Signed-off-by Steve Yang <[email protected]>
Applied to dpdk-next-net-intel.
Thanks
Qi
Re: [PATCH v2] net/i40e: fix unintentional integer overflow
In reply to Steve YangQuoted 26 lines · On Thu, 24 Feb 2022 01:17:22 +0000 Steve Yang <[email protected]> wrote:
Cast 1 to type
uint64_tto 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 typeuint64_t(64 bits, unsigned).Coverity issue: 375812
Fixes 5fec01c35c49 ("net/i40e: support Linux VF to configure IRQ link list")---
v2: update commit message.Signed-off-by Steve Yang <[email protected]>--- drivers/net/i40e/i40e_pf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/i40e/i40e_pf.c +0
-0
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?
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 overflowQuoted 23 lines · On Thu, 24 Feb 2022 01:17:22 +0000 Steve Yang <[email protected]> wrote:
Cast 1 to type
uint64_tto 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 typeuint64_t
(64 bits, unsigned).Coverity issue: 375812
Fixes 5fec01c35c49 ("net/i40e: support Linux VF to configure IRQ linklist")
Cc: [email protected]---
v2: update commit message.Signed-off-by Steve Yang <[email protected]>--- 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@@ -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.
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 overflowQuoted 23 lines · On Thu, 24 Feb 2022 01:17:22 +0000 Steve Yang <[email protected]> wrote:
Cast 1 to type
uint64_tto 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 typeuint64_t
(64 bits, unsigned).Coverity issue: 375812
Fixes 5fec01c35c49 ("net/i40e: support Linux VF to configure IRQ linklist")
Cc: [email protected]---
v2: update commit message.Signed-off-by Steve Yang <[email protected]>--- 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@@ -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.
PATCH v3 1/1 net/i40e: fix unintentional integer overflow
In reply to Steve YangCast 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
---
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
@@ -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
Re: [PATCH v3] net/i40e: fix unintentional integer overflow
Quoted 10 lines · Steve Yang
Cast 1 to type
uint64_tto 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 typeuint64_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: useRTE_BIT64()to set bit;Signed-off-by Steve Yang <[email protected]>
Applied to dpdk-next-net/main, thanks.