From: Danylo Vodopianov <dvo-...@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-...@napatech.com>
---
 drivers/net/ntnic/nthw/stat/nthw_stat.c | 4 ++++
 1 file changed, 4 insertions(+)

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);
-- 
2.47.1

Reply via email to