Skip to content

Commit

Permalink
macvlan: use the right RCU api
Browse files Browse the repository at this point in the history
Make sure we use proper API to fetch dev->rx_handler_data,
instead of ugly casts.

Rename macvlan_port_get() to macvlan_port_get_rtnl() to document fact
that we hold RTNL when needed, with lockdep support.

This removes sparse warnings as well (CONFIG_SPARSE_RCU_POINTER=y)

CHECK   drivers/net/macvlan.c
drivers/net/macvlan.c:706:37: warning: cast removes address space of expression
drivers/net/macvlan.c:775:16: warning: cast removes address space of expression
drivers/net/macvlan.c:924:16: warning: cast removes address space of expression

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Mar 30, 2013
1 parent 4c3d5e7 commit e052f7e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions drivers/net/macvlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,16 @@ struct macvlan_port {

static void macvlan_port_destroy(struct net_device *dev);

#define macvlan_port_get_rcu(dev) \
((struct macvlan_port *) rcu_dereference(dev->rx_handler_data))
#define macvlan_port_get(dev) ((struct macvlan_port *) dev->rx_handler_data)
static struct macvlan_port *macvlan_port_get_rcu(const struct net_device *dev)
{
return rcu_dereference(dev->rx_handler_data);
}

static struct macvlan_port *macvlan_port_get_rtnl(const struct net_device *dev)
{
return rtnl_dereference(dev->rx_handler_data);
}

#define macvlan_port_exists(dev) (dev->priv_flags & IFF_MACVLAN_PORT)

static struct macvlan_dev *macvlan_hash_lookup(const struct macvlan_port *port,
Expand Down Expand Up @@ -703,7 +710,7 @@ static int macvlan_port_create(struct net_device *dev)

static void macvlan_port_destroy(struct net_device *dev)
{
struct macvlan_port *port = macvlan_port_get(dev);
struct macvlan_port *port = macvlan_port_get_rtnl(dev);

dev->priv_flags &= ~IFF_MACVLAN_PORT;
netdev_rx_handler_unregister(dev);
Expand Down Expand Up @@ -772,7 +779,7 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
if (err < 0)
return err;
}
port = macvlan_port_get(lowerdev);
port = macvlan_port_get_rtnl(lowerdev);

/* Only 1 macvlan device can be created in passthru mode */
if (port->passthru)
Expand Down Expand Up @@ -921,7 +928,7 @@ static int macvlan_device_event(struct notifier_block *unused,
if (!macvlan_port_exists(dev))
return NOTIFY_DONE;

port = macvlan_port_get(dev);
port = macvlan_port_get_rtnl(dev);

switch (event) {
case NETDEV_CHANGE:
Expand Down

0 comments on commit e052f7e

Please sign in to comment.