net/mlx5: Move state lock taking into mlx5_sf_dealloc()
authorJiri Pirko <jiri@nvidia.com>
Fri, 2 Jun 2023 13:51:42 +0000 (15:51 +0200)
committerSaeed Mahameed <saeedm@nvidia.com>
Wed, 20 Sep 2023 06:33:06 +0000 (23:33 -0700)
Instead of taking lock and calling mlx5_sf_dealloc(), move the lock
taking into mlx5_sf_dealloc(). The other caller of mlx5_sf_dealloc()
does not need it now, but will need it after a follow-up patch removing
the table reference counting.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Shay Drory <shayd@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c

index 78cdfe595a0191c43d98d196dce7a8a9176fc73f..bed3fe8759d2bf42337f4c8ac615c0a4106c14f7 100644 (file)
@@ -341,6 +341,8 @@ int mlx5_devlink_sf_port_new(struct devlink *devlink,
 
 static void mlx5_sf_dealloc(struct mlx5_sf_table *table, struct mlx5_sf *sf)
 {
+       mutex_lock(&table->sf_state_lock);
+
        mlx5_sf_function_id_erase(table, sf);
 
        if (sf->hw_state == MLX5_VHCA_STATE_ALLOCATED) {
@@ -358,6 +360,8 @@ static void mlx5_sf_dealloc(struct mlx5_sf_table *table, struct mlx5_sf *sf)
                mlx5_sf_hw_table_sf_deferred_free(table->dev, sf->controller, sf->id);
                kfree(sf);
        }
+
+       mutex_unlock(&table->sf_state_lock);
 }
 
 int mlx5_devlink_sf_port_del(struct devlink *devlink,
@@ -377,10 +381,7 @@ int mlx5_devlink_sf_port_del(struct devlink *devlink,
        }
 
        mlx5_eswitch_unload_sf_vport(esw, sf->hw_fn_id);
-
-       mutex_lock(&table->sf_state_lock);
        mlx5_sf_dealloc(table, sf);
-       mutex_unlock(&table->sf_state_lock);
        mlx5_sf_table_put(table);
        return 0;
 }