[PATCH v3 2/8] ml/cnxk: fix potential division by zero

Srikanth Yalavarthi syalavarthi at marvell.com
Thu Mar 16 22:28:58 CET 2023


Fix division or modulo by zero issue reported by coverity. Added
a check to count, before updating average value of a stat.

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

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

diff --git a/drivers/ml/cnxk/cn10k_ml_ops.c b/drivers/ml/cnxk/cn10k_ml_ops.c
index 7d5eb97668..bf9409ad10 100644
--- a/drivers/ml/cnxk/cn10k_ml_ops.c
+++ b/drivers/ml/cnxk/cn10k_ml_ops.c
@@ -444,7 +444,8 @@ cn10k_ml_prep_fp_job_descriptor(struct rte_ml_dev *dev, struct cn10k_ml_req *req
 			count += model->burst_stats[qp_id].dequeued_count -                        \
 				 model->burst_stats[qp_id].str##_reset_count;                      \
 		}                                                                                  \
-		value = value / count;                                                             \
+		if (count != 0)                                                                    \
+			value = value / count;                                                     \
 	} while (0)
 
 #define ML_MIN_FOREACH_QP(dev, model, qp_id, str, value, count)                                    \
-- 
2.17.1



More information about the dev mailing list