diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c index fa86a1466718..ae11678a31e8 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c @@ -2608,18 +2608,18 @@ int mlx5e_configure_flower(struct mlx5e_priv *priv, if (err != -EAGAIN) flow->flags |= MLX5E_TC_FLOW_OFFLOADED; - err = rhashtable_insert_fast(&tc->ht, &flow->node, - tc->ht_params); - if (err) - goto err_del_rule; - - if (flow->flags & MLX5E_TC_FLOW_ESWITCH && + if (!(flow->flags & MLX5E_TC_FLOW_ESWITCH) || !(flow->esw_attr->action & MLX5_FLOW_CONTEXT_ACTION_ENCAP)) kvfree(parse_attr); - return err; -err_del_rule: - mlx5e_tc_del_flow(priv, flow); + err = rhashtable_insert_fast(&tc->ht, &flow->node, + tc->ht_params); + if (err) { + mlx5e_tc_del_flow(priv, flow); + kfree(flow); + } + + return err; err_free: kvfree(parse_attr);