From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 7F47C45500;
	Wed, 26 Jun 2024 13:57:05 +0200 (CEST)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id A60334331A;
	Wed, 26 Jun 2024 13:55:16 +0200 (CEST)
Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9])
 by mails.dpdk.org (Postfix) with ESMTP id DD3F542E95
 for <dev@dpdk.org>; Wed, 26 Jun 2024 13:43:35 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1719402216; x=1750938216;
 h=from:to:cc:subject:date:message-id:in-reply-to:
 references:mime-version:content-transfer-encoding;
 bh=PmoQQYJYtL1XG6LqyWFBOvcUA+II2N+4XtEGMb7EvZc=;
 b=Kmic794pY13ow3vG8omywPlaueo4kAFav3/3Ai5eN1qLrhw49Bd0WJ6t
 R+upeqtVt9JC/piE8LbrWt/Q5m0cx2nmBVOUZfG1dn09GAkEYmE/MdyaV
 HvTymhEZEJNfIw2TLeRzPQjoqDdPlhYHX95/CF5NV+BDOhLEkUE08SLdd
 LxALiBBQPysBVd/PDDvr7460lzWNLVUtiP3yY98udNd5huUbkNiwYYPgU
 g3G6KM7iDwJ+s/Hxsvrpo/FY1IX5v0NXiUSx27gjl/R5xhVagT69MDUJ7
 Elhpx2T3igb9wLMFTdVY2rnTneTflqUSH/bBK3t9iGe6SLZ/zpY0DRhWZ Q==;
X-CSE-ConnectionGUID: dX3Bja3+R8+ZTmaIy3/kRA==
X-CSE-MsgGUID: 7JgboXzuS7mKyXpQfxj6pA==
X-IronPort-AV: E=McAfee;i="6700,10204,11114"; a="38979333"
X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="38979333"
Received: from orviesa010.jf.intel.com ([10.64.159.150])
 by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 26 Jun 2024 04:43:35 -0700
X-CSE-ConnectionGUID: 6Y3D0VGLS/CEvyyfpqhHRQ==
X-CSE-MsgGUID: TFx37ItPSoil+/s41H+Ysg==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="43873551"
Received: from unknown (HELO silpixa00401119.ir.intel.com) ([10.55.129.167])
 by orviesa010.jf.intel.com with ESMTP; 26 Jun 2024 04:43:32 -0700
From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org
Cc: Jacob Keller <jacob.e.keller@intel.com>, ian.stokes@intel.com,
 bruce.richardson@intel.com
Subject: [PATCH v4 020/103] net/ice/base: fix incorrect size when allocating
 children arrays
Date: Wed, 26 Jun 2024 12:41:08 +0100
Message-ID: <bbecf40b04ddb2617bc194cc88e475e9c76b4fa3.1719401847.git.anatoly.burakov@intel.com>
X-Mailer: git-send-email 2.43.0
In-Reply-To: <cover.1719401847.git.anatoly.burakov@intel.com>
References: <cover.1719313663.git.anatoly.burakov@intel.com>
 <cover.1719401847.git.anatoly.burakov@intel.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

From: Jacob Keller <jacob.e.keller@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@intel.com>
Signed-off-by: Ian Stokes <ian.stokes@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