net: dsa: simplify netdevice events handling
Simplify the code handling the slave netdevice notifier call by providing a dsa_slave_changeupper helper for NETDEV_CHANGEUPPER, and so on (only this event is supported at the moment.) Return NOTIFY_DONE when we did not care about an event, and NOTIFY_OK when we were concerned but no error occurred, as the API suggests. Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
88e4f0ca4e
commit
8e92ab3a42
@ -1491,37 +1491,22 @@ static bool dsa_slave_dev_check(struct net_device *dev)
|
|||||||
return dev->netdev_ops == &dsa_slave_netdev_ops;
|
return dev->netdev_ops == &dsa_slave_netdev_ops;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dsa_slave_port_upper_event(struct net_device *dev,
|
static int dsa_slave_changeupper(struct net_device *dev,
|
||||||
unsigned long event, void *ptr)
|
struct netdev_notifier_changeupper_info *info)
|
||||||
{
|
{
|
||||||
struct netdev_notifier_changeupper_info *info = ptr;
|
int err = NOTIFY_DONE;
|
||||||
struct net_device *upper = info->upper_dev;
|
|
||||||
int err = 0;
|
|
||||||
|
|
||||||
switch (event) {
|
if (netif_is_bridge_master(info->upper_dev)) {
|
||||||
case NETDEV_CHANGEUPPER:
|
if (info->linking) {
|
||||||
if (netif_is_bridge_master(upper)) {
|
err = dsa_slave_bridge_port_join(dev, info->upper_dev);
|
||||||
if (info->linking)
|
err = notifier_from_errno(err);
|
||||||
err = dsa_slave_bridge_port_join(dev, upper);
|
} else {
|
||||||
else
|
dsa_slave_bridge_port_leave(dev, info->upper_dev);
|
||||||
dsa_slave_bridge_port_leave(dev, upper);
|
err = NOTIFY_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return notifier_from_errno(err);
|
return err;
|
||||||
}
|
|
||||||
|
|
||||||
static int dsa_slave_port_event(struct net_device *dev, unsigned long event,
|
|
||||||
void *ptr)
|
|
||||||
{
|
|
||||||
switch (event) {
|
|
||||||
case NETDEV_CHANGEUPPER:
|
|
||||||
return dsa_slave_port_upper_event(dev, event, ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NOTIFY_DONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dsa_slave_netdevice_event(struct notifier_block *nb,
|
static int dsa_slave_netdevice_event(struct notifier_block *nb,
|
||||||
@ -1529,8 +1514,11 @@ static int dsa_slave_netdevice_event(struct notifier_block *nb,
|
|||||||
{
|
{
|
||||||
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
|
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
|
||||||
|
|
||||||
if (dsa_slave_dev_check(dev))
|
if (dev->netdev_ops != &dsa_slave_netdev_ops)
|
||||||
return dsa_slave_port_event(dev, event, ptr);
|
return NOTIFY_DONE;
|
||||||
|
|
||||||
|
if (event == NETDEV_CHANGEUPPER)
|
||||||
|
return dsa_slave_changeupper(dev, ptr);
|
||||||
|
|
||||||
return NOTIFY_DONE;
|
return NOTIFY_DONE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user