DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Wei Hu (Xavier)" <xavier.huwei@huawei.com>
To: <dev@dpdk.org>
Cc: <xavier.huwei@huawei.com>, <ferruh.yigit@intel.com>
Subject: [dpdk-dev] [PATCH 3/4] net/hns3: fix unintended sign extension in fd operation
Date: Tue, 9 Jun 2020 16:44:16 +0800	[thread overview]
Message-ID: <1591692257-55884-4-git-send-email-xavier.huwei@huawei.com> (raw)
In-Reply-To: <1591692257-55884-1-git-send-email-xavier.huwei@huawei.com>

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) <xavier.huwei@huawei.com>
---
 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


  parent reply	other threads:[~2020-06-09  8:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-09  8:44 [dpdk-dev] [PATCH 0/4] Bugfixes of coverity defects for hns3 PMD driver Wei Hu (Xavier)
2020-06-09  8:44 ` [dpdk-dev] [PATCH 1/4] net/hns3: fix passing negative parameter to strerror Wei Hu (Xavier)
2020-06-09  8:44 ` [dpdk-dev] [PATCH 2/4] net/hns3: avoid unchecked return value in reset err process Wei Hu (Xavier)
2020-06-09  8:44 ` Wei Hu (Xavier) [this message]
2020-06-09  8:44 ` [dpdk-dev] [PATCH 4/4] net/hns3: fix unintended sign extension in dump operation Wei Hu (Xavier)
2020-06-10  9:46 ` [dpdk-dev] [PATCH 0/4] Bugfixes of coverity defects for hns3 PMD driver Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1591692257-55884-4-git-send-email-xavier.huwei@huawei.com \
    --to=xavier.huwei@huawei.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).