From: Joe Stringer Date: Thu, 1 May 2014 23:55:05 +0000 (+1200) Subject: netdev: Safely increment refcount in netdev_open(). X-Git-Tag: v2.3~177 X-Git-Url: http://git.cascardo.eti.br/?a=commitdiff_plain;h=ca94dda64d82fc7a65e8de2c1479e7c83bdc152b;p=cascardo%2Fovs.git netdev: Safely increment refcount in netdev_open(). 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 Reviewed-by: YAMAMOTO Takashi Acked-by: Ben Pfaff --- diff --git a/lib/netdev.c b/lib/netdev.c index 2466c2bfb..5bf2220c4 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -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; }