[ovs-dev] [PATCH v2 2/2] flow: Add helper to zero padding of flow

Simon Horman horms at verge.net.au
Wed Sep 25 04:31:08 UTC 2013


The sole purpose of this change is to avoid sparse warnings
about memset of zero length in the case where the zero field
of struct flow is zero bytes long, as is the case after
"Remove mpls_depth field from flow".

Signed-off-by: Simon Horman <horms at verge.net.au>

---

This patch could trivially be: applied as-is; trivially up-dated
so that it can be applied before "Remove mpls_depth field from flow."
which would also need to be trivially updated; or dropped entirely.
I am equally comfortable with any of those options.

v2
* First post
---
 lib/flow.c             |  2 +-
 lib/flow.h             | 14 +++++++++++++-
 tests/test-bundle.c    |  2 +-
 tests/test-multipath.c |  2 +-
 4 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/lib/flow.c b/lib/flow.c
index ef10964..5b39e58 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -611,7 +611,7 @@ void
 flow_wildcards_init_exact(struct flow_wildcards *wc)
 {
     memset(&wc->masks, 0xff, sizeof wc->masks);
-    memset(wc->masks.zeros, 0, sizeof wc->masks.zeros);
+    flow_zero_padding(&wc->masks);
 }
 
 /* Returns true if 'wc' matches every packet, false if 'wc' fixes any bits or
diff --git a/lib/flow.h b/lib/flow.h
index fbb413d..1e321a6 100644
--- a/lib/flow.h
+++ b/lib/flow.h
@@ -76,6 +76,8 @@ union flow_in_port {
     odp_port_t odp_port;
 };
 
+#define FLOW_PAD_BYTES 0
+
 /*
 * A flow in the network.
 *
@@ -110,7 +112,7 @@ struct flow {
     uint8_t arp_tha[6];         /* ARP/ND target hardware address. */
     uint8_t nw_ttl;             /* IP TTL/Hop Limit. */
     uint8_t nw_frag;            /* FLOW_FRAG_* flags. */
-    uint8_t zeros[0];
+    uint8_t zeros[FLOW_PAD_BYTES];
 };
 BUILD_ASSERT_DECL(sizeof(struct flow) % 4 == 0);
 
@@ -135,6 +137,7 @@ void flow_extract(struct ofpbuf *, uint32_t priority, uint32_t mark,
                   const struct flow_tnl *, const union flow_in_port *in_port,
                   struct flow *);
 
+static inline void flow_zero_padding(struct flow *);
 void flow_zero_wildcards(struct flow *, const struct flow_wildcards *);
 void flow_get_metadata(const struct flow *, struct flow_metadata *);
 
@@ -159,6 +162,15 @@ void flow_set_mpls_bos(struct flow *flow, uint8_t stack);
 
 void flow_compose(struct ofpbuf *, const struct flow *);
 
+#if FLOW_PAD_BYTES > 0
+static inline void flow_zero_padding(struct flow *flow)
+{
+    memset(flows->zeros, 0, sizeof flows->zeros);
+}
+#else
+static inline void flow_zero_padding(struct flow *flow OVS_UNUSED) { }
+#endif
+
 static inline int
 flow_compare_3way(const struct flow *a, const struct flow *b)
 {
diff --git a/tests/test-bundle.c b/tests/test-bundle.c
index c901bfc..35a13b5 100644
--- a/tests/test-bundle.c
+++ b/tests/test-bundle.c
@@ -141,7 +141,7 @@ main(int argc, char *argv[])
     flows = xmalloc(N_FLOWS * sizeof *flows);
     for (i = 0; i < N_FLOWS; i++) {
         random_bytes(&flows[i], sizeof flows[i]);
-        memset(flows[i].zeros, 0, sizeof flows[i].zeros);
+        flow_zero_padding(&flows[i]);
         flows[i].regs[0] = ofp_to_u16(OFPP_NONE);
     }
 
diff --git a/tests/test-multipath.c b/tests/test-multipath.c
index f5298bf..32fbd79 100644
--- a/tests/test-multipath.c
+++ b/tests/test-multipath.c
@@ -66,7 +66,7 @@ main(int argc, char *argv[])
             struct flow flow;
 
             random_bytes(&flow, sizeof flow);
-            memset(flow.zeros, 0, sizeof flow.zeros);
+            flow_zero_padding(&flow);
 
             mp.max_link = n - 1;
             multipath_execute(&mp, &flow, &wc);
-- 
1.8.4




More information about the dev mailing list