[v2,21/26] net/ntnic: avoid divide by zero

Message ID 20250505071309.586015-22-okl-plv@napatech.com (mailing list archive)
State New
Delegated to: Stephen Hemminger
Headers
Series net/ntnic: fixes and improvements |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Oleksandr Kolomeiets May 5, 2025, 7:13 a.m. UTC
From: Danylo Vodopianov <dvo-plv@napatech.com>

Fix CID issue 457736 divide by 0. It was avoided by
adding adittional checking on the return value
for function.

Fixes: effa04693274 ("net/ntnic: add statistics")

Signed-off-by: Danylo Vodopianov <dvo-plv@napatech.com>
---
 drivers/net/ntnic/nthw/stat/nthw_stat.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Patch

diff --git a/drivers/net/ntnic/nthw/stat/nthw_stat.c b/drivers/net/ntnic/nthw/stat/nthw_stat.c
index 2ddef052a5..9bb97bf311 100644
--- a/drivers/net/ntnic/nthw/stat/nthw_stat.c
+++ b/drivers/net/ntnic/nthw/stat/nthw_stat.c
@@ -319,6 +319,10 @@  int nthw_stat_init(nthw_stat_t *p, nthw_fpga_t *p_fpga, int n_instance)
 	/* Set the sliding windows size for port load */
 	if (p->mp_fld_load_bin) {
 		uint32_t rpp = nthw_fpga_get_product_param(p_fpga, NT_RPP_PER_PS, 0);
+		if (rpp == 0) {
+			NT_LOG(ERR, NTHW, "RPP has wrong value"); /* Avoid divide by 0 */
+			return -1;
+		}
 		uint32_t bin =
 			(uint32_t)(((PORT_LOAD_WINDOWS_SIZE * 1000000000000ULL) / (32ULL * rpp)) -
 				1ULL);