Commit 4c3f80d2 authored by Vladimir Oltean's avatar Vladimir Oltean Committed by Paolo Abeni

net: dsa: walk through all changeupper notifier functions

Traditionally, DSA has had a single netdev notifier handling function
for each device type.

For the sake of code cleanliness, we would like to introduce more
handling functions which do one thing, but the conditions for entering
these functions start to overlap. Example: a handling function which
tracks whether any bridges contain both DSA and non-DSA interfaces.
Either this is placed before dsa_slave_changeupper(), case in which it
will prevent that function from executing, or we place it after
dsa_slave_changeupper(), case in which we will prevent it from
executing. The other alternative is to ignore errors from the new
handling function (not ideal).

To support this usage, we need to change the pattern. In the new model,
we enter all notifier handling sub-functions, and exit with NOTIFY_DONE
if there is nothing to do. This allows the sub-functions to be
relatively free-form and independent from each other.
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent 139b5fbd
......@@ -2476,6 +2476,9 @@ static int dsa_slave_changeupper(struct net_device *dev,
struct netlink_ext_ack *extack;
int err = NOTIFY_DONE;
if (!dsa_slave_dev_check(dev))
return err;
extack = netdev_notifier_info_to_extack(&info->info);
if (netif_is_bridge_master(info->upper_dev)) {
......@@ -2531,6 +2534,9 @@ static int dsa_slave_prechangeupper(struct net_device *dev,
{
struct dsa_port *dp = dsa_slave_to_port(dev);
if (!dsa_slave_dev_check(dev))
return NOTIFY_DONE;
if (netif_is_bridge_master(info->upper_dev) && !info->linking)
dsa_port_pre_bridge_leave(dp, info->upper_dev);
else if (netif_is_lag_master(info->upper_dev) && !info->linking)
......@@ -2551,6 +2557,9 @@ dsa_slave_lag_changeupper(struct net_device *dev,
int err = NOTIFY_DONE;
struct dsa_port *dp;
if (!netif_is_lag_master(dev))
return err;
netdev_for_each_lower_dev(dev, lower, iter) {
if (!dsa_slave_dev_check(lower))
continue;
......@@ -2580,6 +2589,9 @@ dsa_slave_lag_prechangeupper(struct net_device *dev,
int err = NOTIFY_DONE;
struct dsa_port *dp;
if (!netif_is_lag_master(dev))
return err;
netdev_for_each_lower_dev(dev, lower, iter) {
if (!dsa_slave_dev_check(lower))
continue;
......@@ -2701,22 +2713,29 @@ static int dsa_slave_netdevice_event(struct notifier_block *nb,
if (err != NOTIFY_DONE)
return err;
if (dsa_slave_dev_check(dev))
return dsa_slave_prechangeupper(dev, ptr);
err = dsa_slave_prechangeupper(dev, ptr);
if (notifier_to_errno(err))
return err;
if (netif_is_lag_master(dev))
return dsa_slave_lag_prechangeupper(dev, ptr);
err = dsa_slave_lag_prechangeupper(dev, ptr);
if (notifier_to_errno(err))
return err;
break;
}
case NETDEV_CHANGEUPPER:
if (dsa_slave_dev_check(dev))
return dsa_slave_changeupper(dev, ptr);
case NETDEV_CHANGEUPPER: {
int err;
err = dsa_slave_changeupper(dev, ptr);
if (notifier_to_errno(err))
return err;
if (netif_is_lag_master(dev))
return dsa_slave_lag_changeupper(dev, ptr);
err = dsa_slave_lag_changeupper(dev, ptr);
if (notifier_to_errno(err))
return err;
break;
}
case NETDEV_CHANGELOWERSTATE: {
struct netdev_notifier_changelowerstate_info *info = ptr;
struct dsa_port *dp;
......
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