Skip to content

Commit

Permalink
net: dsa: walk through all changeupper notifier functions
Browse files Browse the repository at this point in the history
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: Vladimir Oltean <[email protected]>
Reviewed-by: Florian Fainelli <[email protected]>
Signed-off-by: Paolo Abeni <[email protected]>
  • Loading branch information
vladimiroltean authored and Paolo Abeni committed Aug 23, 2022
1 parent 139b5fb commit 4c3f80d
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions net/dsa/slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4c3f80d

Please sign in to comment.