Skip to content

Commit deb9a9a

Browse files
Colin Ian KingJeff Kirsher
authored andcommitted
i40evf: remove redundant array comparisons to 0 checks
The checks to see if key->dst.s6_addr and key->src.s6_addr are null pointers are redundant because these are constant size arrays and so the checks always return true. Fix this by removing the redundant checks. Also replace filter->f with vf, allowing wide lines to be condensed and to rejoin some split wide lines. Detected by CoverityScan, CID#1465279 ("Array compared to 0") Signed-off-by: Colin Ian King <[email protected]> Tested-by: Andrew Bowers <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent 46345b3 commit deb9a9a

File tree

1 file changed

+25
-36
lines changed

1 file changed

+25
-36
lines changed

drivers/net/ethernet/intel/i40evf/i40evf_main.c

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,6 +2490,7 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter,
24902490
u16 addr_type = 0;
24912491
u16 n_proto = 0;
24922492
int i = 0;
2493+
struct virtchnl_filter *vf = &filter->f;
24932494

24942495
if (f->dissector->used_keys &
24952496
~(BIT(FLOW_DISSECTOR_KEY_CONTROL) |
@@ -2537,7 +2538,7 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter,
25372538
return -EINVAL;
25382539
if (n_proto == ETH_P_IPV6) {
25392540
/* specify flow type as TCP IPv6 */
2540-
filter->f.flow_type = VIRTCHNL_TCP_V6_FLOW;
2541+
vf->flow_type = VIRTCHNL_TCP_V6_FLOW;
25412542
}
25422543

25432544
if (key->ip_proto != IPPROTO_TCP) {
@@ -2582,9 +2583,8 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter,
25822583
is_multicast_ether_addr(key->dst)) {
25832584
/* set the mask if a valid dst_mac address */
25842585
for (i = 0; i < ETH_ALEN; i++)
2585-
filter->f.mask.tcp_spec.dst_mac[i] |=
2586-
0xff;
2587-
ether_addr_copy(filter->f.data.tcp_spec.dst_mac,
2586+
vf->mask.tcp_spec.dst_mac[i] |= 0xff;
2587+
ether_addr_copy(vf->data.tcp_spec.dst_mac,
25882588
key->dst);
25892589
}
25902590

@@ -2593,9 +2593,8 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter,
25932593
is_multicast_ether_addr(key->src)) {
25942594
/* set the mask if a valid dst_mac address */
25952595
for (i = 0; i < ETH_ALEN; i++)
2596-
filter->f.mask.tcp_spec.src_mac[i] |=
2597-
0xff;
2598-
ether_addr_copy(filter->f.data.tcp_spec.src_mac,
2596+
vf->mask.tcp_spec.src_mac[i] |= 0xff;
2597+
ether_addr_copy(vf->data.tcp_spec.src_mac,
25992598
key->src);
26002599
}
26012600
}
@@ -2619,8 +2618,8 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter,
26192618
return I40E_ERR_CONFIG;
26202619
}
26212620
}
2622-
filter->f.mask.tcp_spec.vlan_id |= cpu_to_be16(0xffff);
2623-
filter->f.data.tcp_spec.vlan_id = cpu_to_be16(key->vlan_id);
2621+
vf->mask.tcp_spec.vlan_id |= cpu_to_be16(0xffff);
2622+
vf->data.tcp_spec.vlan_id = cpu_to_be16(key->vlan_id);
26242623
}
26252624

26262625
if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_CONTROL)) {
@@ -2667,14 +2666,12 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter,
26672666
return I40E_ERR_CONFIG;
26682667
}
26692668
if (key->dst) {
2670-
filter->f.mask.tcp_spec.dst_ip[0] |=
2671-
cpu_to_be32(0xffffffff);
2672-
filter->f.data.tcp_spec.dst_ip[0] = key->dst;
2669+
vf->mask.tcp_spec.dst_ip[0] |= cpu_to_be32(0xffffffff);
2670+
vf->data.tcp_spec.dst_ip[0] = key->dst;
26732671
}
26742672
if (key->src) {
2675-
filter->f.mask.tcp_spec.src_ip[0] |=
2676-
cpu_to_be32(0xffffffff);
2677-
filter->f.data.tcp_spec.src_ip[0] = key->src;
2673+
vf->mask.tcp_spec.src_ip[0] |= cpu_to_be32(0xffffffff);
2674+
vf->data.tcp_spec.src_ip[0] = key->src;
26782675
}
26792676
}
26802677

@@ -2707,22 +2704,14 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter,
27072704
if (!ipv6_addr_any(&mask->dst) || !ipv6_addr_any(&mask->src))
27082705
field_flags |= I40EVF_CLOUD_FIELD_IIP;
27092706

2710-
if (key->dst.s6_addr) {
2711-
for (i = 0; i < 4; i++)
2712-
filter->f.mask.tcp_spec.dst_ip[i] |=
2713-
cpu_to_be32(0xffffffff);
2714-
memcpy(&filter->f.data.tcp_spec.dst_ip,
2715-
&key->dst.s6_addr32,
2716-
sizeof(filter->f.data.tcp_spec.dst_ip));
2717-
}
2718-
if (key->src.s6_addr) {
2719-
for (i = 0; i < 4; i++)
2720-
filter->f.mask.tcp_spec.src_ip[i] |=
2721-
cpu_to_be32(0xffffffff);
2722-
memcpy(&filter->f.data.tcp_spec.src_ip,
2723-
&key->src.s6_addr32,
2724-
sizeof(filter->f.data.tcp_spec.src_ip));
2725-
}
2707+
for (i = 0; i < 4; i++)
2708+
vf->mask.tcp_spec.dst_ip[i] |= cpu_to_be32(0xffffffff);
2709+
memcpy(&vf->data.tcp_spec.dst_ip, &key->dst.s6_addr32,
2710+
sizeof(vf->data.tcp_spec.dst_ip));
2711+
for (i = 0; i < 4; i++)
2712+
vf->mask.tcp_spec.src_ip[i] |= cpu_to_be32(0xffffffff);
2713+
memcpy(&vf->data.tcp_spec.src_ip, &key->src.s6_addr32,
2714+
sizeof(vf->data.tcp_spec.src_ip));
27262715
}
27272716
if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_PORTS)) {
27282717
struct flow_dissector_key_ports *key =
@@ -2754,16 +2743,16 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter,
27542743
}
27552744
}
27562745
if (key->dst) {
2757-
filter->f.mask.tcp_spec.dst_port |= cpu_to_be16(0xffff);
2758-
filter->f.data.tcp_spec.dst_port = key->dst;
2746+
vf->mask.tcp_spec.dst_port |= cpu_to_be16(0xffff);
2747+
vf->data.tcp_spec.dst_port = key->dst;
27592748
}
27602749

27612750
if (key->src) {
2762-
filter->f.mask.tcp_spec.src_port |= cpu_to_be16(0xffff);
2763-
filter->f.data.tcp_spec.src_port = key->dst;
2751+
vf->mask.tcp_spec.src_port |= cpu_to_be16(0xffff);
2752+
vf->data.tcp_spec.src_port = key->dst;
27642753
}
27652754
}
2766-
filter->f.field_flags = field_flags;
2755+
vf->field_flags = field_flags;
27672756

27682757
return 0;
27692758
}

0 commit comments

Comments
 (0)