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 620A0A034C;
	Fri, 25 Feb 2022 03:47:07 +0100 (CET)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id D50324014E;
	Fri, 25 Feb 2022 03:47:06 +0100 (CET)
Received: from mga12.intel.com (mga12.intel.com [192.55.52.136])
 by mails.dpdk.org (Postfix) with ESMTP id 818D440141;
 Fri, 25 Feb 2022 03:47:05 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1645757225; x=1677293225;
 h=from:to:cc:subject:date:message-id:in-reply-to:
 references:mime-version:content-transfer-encoding;
 bh=J3N2YHZCMTk4ceZahW0C62x1ZA0xmKOk/ylGo6YPpys=;
 b=JFL40JRQUL32cHZfg9/NmosJ+bMFN7Rt4uGL3ANgssq0UWBbQbITgGE7
 zbCx/AapUzMr6BF1S8pER8bTtqvxNlMzN7VIPybGHiXwPuD6sJx3SbGEW
 sduwVyamax/3G8rg0g2/e2AGVq2QdIVWVrAdBoG8w8ExQCxv2QxchSGJS
 CRHIRjX9lXHPTWTpsCULSDjitGMWvGnBpl5cp+hBxBeB9o+xo6pDtGon4
 L1/wmQBqfstQvOrFa/q01M5m9XJDS2kTGOfgU65QIMpq+xTudzDFJ2ILd
 GjhzKYYb8EYb7j+0cL7eX+mrORR5OKEnFSYHpDgDx1fF9uoC7u96OA7c8 Q==;
X-IronPort-AV: E=McAfee;i="6200,9189,10268"; a="232376647"
X-IronPort-AV: E=Sophos;i="5.90,134,1643702400"; d="scan'208";a="232376647"
Received: from orsmga007.jf.intel.com ([10.7.209.58])
 by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 24 Feb 2022 18:47:04 -0800
X-IronPort-AV: E=Sophos;i="5.90,134,1643702400"; d="scan'208";a="533398786"
Received: from intel-cd-odc-steve.cd.intel.com ([10.240.178.135])
 by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 24 Feb 2022 18:47:01 -0800
From: Steve Yang <stevex.yang@intel.com>
To: dev@dpdk.org
Cc: beilei.xing@intel.com, stephen@networkplumber.org, ferruh.yigit@intel.com,
 Steve Yang <stevex.yang@intel.com>, stable@dpdk.org
Subject: [PATCH v3] net/i40e: fix unintentional integer overflow
Date: Fri, 25 Feb 2022 02:39:47 +0000
Message-Id: <20220225023947.73045-1-stevex.yang@intel.com>
X-Mailer: git-send-email 2.27.0
In-Reply-To: <20220224011722.3585748-1-stevex.yang@intel.com>
References: <20220224011722.3585748-1-stevex.yang@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

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
Fixes: 5fec01c35c49 ("net/i40e: support Linux VF to configure IRQ link list")
Cc: stable@dpdk.org

---
v2: update commit message;
v3: use RTE_BIT64() to set bit;

Signed-off-by: Steve Yang <stevex.yang@intel.com>
---
 drivers/net/i40e/i40e_pf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/i40e/i40e_pf.c b/drivers/net/i40e/i40e_pf.c
index 2435a8a070..15d9ff868f 100644
--- a/drivers/net/i40e/i40e_pf.c
+++ b/drivers/net/i40e/i40e_pf.c
@@ -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;
 	}
 
-- 
2.27.0