diff mbox series

net/ice/base: fix mem allocations wrapper

Message ID 20210506100702.23778-1-david.marchand@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Qi Zhang
Headers show
Series net/ice/base: fix mem allocations wrapper | expand

Checks

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

Commit Message

David Marchand May 6, 2021, 10:07 a.m. UTC
This is reported by our internal covscan:

1. dpdk-20.11/drivers/net/ice/base/ice_switch.c:4214: sign_extension:
Suspicious implicit sign extension: "s_rule_size" with type "u16" (16
bits, unsigned) is promoted in "num_unicast * s_rule_size" to type "int"
(32 bits, signed), then sign-extended to type "unsigned long" (64 bits,
unsigned).
If "num_unicast * s_rule_size" is greater than 0x7FFFFFFF, the upper bits
of the result will all be 1.

 #  4212|   	s_rule_size = ICE_SW_RULE_RX_TX_ETH_HDR_SIZE;
 #  4213|   	s_rule = (struct ice_aqc_sw_rules_elem *)
 #  4214|-> 		ice_calloc(hw, num_unicast, s_rule_size);
 #  4215|   	if (!s_rule) {
 #  4216|   		status = ICE_ERR_NO_MEMORY;

Even if this condition is not likely to happen, in any case, it is more
straightforward to rely on the existing rte_calloc.

Fixes: 5f0978e96220 ("net/ice/base: add OS specific implementation")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/ice/base/ice_osdep.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Zhang, Qi Z May 8, 2021, 1:53 a.m. UTC | #1
> -----Original Message-----
> From: David Marchand <david.marchand@redhat.com>
> Sent: Thursday, May 6, 2021 6:07 PM
> To: dev@dpdk.org
> Cc: stable@dpdk.org; Yang, Qiming <qiming.yang@intel.com>; Zhang, Qi Z
> <qi.z.zhang@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com>; Lu, Wenzhuo
> <wenzhuo.lu@intel.com>
> Subject: [PATCH] net/ice/base: fix mem allocations wrapper
> 
> This is reported by our internal covscan:
> 
> 1. dpdk-20.11/drivers/net/ice/base/ice_switch.c:4214: sign_extension:
> Suspicious implicit sign extension: "s_rule_size" with type "u16" (16 bits,
> unsigned) is promoted in "num_unicast * s_rule_size" to type "int"
> (32 bits, signed), then sign-extended to type "unsigned long" (64 bits,
> unsigned).
> If "num_unicast * s_rule_size" is greater than 0x7FFFFFFF, the upper bits of the
> result will all be 1.
> 
>  #  4212|   	s_rule_size = ICE_SW_RULE_RX_TX_ETH_HDR_SIZE;
>  #  4213|   	s_rule = (struct ice_aqc_sw_rules_elem *)
>  #  4214|-> 		ice_calloc(hw, num_unicast, s_rule_size);
>  #  4215|   	if (!s_rule) {
>  #  4216|   		status = ICE_ERR_NO_MEMORY;
> 
> Even if this condition is not likely to happen, in any case, it is more
> straightforward to rely on the existing rte_calloc.
> 
> Fixes: 5f0978e96220 ("net/ice/base: add OS specific implementation")
> Cc: stable@dpdk.org
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Acked-by: Qi Zhang <qi.z.zhang@intel.com>

Applied to dpdk-next-net-intel.

Thanks
Qi
diff mbox series

Patch

diff --git a/drivers/net/ice/base/ice_osdep.h b/drivers/net/ice/base/ice_osdep.h
index f4cc762e99..878c5597d4 100644
--- a/drivers/net/ice/base/ice_osdep.h
+++ b/drivers/net/ice/base/ice_osdep.h
@@ -207,7 +207,7 @@  struct ice_virt_mem {
 } __rte_packed;
 
 #define ice_malloc(h, s)    rte_zmalloc(NULL, s, 0)
-#define ice_calloc(h, c, s) rte_zmalloc(NULL, (c) * (s), 0)
+#define ice_calloc(h, c, s) rte_calloc(NULL, c, s, 0)
 #define ice_free(h, m)         rte_free(m)
 
 #define ice_memset(a, b, c, d) memset((a), (b), (c))