[PATCH v4 020/103] net/ice/base: fix incorrect size when allocating children arrays
Anatoly Burakov
anatoly.burakov at intel.com
Wed Jun 26 13:41:08 CEST 2024
From: Jacob Keller <jacob.e.keller at intel.com>
The ice_sched_add_root_node() and ice_sched_add_node() functions have comments
to suppress Coverity warnings about a suspicious sizeof used when allocating the
children array of an struct ice_sched_node.
The size is calculated using the size of the scheduler node, which overallocates
the array by a significant amount.
Fix the code to correctly calculate the size by using *root->children and
*node->children respectively.
This saves some memory and allows us to drop the Coverity suppression comments.
Signed-off-by: Jacob Keller <jacob.e.keller at intel.com>
Signed-off-by: Ian Stokes <ian.stokes at intel.com>
---
drivers/net/ice/base/ice_sched.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ice/base/ice_sched.c b/drivers/net/ice/base/ice_sched.c
index c9d70fb043..74d57329da 100644
--- a/drivers/net/ice/base/ice_sched.c
+++ b/drivers/net/ice/base/ice_sched.c
@@ -28,9 +28,8 @@ ice_sched_add_root_node(struct ice_port_info *pi,
if (!root)
return ICE_ERR_NO_MEMORY;
- /* coverity[suspicious_sizeof] */
root->children = (struct ice_sched_node **)
- ice_calloc(hw, hw->max_children[0], sizeof(*root));
+ ice_calloc(hw, hw->max_children[0], sizeof(*root->children));
if (!root->children) {
ice_free(hw, root);
return ICE_ERR_NO_MEMORY;
@@ -186,9 +185,9 @@ ice_sched_add_node(struct ice_port_info *pi, u8 layer,
if (!node)
return ICE_ERR_NO_MEMORY;
if (hw->max_children[layer]) {
- /* coverity[suspicious_sizeof] */
node->children = (struct ice_sched_node **)
- ice_calloc(hw, hw->max_children[layer], sizeof(*node));
+ ice_calloc(hw, hw->max_children[layer],
+ sizeof(*node->children));
if (!node->children) {
ice_free(hw, node);
return ICE_ERR_NO_MEMORY;
--
2.43.0
More information about the dev
mailing list