diff mbox

[next] ipvlan: Fix failure path in dev registration during link creation

Message ID 1461782259-10806-1-git-send-email-mahesh@bandewar.net
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Mahesh Bandewar April 27, 2016, 6:37 p.m. UTC
From: Mahesh Bandewar <maheshb@google.com>

When newlink creation fails at device-registration, the port->count
is decremented twice. Francesco Ruggeri (fruggeri@arista.com) found
this issue in Macvlan and the same exists in IPvlan driver too.

While fixing this issue I noticed another issue of missing unregister
in case of failure, so adding it to the fix which is similar to the
macvlan fix by Francesco in SHA1:308379607548524b8d86dbf20134681024935e0b

Reported-by: Francesco Ruggeri <fruggeri@arista.com>
Signed-off-by: Mahesh Bandewar <maheshb@google.com>
CC: Eric Dumazet <edumazet@google.com>
CC: Eric W. Biederman <ebiederm@xmission.com>
---
 drivers/net/ipvlan/ipvlan_main.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

Comments

David Miller April 27, 2016, 6:57 p.m. UTC | #1
From: Mahesh Bandewar <mahesh@bandewar.net>
Date: Wed, 27 Apr 2016 11:37:39 -0700

> While fixing this issue I noticed another issue of missing unregister
> in case of failure, so adding it to the fix which is similar to the
> macvlan fix by Francesco in SHA1:308379607548524b8d86dbf20134681024935e0b

This is not the correct way to refer to commits.

You should specify, exactly, 12 digits of the SHA1 value, followed by
a space, followed by the header line text of that commit contained in
parenthesis and double quotes, like how Fixes: tags specify commits.
On Wed, Apr 27, 2016 at 11:57 AM, David Miller <davem@davemloft.net> wrote:
> From: Mahesh Bandewar <mahesh@bandewar.net>
> Date: Wed, 27 Apr 2016 11:37:39 -0700
>
>> While fixing this issue I noticed another issue of missing unregister
>> in case of failure, so adding it to the fix which is similar to the
>> macvlan fix by Francesco in SHA1:308379607548524b8d86dbf20134681024935e0b
>
> This is not the correct way to refer to commits.
>
> You should specify, exactly, 12 digits of the SHA1 value, followed by
> a space, followed by the header line text of that commit contained in
> parenthesis and double quotes, like how Fixes: tags specify commits.
Ok, will fix that soon.
diff mbox

Patch

diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c
index 57941d3f4227..1c4d395fbd49 100644
--- a/drivers/net/ipvlan/ipvlan_main.c
+++ b/drivers/net/ipvlan/ipvlan_main.c
@@ -113,6 +113,7 @@  static int ipvlan_init(struct net_device *dev)
 {
 	struct ipvl_dev *ipvlan = netdev_priv(dev);
 	const struct net_device *phy_dev = ipvlan->phy_dev;
+	struct ipvl_port *port = ipvlan->port;
 
 	dev->state = (dev->state & ~IPVLAN_STATE_MASK) |
 		     (phy_dev->state & IPVLAN_STATE_MASK);
@@ -128,6 +129,8 @@  static int ipvlan_init(struct net_device *dev)
 	if (!ipvlan->pcpu_stats)
 		return -ENOMEM;
 
+	port->count += 1;
+
 	return 0;
 }
 
@@ -481,27 +484,21 @@  static int ipvlan_link_new(struct net *src_net, struct net_device *dev,
 
 	dev->priv_flags |= IFF_IPVLAN_SLAVE;
 
-	port->count += 1;
 	err = register_netdevice(dev);
 	if (err < 0)
-		goto ipvlan_destroy_port;
+		return err;
 
 	err = netdev_upper_dev_link(phy_dev, dev);
-	if (err)
-		goto ipvlan_destroy_port;
+	if (err) {
+		unregister_netdevice(dev);
+		return err;
+	}
 
 	list_add_tail_rcu(&ipvlan->pnode, &port->ipvlans);
 	ipvlan_set_port_mode(port, mode);
 
 	netif_stacked_transfer_operstate(phy_dev, dev);
 	return 0;
-
-ipvlan_destroy_port:
-	port->count -= 1;
-	if (!port->count)
-		ipvlan_port_destroy(phy_dev);
-
-	return err;
 }
 
 static void ipvlan_link_delete(struct net_device *dev, struct list_head *head)