Skip to contentSkip to conversation

net: openvswitch: pass NULL for unused parameters

PATCH Superseded [email protected] 2 participants 3 messages Aug 30, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: openvswitch: pass NULL for unused parameters

From: Tom Rix <[email protected]>

clang static analysis flags these problems

flow_table.c:713:2: warning: The expression is an uninitialized
value. The computed value will also be garbage

        (*n_mask_hit)++;
        ^~~~~~~~~~~~~~~
flow_table.c:748:5: warning: The expression is an uninitialized
  value. The computed value will also be garbage
                                (*n_cache_hit)++;
                                ^~~~~~~~~~~~~~~~

These are not problems because neither pararmeter is used by the calling function.

Looking at all of the calling functions, there are many cases where the results are unused. Passing unused parameters is a waste.

To avoid passing unused parameters, rework the masked_flow_lookup() and flow_lookup() routines to check for NULL parameters and change the unused parameters to NULL.

---
 net/openvswitch/flow_table.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
net/openvswitch/flow_table.c +7 -9
index e2235849a57e..18e7fa3aa67e 100644
@@ -710,7 +710,8 @@ static struct sw_flow *masked_flow_lookup(struct table_instance *ti,
 	ovs_flow_mask_key(&masked_key, unmasked, false, mask);
 	hash = flow_hash(&masked_key, &mask->range);
 	head = find_bucket(ti, hash);
-	(*n_mask_hit)++;
+	if (n_mask_hit)
+		(*n_mask_hit)++;
 
 	hlist_for_each_entry_rcu(flow, head, flow_table.node[ti->node_ver],
 				lockdep_ovsl_is_held()) {
@@ -745,7 +746,8 @@ static struct sw_flow *flow_lookup(struct flow_table *tbl,
 				u64_stats_update_begin(&ma->syncp);
 				usage_counters[*index]++;
 				u64_stats_update_end(&ma->syncp);
-				(*n_cache_hit)++;
+				if (n_cache_hit)
+					(*n_cache_hit)++;
 				return flow;
 			}
 		}
@@ -798,9 +800,8 @@ struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *tbl,
 	*n_cache_hit = 0;
 	if (unlikely(!skb_hash || mc->cache_size == 0)) {
 		u32 mask_index = 0;
-		u32 cache = 0;
 
-		return flow_lookup(tbl, ti, ma, key, n_mask_hit, &cache,
+		return flow_lookup(tbl, ti, ma, key, n_mask_hit, NULL,
 				   &mask_index);
 	}
 
@@ -849,11 +850,9 @@ struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *tbl,
 {
 	struct table_instance *ti = rcu_dereference_ovsl(tbl->ti);
 	struct mask_array *ma = rcu_dereference_ovsl(tbl->mask_array);
-	u32 __always_unused n_mask_hit;
-	u32 __always_unused n_cache_hit;
 	u32 index = 0;
 
-	return flow_lookup(tbl, ti, ma, key, &n_mask_hit, &n_cache_hit, &index);
+	return flow_lookup(tbl, ti, ma, key, NULL, NULL, &index);
 }
 
 struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
@@ -865,7 +864,6 @@ struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
 	/* Always called under ovs-mutex. */
 	for (i = 0; i < ma->max; i++) {
 		struct table_instance *ti = rcu_dereference_ovsl(tbl->ti);
-		u32 __always_unused n_mask_hit;
 		struct sw_flow_mask *mask;
 		struct sw_flow *flow;
 
@@ -873,7 +871,7 @@ struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
 		if (!mask)
 			continue;
 
-		flow = masked_flow_lookup(ti, match->key, mask, &n_mask_hit);
+		flow = masked_flow_lookup(ti, match->key, mask, NULL);
 		if (flow && ovs_identifier_is_key(&flow->id) &&
 		    ovs_flow_cmp_unmasked_key(flow, match)) {
 			return flow;
Signature · 1 line
2.18.1
#1 lore raw
Quoted 7 lines · On Sun, Aug 30, 2020 at 6:17 PM <[email protected]> wrote:

From: Tom Rix <[email protected]>

clang static analysis flags these problems

flow_table.c:713:2: warning: The expression is an uninitialized
value. The computed value will also be garbage

Quoted 8 lines
        (*n_mask_hit)++;
        ^~~~~~~~~~~~~~~
flow_table.c:748:5: warning: The expression is an uninitialized
  value. The computed value will also be garbage
                                (*n_cache_hit)++;
                                ^~~~~~~~~~~~~~~~

These are not problems because neither pararmeter is used

parameter

Quoted 40 lines

by the calling function.

Looking at all of the calling functions, there are many cases where the results are unused. Passing unused parameters is a waste.

To avoid passing unused parameters, rework the masked_flow_lookup() and flow_lookup() routines to check for NULL parameters and change the unused parameters to NULL.

---
 net/openvswitch/flow_table.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
net/openvswitch/flow_table.c +4 -2
index e2235849a57e..18e7fa3aa67e 100644
@@ -710,7 +710,8 @@ static struct sw_flow *masked_flow_lookup(struct table_instance *ti,
        ovs_flow_mask_key(&masked_key, unmasked, false, mask);
        hash = flow_hash(&masked_key, &mask->range);
        head = find_bucket(ti, hash);
-       (*n_mask_hit)++;
+       if (n_mask_hit)
+               (*n_mask_hit)++;
 
        hlist_for_each_entry_rcu(flow, head, flow_table.node[ti->node_ver],
                                lockdep_ovsl_is_held()) {
@@ -745,7 +746,8 @@ static struct sw_flow *flow_lookup(struct flow_table *tbl,
                                u64_stats_update_begin(&ma->syncp);
                                usage_counters[*index]++;
                                u64_stats_update_end(&ma->syncp);
-                               (*n_cache_hit)++;
+                               if (n_cache_hit)
+                                       (*n_cache_hit)++;
                                return flow;
                        }
                }

net/openvswitch/flow_table.c struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *tbl, · line 806

Quoted 9 lines
net/openvswitch/flow_table.c +1 -2
@@ -798,9 +800,8 @@ struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *tbl,
        *n_cache_hit = 0;
 
        if (unlikely(!skb_hash || mc->cache_size == 0)) {
                u32 mask_index = 0;
-               u32 cache = 0;
 
-               return flow_lookup(tbl, ti, ma, key, n_mask_hit, &cache,
+               return flow_lookup(tbl, ti, ma, key, n_mask_hit, NULL,
                                   &mask_index);

Can it be done for mask_index as well?

net/openvswitch/flow_table.c struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *tbl, · line 856

Quoted 13 lines
net/openvswitch/flow_table.c +1 -3
        }
@@ -849,11 +850,9 @@ struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *tbl,
 {
        struct table_instance *ti = rcu_dereference_ovsl(tbl->ti);
        struct mask_array *ma = rcu_dereference_ovsl(tbl->mask_array);
-       u32 __always_unused n_mask_hit;
-       u32 __always_unused n_cache_hit;
        u32 index = 0;
 
 
-       return flow_lookup(tbl, ti, ma, key, &n_mask_hit, &n_cache_hit, &index);
+       return flow_lookup(tbl, ti, ma, key, NULL, NULL, &index);

Ditto.

Quoted 23 lines
net/openvswitch/flow_table.c +0 -0
 }
 

struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,

net/openvswitch/flow_table.c +1 -3
@@ -865,7 +864,6 @@ struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
        /* Always called under ovs-mutex. */
        for (i = 0; i < ma->max; i++) {
                struct table_instance *ti = rcu_dereference_ovsl(tbl->ti);
-               u32 __always_unused n_mask_hit;
                struct sw_flow_mask *mask;
                struct sw_flow *flow;
 
@@ -873,7 +871,7 @@ struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
                if (!mask)
                        continue;
 
-               flow = masked_flow_lookup(ti, match->key, mask, &n_mask_hit);
+               flow = masked_flow_lookup(ti, match->key, mask, NULL);
                if (flow && ovs_identifier_is_key(&flow->id) &&
                    ovs_flow_cmp_unmasked_key(flow, match)) {
                        return flow;
--

2.18.1

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#2 lore raw
Quoted 14 lines · Andy Shevchenko
Quoted 13 lines · On Sun, Aug 30, 2020 at 6:17 PM <[email protected]> wrote:

From: Tom Rix <[email protected]>

clang static analysis flags these problems

flow_table.c:713:2: warning: The expression is an uninitialized
value. The computed value will also be garbage

        (*n_mask_hit)++;
        ^~~~~~~~~~~~~~~
flow_table.c:748:5: warning: The expression is an uninitialized
  value. The computed value will also be garbage
                                (*n_cache_hit)++;
                                ^~~~~~~~~~~~~~~~
Quoted 2 lines
Quoted 1 line

These are not problems because neither pararmeter is used

parameter

Too many ar's, it must be talk like a pirate day.

Quoted 46 lines
Quoted 46 lines

by the calling function.

Looking at all of the calling functions, there are many cases where the results are unused. Passing unused parameters is a waste.

To avoid passing unused parameters, rework the masked_flow_lookup() and flow_lookup() routines to check for NULL parameters and change the unused parameters to NULL.

---
 net/openvswitch/flow_table.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
net/openvswitch/flow_table.c +4 -3
index e2235849a57e..18e7fa3aa67e 100644
@@ -710,7 +710,8 @@ static struct sw_flow *masked_flow_lookup(struct table_instance *ti,
        ovs_flow_mask_key(&masked_key, unmasked, false, mask);
        hash = flow_hash(&masked_key, &mask->range);
        head = find_bucket(ti, hash);
-       (*n_mask_hit)++;
+       if (n_mask_hit)
+               (*n_mask_hit)++;
 
        hlist_for_each_entry_rcu(flow, head, flow_table.node[ti->node_ver],
                                lockdep_ovsl_is_held()) {
@@ -745,7 +746,8 @@ static struct sw_flow *flow_lookup(struct flow_table *tbl,
                                u64_stats_update_begin(&ma->syncp);
                                usage_counters[*index]++;
                                u64_stats_update_end(&ma->syncp);
-                               (*n_cache_hit)++;
+                               if (n_cache_hit)
+                                       (*n_cache_hit)++;
                                return flow;
                        }
                }
@@ -798,9 +800,8 @@ struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *tbl,
        *n_cache_hit = 0;
        if (unlikely(!skb_hash || mc->cache_size == 0)) {
                u32 mask_index = 0;
-               u32 cache = 0;
 
Quoted 4 lines

net/openvswitch/flow_table.c struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *tbl, · line 805

Quoted 3 lines
net/openvswitch/flow_table.c +1 -1
-               return flow_lookup(tbl, ti, ma, key, n_mask_hit, &cache,
+               return flow_lookup(tbl, ti, ma, key, n_mask_hit, NULL,
                                   &mask_index);

Can it be done for mask_index as well?

Yes, it's a bit more complicated but doable.

Tom