On Thu, Dec 17, 2020 at 03:58:18AM +0200, Vladimir Oltean wrote:
> For many drivers, the .port_mdb_prepare callback was not a good opportunity
> to avoid any error condition, and they would suppress errors found during
> the actual commit phase.
> 
> Where a logical separation between the prepare and the commit phase
> existed, the function that used to implement the .port_mdb_prepare
> callback still exists, but now it is called directly from .port_mdb_add,
> which was modified to return an int code.
> 
> Signed-off-by: Vladimir Oltean <vladimir.olt...@nxp.com>
> ---
[...]
> diff --git a/net/dsa/switch.c b/net/dsa/switch.c
> index 39848eac1da8..65124bc3ddfb 100644
> --- a/net/dsa/switch.c
> +++ b/net/dsa/switch.c
> @@ -178,35 +178,13 @@ static bool dsa_switch_mdb_match(struct dsa_switch *ds, 
> int port,
>       return false;
>  }
>  
> -static int dsa_switch_mdb_prepare(struct dsa_switch *ds,
> -                               struct dsa_notifier_mdb_info *info)
> -{
> -     int port, err;
> -
> -     if (!ds->ops->port_mdb_prepare || !ds->ops->port_mdb_add)
> -             return -EOPNOTSUPP;
> -
> -     for (port = 0; port < ds->num_ports; port++) {
> -             if (dsa_switch_mdb_match(ds, port, info)) {
> -                     err = ds->ops->port_mdb_prepare(ds, port, info->mdb);
> -                     if (err)
> -                             return err;
> -             }
> -     }
> -
> -     return 0;
> -}
> -
>  static int dsa_switch_mdb_add(struct dsa_switch *ds,
>                             struct dsa_notifier_mdb_info *info)
>  {
>       int port;
>  
> -     if (switchdev_trans_ph_prepare(info->trans))
> -             return dsa_switch_mdb_prepare(ds, info);
> -
>       if (!ds->ops->port_mdb_add)
> -             return 0;
> +             return -EOPNOTSUPP;
>  
>       for (port = 0; port < ds->num_ports; port++)
>               if (dsa_switch_mdb_match(ds, port, info))
> -- 
> 2.25.1
> 

For anybody who wants to test, I forgot to update dsa_switch_mdb_add to
propagate the errors. It should look like this:

static int dsa_switch_mdb_add(struct dsa_switch *ds,
                              struct dsa_notifier_mdb_info *info)
{
        int err = 0;
        int port;

        if (!ds->ops->port_mdb_add)
                return -EOPNOTSUPP;

        for (port = 0; port < ds->num_ports; port++) {
                if (dsa_switch_mdb_match(ds, port, info)) {
                        err = ds->ops->port_mdb_add(ds, port, info->mdb);
                        if (err)
                                break;
                }
        }

        return err;
}

Reply via email to