ofproto-dpif-xlate: Initialize '*xout' all together at beginning.
authorBen Pfaff <blp@nicira.com>
Thu, 30 Jul 2015 05:31:07 +0000 (22:31 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 31 Jul 2015 20:08:08 +0000 (13:08 -0700)
To my mind, this is a good way to ensure that '*xout' gets initialized
properly in every execution.  By using an initializer rather than a
series of assignment statements, we can be assured that every member
gets initialized.

This commit makes xlate_actions() more expensive because struct
xlate_out is large and this assignment will initialize all of it due to
C rules.  Later commits will fix this up by removing all of the large
members, reducing xlate_out to only a few bytes total.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
ofproto/ofproto-dpif-xlate.c

index 125d4c6..b6d5d15 100644 (file)
@@ -4720,6 +4720,17 @@ too_many_output_actions(const struct ofpbuf *odp_actions OVS_UNUSED)
 void
 xlate_actions(struct xlate_in *xin, struct xlate_out *xout)
 {
+    *xout = (struct xlate_out) {
+        .slow = 0,
+        .fail_open = false,
+        .has_learn = false,
+        .has_normal = false,
+        .has_fin_timeout = false,
+        .nf_output_iface = NF_OUT_DROP,
+        .mirrors = 0,
+        .n_recircs = 0,
+    };
+
     struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
     struct flow_wildcards *wc = NULL;
     struct flow *flow = &xin->flow;
@@ -4760,13 +4771,6 @@ xlate_actions(struct xlate_in *xin, struct xlate_out *xout)
 
     ctx.xin = xin;
     ctx.xout = xout;
-    ctx.xout->slow = 0;
-    ctx.xout->has_learn = false;
-    ctx.xout->has_normal = false;
-    ctx.xout->has_fin_timeout = false;
-    ctx.xout->nf_output_iface = NF_OUT_DROP;
-    ctx.xout->mirrors = 0;
-    ctx.xout->n_recircs = 0;
 
     xout->odp_actions = xin->odp_actions;
     if (!xout->odp_actions) {