Commit 30837960 authored by Francesco Ruggeri's avatar Francesco Ruggeri Committed by David S. Miller

macvlan: fix failure during registration v3

If macvlan_common_newlink fails in register_netdevice after macvlan_init
then it decrements port->count twice, first in macvlan_uninit (from
register_netdevice or rollback_registered) and then again in
macvlan_common_newlink.
A similar problem may exist in the ipvlan driver.
This patch consolidates modifications to port->count into macvlan_init
and macvlan_uninit (thanks to Eric Biederman for suggesting this approach).

v3: remove macvtap specific bits.
Signed-off-by: default avatarFrancesco Ruggeri <fruggeri@arista.com>
Acked-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 713d4ddc
...@@ -795,6 +795,7 @@ static int macvlan_init(struct net_device *dev) ...@@ -795,6 +795,7 @@ static int macvlan_init(struct net_device *dev)
{ {
struct macvlan_dev *vlan = netdev_priv(dev); struct macvlan_dev *vlan = netdev_priv(dev);
const struct net_device *lowerdev = vlan->lowerdev; const struct net_device *lowerdev = vlan->lowerdev;
struct macvlan_port *port = vlan->port;
dev->state = (dev->state & ~MACVLAN_STATE_MASK) | dev->state = (dev->state & ~MACVLAN_STATE_MASK) |
(lowerdev->state & MACVLAN_STATE_MASK); (lowerdev->state & MACVLAN_STATE_MASK);
...@@ -812,6 +813,8 @@ static int macvlan_init(struct net_device *dev) ...@@ -812,6 +813,8 @@ static int macvlan_init(struct net_device *dev)
if (!vlan->pcpu_stats) if (!vlan->pcpu_stats)
return -ENOMEM; return -ENOMEM;
port->count += 1;
return 0; return 0;
} }
...@@ -1312,10 +1315,9 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev, ...@@ -1312,10 +1315,9 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
return err; return err;
} }
port->count += 1;
err = register_netdevice(dev); err = register_netdevice(dev);
if (err < 0) if (err < 0)
goto destroy_port; return err;
dev->priv_flags |= IFF_MACVLAN; dev->priv_flags |= IFF_MACVLAN;
err = netdev_upper_dev_link(lowerdev, dev); err = netdev_upper_dev_link(lowerdev, dev);
...@@ -1330,10 +1332,6 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev, ...@@ -1330,10 +1332,6 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
unregister_netdev: unregister_netdev:
unregister_netdevice(dev); unregister_netdevice(dev);
destroy_port:
port->count -= 1;
if (!port->count)
macvlan_port_destroy(lowerdev);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment