Commit a188a54d authored by dingtianhong's avatar dingtianhong Committed by David S. Miller

macvlan: simplify the structure port

The port->count was used to count the number of macvlan devs
in the same port, but the list vlans could play the same role
to do that, so free the port if the list vlans is empty and
no need to use the parameter count.
Signed-off-by: default avatarDing Tianhong <dingtianhong@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 112a3513
...@@ -44,9 +44,10 @@ struct macvlan_port { ...@@ -44,9 +44,10 @@ struct macvlan_port {
struct sk_buff_head bc_queue; struct sk_buff_head bc_queue;
struct work_struct bc_work; struct work_struct bc_work;
bool passthru; bool passthru;
int count;
}; };
#define MACVLAN_PORT_IS_EMPTY(port) list_empty(&port->vlans)
struct macvlan_skb_cb { struct macvlan_skb_cb {
const struct macvlan_dev *src; const struct macvlan_dev *src;
}; };
...@@ -628,8 +629,7 @@ static void macvlan_uninit(struct net_device *dev) ...@@ -628,8 +629,7 @@ static void macvlan_uninit(struct net_device *dev)
free_percpu(vlan->pcpu_stats); free_percpu(vlan->pcpu_stats);
port->count -= 1; if (MACVLAN_PORT_IS_EMPTY(port))
if (!port->count)
macvlan_port_destroy(port->dev); macvlan_port_destroy(port->dev);
} }
...@@ -931,13 +931,12 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev, ...@@ -931,13 +931,12 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
vlan->flags = nla_get_u16(data[IFLA_MACVLAN_FLAGS]); vlan->flags = nla_get_u16(data[IFLA_MACVLAN_FLAGS]);
if (vlan->mode == MACVLAN_MODE_PASSTHRU) { if (vlan->mode == MACVLAN_MODE_PASSTHRU) {
if (port->count) if (!MACVLAN_PORT_IS_EMPTY(port))
return -EINVAL; return -EINVAL;
port->passthru = true; port->passthru = true;
eth_hw_addr_inherit(dev, lowerdev); eth_hw_addr_inherit(dev, lowerdev);
} }
port->count += 1;
err = register_netdevice(dev); err = register_netdevice(dev);
if (err < 0) if (err < 0)
goto destroy_port; goto destroy_port;
...@@ -955,8 +954,7 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev, ...@@ -955,8 +954,7 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
unregister_netdev: unregister_netdev:
unregister_netdevice(dev); unregister_netdevice(dev);
destroy_port: destroy_port:
port->count -= 1; if (MACVLAN_PORT_IS_EMPTY(port))
if (!port->count)
macvlan_port_destroy(lowerdev); 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