Skip to content

Commit

Permalink
net/hns3: fix unintended sign extension in fd operation
Browse files Browse the repository at this point in the history
[ upstream commit 5c471cb ]

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: fcba820 ("net/hns3: support flow director")

Signed-off-by: Wei Hu (Xavier) <xavier.huwei@huawei.com>
  • Loading branch information
xavierhw authored and bluca committed Jul 23, 2020
1 parent 0596f4a commit 9cd77fe
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/net/hns3/hns3_fdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 9cd77fe

Please sign in to comment.