From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 732F2A04FA; Tue, 9 Jun 2020 10:46:26 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 2480A2D13; Tue, 9 Jun 2020 10:46:04 +0200 (CEST) Received: from huawei.com (szxga07-in.huawei.com [45.249.212.35]) by dpdk.org (Postfix) with ESMTP id AF6972A62 for ; Tue, 9 Jun 2020 10:45:57 +0200 (CEST) Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 7DDABDFF77A314212BA8 for ; Tue, 9 Jun 2020 16:45:55 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Tue, 9 Jun 2020 16:45:46 +0800 From: "Wei Hu (Xavier)" To: CC: , Date: Tue, 9 Jun 2020 16:44:16 +0800 Message-ID: <1591692257-55884-4-git-send-email-xavier.huwei@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1591692257-55884-1-git-send-email-xavier.huwei@huawei.com> References: <1591692257-55884-1-git-send-email-xavier.huwei@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH 3/4] net/hns3: fix unintended sign extension in fd operation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Currently, there are coverity defects warning as below: CID 349937 (#1 of 1): Unintended sign extension (SIGN_EXTENSION) sign_extension: Suspicious implicit sign extension: port_number with type uint16_t (16 bits, unsigned) is promoted in port_number << cur_pos to type int (32 bits, signed), then sign-extended to type unsigned long (64 bits, unsigned). If port_number << cur_pos is greater than 0x7FFFFFFF, the upper bits of the result will all be 1. CID 349893 (#1 of 1): Unintended sign extension (SIGN_EXTENSION) sign_extension: Suspicious implicit sign extension: vlan_tag with type uint8_t (8 bits, unsigned) is promoted in vlan_tag << cur_pos to type int (32 bits, signed), then sign-extended to type unsigned long (64 bits, unsigned). If vlan_tag << cur_pos is greater than 0x7FFFFFFF, the upper bits of the result will all be 1. This patch fixes them by replacing the data type of port_number and vlan_tag with uint32_t in the inner static function named hns3_fd_convert_meta_data of hns3 PMD driver. Coverity issue: 349937, 349893 Fixes: fcba820d9b9e ("net/hns3: support flow director") Cc: stable@dpdk.org Signed-off-by: Wei Hu (Xavier) --- drivers/net/hns3/hns3_fdir.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/hns3/hns3_fdir.c b/drivers/net/hns3/hns3_fdir.c index 7bc5bf8..6ab439d 100644 --- a/drivers/net/hns3/hns3_fdir.c +++ b/drivers/net/hns3/hns3_fdir.c @@ -619,7 +619,7 @@ static void hns3_fd_convert_meta_data(struct hns3_fd_key_cfg *cfg, uint8_t *key_x, uint8_t *key_y) { uint16_t meta_data = 0; - uint16_t port_number; + uint32_t port_number; uint8_t cur_pos = 0; uint8_t tuple_size; uint8_t shift_bits; @@ -637,7 +637,7 @@ static void hns3_fd_convert_meta_data(struct hns3_fd_key_cfg *cfg, rule->key_conf.spec.tunnel_type ? 1 : 0); cur_pos += tuple_size; } else if (i == VLAN_NUMBER) { - uint8_t vlan_tag; + uint32_t vlan_tag; uint8_t vlan_num; if (rule->key_conf.spec.tunnel_type == 0) vlan_num = rule->key_conf.vlan_num; -- 2.7.4