mlxsw: spectrum: Move port used check outside port remove function
authorJiri Pirko <jiri@mellanox.com>
Fri, 28 Oct 2016 19:35:49 +0000 (21:35 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sun, 30 Oct 2016 20:50:17 +0000 (16:50 -0400)
Be symmentrical with create and do the check outside the remove function.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Elad Raz <eladr@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum.c

index 2573faaffea8d67a203a4ddec3837082ff837c52..d6490641dd3eb02dbe7610ae1f3edb007e911a6e 100644 (file)
@@ -2403,8 +2403,6 @@ static void mlxsw_sp_port_remove(struct mlxsw_sp *mlxsw_sp, u8 local_port)
 {
        struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp->ports[local_port];
 
-       if (!mlxsw_sp_port)
-               return;
        cancel_delayed_work_sync(&mlxsw_sp_port->hw_stats.update_dw);
        mlxsw_core_port_fini(&mlxsw_sp_port->core_port);
        unregister_netdev(mlxsw_sp_port->dev); /* This calls ndo_stop */
@@ -2422,12 +2420,18 @@ static void mlxsw_sp_port_remove(struct mlxsw_sp *mlxsw_sp, u8 local_port)
        free_netdev(mlxsw_sp_port->dev);
 }
 
+static bool mlxsw_sp_port_created(struct mlxsw_sp *mlxsw_sp, u8 local_port)
+{
+       return mlxsw_sp->ports[local_port] != NULL;
+}
+
 static void mlxsw_sp_ports_remove(struct mlxsw_sp *mlxsw_sp)
 {
        int i;
 
        for (i = 1; i < MLXSW_PORT_MAX_PORTS; i++)
-               mlxsw_sp_port_remove(mlxsw_sp, i);
+               if (mlxsw_sp_port_created(mlxsw_sp, i))
+                       mlxsw_sp_port_remove(mlxsw_sp, i);
        kfree(mlxsw_sp->ports);
 }
 
@@ -2461,7 +2465,8 @@ static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp)
 err_port_create:
 err_port_module_info_get:
        for (i--; i >= 1; i--)
-               mlxsw_sp_port_remove(mlxsw_sp, i);
+               if (mlxsw_sp_port_created(mlxsw_sp, i))
+                       mlxsw_sp_port_remove(mlxsw_sp, i);
        kfree(mlxsw_sp->ports);
        return err;
 }
@@ -2503,7 +2508,8 @@ static int mlxsw_sp_port_split_create(struct mlxsw_sp *mlxsw_sp, u8 base_port,
 
 err_port_create:
        for (i--; i >= 0; i--)
-               mlxsw_sp_port_remove(mlxsw_sp, base_port + i);
+               if (mlxsw_sp_port_created(mlxsw_sp, base_port + i))
+                       mlxsw_sp_port_remove(mlxsw_sp, base_port + i);
        i = count;
 err_port_swid_set:
        for (i--; i >= 0; i--)
@@ -2593,7 +2599,8 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port,
        }
 
        for (i = 0; i < count; i++)
-               mlxsw_sp_port_remove(mlxsw_sp, base_port + i);
+               if (mlxsw_sp_port_created(mlxsw_sp, base_port + i))
+                       mlxsw_sp_port_remove(mlxsw_sp, base_port + i);
 
        err = mlxsw_sp_port_split_create(mlxsw_sp, base_port, module, count);
        if (err) {
@@ -2638,7 +2645,8 @@ static int mlxsw_sp_port_unsplit(struct mlxsw_core *mlxsw_core, u8 local_port)
                base_port = base_port + 2;
 
        for (i = 0; i < count; i++)
-               mlxsw_sp_port_remove(mlxsw_sp, base_port + i);
+               if (mlxsw_sp_port_created(mlxsw_sp, base_port + i))
+                       mlxsw_sp_port_remove(mlxsw_sp, base_port + i);
 
        mlxsw_sp_port_unsplit_create(mlxsw_sp, base_port, count);