OSDN Git Service

mlxsw: spectrum: Generalize split count check
authorJiri Pirko <jiri@mellanox.com>
Thu, 31 Oct 2019 09:42:21 +0000 (11:42 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 31 Oct 2019 17:54:47 +0000 (10:54 -0700)
Make the check generic for any possible value, not only 2 and 4.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Reviewed-by: Shalom Toledo <shalomt@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum.c

index 3ce48d0..ea4cc2a 100644 (file)
@@ -4215,9 +4215,9 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port,
                return -EINVAL;
        }
 
-       if (count != 2 && count != 4) {
-               netdev_err(mlxsw_sp_port->dev, "Port can only be split into 2 or 4 ports\n");
-               NL_SET_ERR_MSG_MOD(extack, "Port can only be split into 2 or 4 ports");
+       if (count == 1 || !is_power_of_2(count) || count > max_width) {
+               netdev_err(mlxsw_sp_port->dev, "Invalid split count\n");
+               NL_SET_ERR_MSG_MOD(extack, "Invalid split count");
                return -EINVAL;
        }