Skip to content

Commit

Permalink
macvlan: simplify the structure port
Browse files Browse the repository at this point in the history
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: Ding Tianhong <dingtianhong@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
dingtianhong authored and davem330 committed May 16, 2014
1 parent 112a351 commit a188a54
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions drivers/net/macvlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ struct macvlan_port {
struct sk_buff_head bc_queue;
struct work_struct bc_work;
bool passthru;
int count;
};

#define MACVLAN_PORT_IS_EMPTY(port) list_empty(&port->vlans)

struct macvlan_skb_cb {
const struct macvlan_dev *src;
};
Expand Down Expand Up @@ -628,8 +629,7 @@ static void macvlan_uninit(struct net_device *dev)

free_percpu(vlan->pcpu_stats);

port->count -= 1;
if (!port->count)
if (MACVLAN_PORT_IS_EMPTY(port))
macvlan_port_destroy(port->dev);
}

Expand Down Expand Up @@ -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]);

if (vlan->mode == MACVLAN_MODE_PASSTHRU) {
if (port->count)
if (!MACVLAN_PORT_IS_EMPTY(port))
return -EINVAL;
port->passthru = true;
eth_hw_addr_inherit(dev, lowerdev);
}

port->count += 1;
err = register_netdevice(dev);
if (err < 0)
goto destroy_port;
Expand All @@ -955,8 +954,7 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
unregister_netdev:
unregister_netdevice(dev);
destroy_port:
port->count -= 1;
if (!port->count)
if (MACVLAN_PORT_IS_EMPTY(port))
macvlan_port_destroy(lowerdev);

return err;
Expand Down

0 comments on commit a188a54

Please sign in to comment.