net/mlx5: fix potential memory leak in meter
PATCH v3 1/1 net/mlx5: fix potential memory leak in meter
When meter not enabled, avoid allocate memory for meter profile table, which will not be freed in close process when meter not enabled
Fixes a295c69a8b24 ("net/mlx5: optimize meter profile lookup")
Signed-off-by Shun Hao <[email protected]>
Acked-by Bing Zhao <[email protected]>
--- drivers/net/mlx5/linux/mlx5_os.c | 8 +++++--- drivers/net/mlx5/mlx5_flow_meter.c | 4 ++-- drivers/net/mlx5/windows/mlx5_os.c | 8 +++++--- 3 files changed, 12 insertions(+), 8 deletions(-)
drivers/net/mlx5/linux/mlx5_os.c +5 -3
@@ -1612,9 +1612,11 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, priv->ctrl_flows =0 ;rte_spinlock_init (&priv->flow_list_lock);TAILQ_INIT (&priv->flow_meters); - priv->mtr_profile_tbl =mlx5_l3t_create (MLX5_L3T_TYPE_PTR ); -if (!priv->mtr_profile_tbl) - goto error; +if (priv->mtr_en) { + priv->mtr_profile_tbl =mlx5_l3t_create (MLX5_L3T_TYPE_PTR ); +if (!priv->mtr_profile_tbl) + goto error; + }/* Bring Ethernet device up. */ DRV_LOG (DEBUG ,"port %u forcing Ethernet interface up" , eth_dev->data->port_id);
drivers/net/mlx5/mlx5_flow_meter.c +2 -2
@@ -378,8 +378,8 @@ mlx5_flow_meter_profile_find(struct mlx5_priv *priv, uint32_t meter_profile_id)if (priv->mtr_profile_arr)return &priv->mtr_profile_arr[meter_profile_id]; -if (mlx5_l3t_get_entry (priv->mtr_profile_tbl, - meter_profile_id, &data) || !data.ptr) +if (!priv->mtr_profile_tbl || +mlx5_l3t_get_entry (priv->mtr_profile_tbl, meter_profile_id, &data) || !data.ptr)return NULL ; fmp = data.ptr;/* Remove reference taken by the mlx5_l3t_get_entry. */
drivers/net/mlx5/windows/mlx5_os.c +5 -3
@@ -521,9 +521,11 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,claim_zero (mlx5_mac_addr_add (eth_dev, &mac,0 ,0 )); priv->ctrl_flows =0 ;TAILQ_INIT (&priv->flow_meters); - priv->mtr_profile_tbl =mlx5_l3t_create (MLX5_L3T_TYPE_PTR ); -if (!priv->mtr_profile_tbl) - goto error; +if (priv->mtr_en) { + priv->mtr_profile_tbl =mlx5_l3t_create (MLX5_L3T_TYPE_PTR ); +if (!priv->mtr_profile_tbl) + goto error; + }/* Bring Ethernet device up. */ DRV_LOG (DEBUG ,"port %u forcing Ethernet interface up." , eth_dev->data->port_id);
Signature · 1 line
2.20.0
Hi,
From: Shun Hao <[email protected]>
Sent: Wednesday, October 23, 2024 9:22 AM
To: Slava Ovsiienko; Matan Azrad; Ori Kam; Dariusz Sosnowski; Bing Zhao; Suanming Mou
Cc: [email protected]; Raslan Darawsheh; [email protected]
Subject: [PATCH v3] net/mlx5: fix potential memory leak in meter
When meter not enabled, avoid allocate memory for meter profile table, which will not be freed in close process when meter not enabled
Fixes a295c69a8b24 ("net/mlx5: optimize meter profile lookup")
Signed-off-by Shun Hao <[email protected]>
Acked-by Bing Zhao <[email protected]>
Patch applied to next-net-mlx,
Kindest regards,
Raslan Darawsheh