Skip to contentSkip to conversation

net/mlx5: fix potential memory leak in meter

PATCH In review Shun Hao 2 participants 2 messages Oct 23, 2024 – Oct 28, 2024 Network drivers

lore
Share & tools
lore

Shun Hao

author
#0 lore raw

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")
---
 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
index 0a8de88759..3881daf5cc 100644
@@ -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
index 19d8607070..98a61cbdd4 100644
@@ -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
index 0ebd233595..61ad06a373 100644
@@ -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
Acked-by Bing Zhao on v3 1/1
#1 lore raw

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")

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh