[v3,5/8] ml/cnxk: fix potential memory leak in xstats

Message ID 20230316212904.9318-6-syalavarthi@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series Fixes to ml/cnxk driver |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Srikanth Yalavarthi March 16, 2023, 9:29 p.m. UTC
  Local buffer xstats_map is not released, when the xstats name
passed by the user application is not valid. This patch releases
the memory in such cases.

Fixes: 4ff4ab8e1a20 ("ml/cnxk: support extended statistics")

Signed-off-by: Srikanth Yalavarthi <syalavarthi@marvell.com>
---
 drivers/ml/cnxk/cn10k_ml_ops.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Patch

diff --git a/drivers/ml/cnxk/cn10k_ml_ops.c b/drivers/ml/cnxk/cn10k_ml_ops.c
index 8d31276e8c..4df2ca0e8c 100644
--- a/drivers/ml/cnxk/cn10k_ml_ops.c
+++ b/drivers/ml/cnxk/cn10k_ml_ops.c
@@ -1128,8 +1128,10 @@  cn10k_ml_dev_xstats_by_name_get(struct rte_ml_dev *dev, const char *name, uint16
 		}
 	}
 
-	if (id == PLT_DIM(cn10k_ml_model_xstats_table) * dev_info.max_models)
+	if (id == PLT_DIM(cn10k_ml_model_xstats_table) * dev_info.max_models) {
+		rte_free(xstats_map);
 		return -EINVAL;
+	}
 
 	model_id = id / PLT_DIM(cn10k_ml_model_xstats_table);
 	type = id % PLT_DIM(cn10k_ml_model_xstats_table);