Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
net/ice/base: fix memory allocation wrapper
[ upstream commit 35f9cb0 ]

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: 5f0978e ("net/ice/base: add OS specific implementation")

Signed-off-by: David Marchand <david.marchand@redhat.com>
Acked-by: Qi Zhang <qi.z.zhang@intel.com>
  • Loading branch information
david-marchand authored and cpaelzer committed Jun 10, 2021
1 parent a619f63 commit 8640d6c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/net/ice/base/ice_osdep.h
Expand Up @@ -173,7 +173,7 @@ struct ice_virt_mem {
} __attribute__((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))
Expand Down

0 comments on commit 8640d6c

Please sign in to comment.