mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-04 10:56:06 -04:00
net/mlx5: Move ttc allocation after switch case to prevent leaks
Relocate the memory allocation for ttc table after the switch statement
that validates params->ns_type in both mlx5_create_inner_ttc_table() and
mlx5_create_ttc_table(). This ensures memory is only allocated after
confirming valid input, eliminating potential memory leaks when invalid
ns_type cases occur.
Fixes: 137f3d50ad ("net/mlx5: Support matching on l4_type for ttc_table")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Link: https://patch.msgid.link/20250418023814.71789-3-bsdhenrymartin@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
committed by
Jakub Kicinski
parent
91037037ee
commit
fa8fd31512
@@ -637,10 +637,6 @@ struct mlx5_ttc_table *mlx5_create_inner_ttc_table(struct mlx5_core_dev *dev,
|
||||
bool use_l4_type;
|
||||
int err;
|
||||
|
||||
ttc = kvzalloc(sizeof(*ttc), GFP_KERNEL);
|
||||
if (!ttc)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
switch (params->ns_type) {
|
||||
case MLX5_FLOW_NAMESPACE_PORT_SEL:
|
||||
use_l4_type = MLX5_CAP_GEN_2(dev, pcc_ifa2) &&
|
||||
@@ -654,6 +650,10 @@ struct mlx5_ttc_table *mlx5_create_inner_ttc_table(struct mlx5_core_dev *dev,
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
ttc = kvzalloc(sizeof(*ttc), GFP_KERNEL);
|
||||
if (!ttc)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
ns = mlx5_get_flow_namespace(dev, params->ns_type);
|
||||
if (!ns) {
|
||||
kvfree(ttc);
|
||||
@@ -715,10 +715,6 @@ struct mlx5_ttc_table *mlx5_create_ttc_table(struct mlx5_core_dev *dev,
|
||||
bool use_l4_type;
|
||||
int err;
|
||||
|
||||
ttc = kvzalloc(sizeof(*ttc), GFP_KERNEL);
|
||||
if (!ttc)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
switch (params->ns_type) {
|
||||
case MLX5_FLOW_NAMESPACE_PORT_SEL:
|
||||
use_l4_type = MLX5_CAP_GEN_2(dev, pcc_ifa2) &&
|
||||
@@ -732,6 +728,10 @@ struct mlx5_ttc_table *mlx5_create_ttc_table(struct mlx5_core_dev *dev,
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
ttc = kvzalloc(sizeof(*ttc), GFP_KERNEL);
|
||||
if (!ttc)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
ns = mlx5_get_flow_namespace(dev, params->ns_type);
|
||||
if (!ns) {
|
||||
kvfree(ttc);
|
||||
|
||||
Reference in New Issue
Block a user