Commit deb9a9ad authored by Colin Ian King's avatar Colin Ian King Committed by Jeff Kirsher

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: default avatarColin Ian King <colin.king@canonical.com>
Tested-by: default avatarAndrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: default avatarJeff Kirsher <jeffrey.t.kirsher@intel.com>
parent 46345b38
...@@ -2490,6 +2490,7 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter, ...@@ -2490,6 +2490,7 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter,
u16 addr_type = 0; u16 addr_type = 0;
u16 n_proto = 0; u16 n_proto = 0;
int i = 0; int i = 0;
struct virtchnl_filter *vf = &filter->f;
if (f->dissector->used_keys & if (f->dissector->used_keys &
~(BIT(FLOW_DISSECTOR_KEY_CONTROL) | ~(BIT(FLOW_DISSECTOR_KEY_CONTROL) |
...@@ -2537,7 +2538,7 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter, ...@@ -2537,7 +2538,7 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter,
return -EINVAL; return -EINVAL;
if (n_proto == ETH_P_IPV6) { if (n_proto == ETH_P_IPV6) {
/* specify flow type as TCP IPv6 */ /* specify flow type as TCP IPv6 */
filter->f.flow_type = VIRTCHNL_TCP_V6_FLOW; vf->flow_type = VIRTCHNL_TCP_V6_FLOW;
} }
if (key->ip_proto != IPPROTO_TCP) { if (key->ip_proto != IPPROTO_TCP) {
...@@ -2582,9 +2583,8 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter, ...@@ -2582,9 +2583,8 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter,
is_multicast_ether_addr(key->dst)) { is_multicast_ether_addr(key->dst)) {
/* set the mask if a valid dst_mac address */ /* set the mask if a valid dst_mac address */
for (i = 0; i < ETH_ALEN; i++) for (i = 0; i < ETH_ALEN; i++)
filter->f.mask.tcp_spec.dst_mac[i] |= vf->mask.tcp_spec.dst_mac[i] |= 0xff;
0xff; ether_addr_copy(vf->data.tcp_spec.dst_mac,
ether_addr_copy(filter->f.data.tcp_spec.dst_mac,
key->dst); key->dst);
} }
...@@ -2593,9 +2593,8 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter, ...@@ -2593,9 +2593,8 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter,
is_multicast_ether_addr(key->src)) { is_multicast_ether_addr(key->src)) {
/* set the mask if a valid dst_mac address */ /* set the mask if a valid dst_mac address */
for (i = 0; i < ETH_ALEN; i++) for (i = 0; i < ETH_ALEN; i++)
filter->f.mask.tcp_spec.src_mac[i] |= vf->mask.tcp_spec.src_mac[i] |= 0xff;
0xff; ether_addr_copy(vf->data.tcp_spec.src_mac,
ether_addr_copy(filter->f.data.tcp_spec.src_mac,
key->src); key->src);
} }
} }
...@@ -2619,8 +2618,8 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter, ...@@ -2619,8 +2618,8 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter,
return I40E_ERR_CONFIG; return I40E_ERR_CONFIG;
} }
} }
filter->f.mask.tcp_spec.vlan_id |= cpu_to_be16(0xffff); vf->mask.tcp_spec.vlan_id |= cpu_to_be16(0xffff);
filter->f.data.tcp_spec.vlan_id = cpu_to_be16(key->vlan_id); vf->data.tcp_spec.vlan_id = cpu_to_be16(key->vlan_id);
} }
if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_CONTROL)) { if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_CONTROL)) {
...@@ -2667,14 +2666,12 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter, ...@@ -2667,14 +2666,12 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter,
return I40E_ERR_CONFIG; return I40E_ERR_CONFIG;
} }
if (key->dst) { if (key->dst) {
filter->f.mask.tcp_spec.dst_ip[0] |= vf->mask.tcp_spec.dst_ip[0] |= cpu_to_be32(0xffffffff);
cpu_to_be32(0xffffffff); vf->data.tcp_spec.dst_ip[0] = key->dst;
filter->f.data.tcp_spec.dst_ip[0] = key->dst;
} }
if (key->src) { if (key->src) {
filter->f.mask.tcp_spec.src_ip[0] |= vf->mask.tcp_spec.src_ip[0] |= cpu_to_be32(0xffffffff);
cpu_to_be32(0xffffffff); vf->data.tcp_spec.src_ip[0] = key->src;
filter->f.data.tcp_spec.src_ip[0] = key->src;
} }
} }
...@@ -2707,22 +2704,14 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter, ...@@ -2707,22 +2704,14 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter,
if (!ipv6_addr_any(&mask->dst) || !ipv6_addr_any(&mask->src)) if (!ipv6_addr_any(&mask->dst) || !ipv6_addr_any(&mask->src))
field_flags |= I40EVF_CLOUD_FIELD_IIP; field_flags |= I40EVF_CLOUD_FIELD_IIP;
if (key->dst.s6_addr) {
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
filter->f.mask.tcp_spec.dst_ip[i] |= vf->mask.tcp_spec.dst_ip[i] |= cpu_to_be32(0xffffffff);
cpu_to_be32(0xffffffff); memcpy(&vf->data.tcp_spec.dst_ip, &key->dst.s6_addr32,
memcpy(&filter->f.data.tcp_spec.dst_ip, sizeof(vf->data.tcp_spec.dst_ip));
&key->dst.s6_addr32,
sizeof(filter->f.data.tcp_spec.dst_ip));
}
if (key->src.s6_addr) {
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
filter->f.mask.tcp_spec.src_ip[i] |= vf->mask.tcp_spec.src_ip[i] |= cpu_to_be32(0xffffffff);
cpu_to_be32(0xffffffff); memcpy(&vf->data.tcp_spec.src_ip, &key->src.s6_addr32,
memcpy(&filter->f.data.tcp_spec.src_ip, sizeof(vf->data.tcp_spec.src_ip));
&key->src.s6_addr32,
sizeof(filter->f.data.tcp_spec.src_ip));
}
} }
if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_PORTS)) { if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_PORTS)) {
struct flow_dissector_key_ports *key = struct flow_dissector_key_ports *key =
...@@ -2754,16 +2743,16 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter, ...@@ -2754,16 +2743,16 @@ static int i40evf_parse_cls_flower(struct i40evf_adapter *adapter,
} }
} }
if (key->dst) { if (key->dst) {
filter->f.mask.tcp_spec.dst_port |= cpu_to_be16(0xffff); vf->mask.tcp_spec.dst_port |= cpu_to_be16(0xffff);
filter->f.data.tcp_spec.dst_port = key->dst; vf->data.tcp_spec.dst_port = key->dst;
} }
if (key->src) { if (key->src) {
filter->f.mask.tcp_spec.src_port |= cpu_to_be16(0xffff); vf->mask.tcp_spec.src_port |= cpu_to_be16(0xffff);
filter->f.data.tcp_spec.src_port = key->dst; vf->data.tcp_spec.src_port = key->dst;
} }
} }
filter->f.field_flags = field_flags; vf->field_flags = field_flags;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment