[ovs-dev] [PATCH] dpif-netdev: Move 'struct dp_netdev_port' initialization before use.

Alex Wang alexw at nicira.com
Sat Nov 8 01:51:18 UTC 2014


There is a portion of the 'struct dp_netdev_port' initialization
that is placed after the reload of pmd threads.  This means in
theory, there could be a race where pmd threads access half-
initialized struct.  Although such race has not been seen, it
makes sense to fully initialize the struct before use.

Found by code inspection.

Signed-off-by: Alex Wang <alexw at nicira.com>
---
 lib/dpif-netdev.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index ad2febc..9d1319f 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -871,13 +871,13 @@ do_add_port(struct dp_netdev *dp, const char *devname, const char *type,
     }
     port->sf = sf;
 
+    ovs_refcount_init(&port->ref_cnt);
+    cmap_insert(&dp->ports, &port->node, hash_port_no(port_no));
+
     if (netdev_is_pmd(netdev)) {
         dp_netdev_set_pmds_on_numa(dp, netdev_get_numa_id(netdev));
         dp_netdev_reload_pmds(dp);
     }
-    ovs_refcount_init(&port->ref_cnt);
-
-    cmap_insert(&dp->ports, &port->node, hash_port_no(port_no));
     seq_change(dp->port_seq);
 
     return 0;
-- 
1.7.9.5




More information about the dev mailing list