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

Message ID 20230316212904.9318-3-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:28 p.m. UTC
  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@marvell.com>
---
 drivers/ml/cnxk/cn10k_ml_ops.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Patch

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