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>
Mon, 5 May 2014 00:21:13 +0000 (12:21 +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>
Acked-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
lib/netdev.c

index 5ed6062..f1b7dbe 100644 (file)
@@ -349,15 +349,15 @@ netdev_open(const char *name, const char *type, struct netdev **netdevp)
         error = 0;
     }
 
-    ovs_mutex_unlock(&netdev_mutex);
-    ovs_rwlock_unlock(&netdev_class_rwlock);
-
     if (!error) {
         netdev->ref_cnt++;
         *netdevp = netdev;
     } else {
         *netdevp = NULL;
     }
+    ovs_mutex_unlock(&netdev_mutex);
+    ovs_rwlock_unlock(&netdev_class_rwlock);
+
     return error;
 }