netdev: Safely increment refcount in netdev_open().
authorJoe Stringer <joestringer@nicira.com>
Thu, 1 May 2014 23:55:05 +0000 (11:55 +1200)
committerJoe Stringer <joestringer@nicira.com>
Sun, 4 May 2014 23:20:43 +0000 (11:20 +1200)
netdev_open() would previously increment a netdev's refcount without
holding a lock for it. This commit shifts the locking to protect it.

Found by inspection.

Signed-off-by: Joe Stringer <joestringer@nicira.com>
Reviewed-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Acked-by: Ben Pfaff <blp@nicira.com>
lib/netdev.c

index 2466c2b..5bf2220 100644 (file)
@@ -387,15 +387,15 @@ netdev_open(const char *name, const char *type, struct netdev **netdevp)
         error = 0;
     }
 
-    ovs_mutex_unlock(&netdev_mutex);
-    ovs_mutex_unlock(&netdev_class_mutex);
-
     if (!error) {
         netdev->ref_cnt++;
         *netdevp = netdev;
     } else {
         *netdevp = NULL;
     }
+    ovs_mutex_unlock(&netdev_mutex);
+    ovs_mutex_unlock(&netdev_class_mutex);
+
     return error;
 }