[ovs-dev] [PATCH-branch-2.1] netdev: Safely increment refcount in netdev_open().

Joe Stringer joestringer at nicira.com
Sun May 4 23:36:19 UTC 2014


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 at nicira.com>
---
 lib/netdev.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/netdev.c b/lib/netdev.c
index 1bcd80f..fd20b05 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -352,15 +352,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;
 }
 
-- 
1.7.10.4




More information about the dev mailing list