From: Joseph Wong <[email protected]>

In bnxt_flow_stats_cnt(), two variable-length arrays are allocated
on the stack. These arrays are allocated merely to be used to
calculate the dimensions via RTE_DIM(). Replace with the
mathematical equivalent to avoid potential stack exhaustion.

Fixes: 1e2f8aca2cc1 ("net/bnxt: fix allocation of flow stat related structs")
Cc: [email protected]

Signed-off-by: Joseph Wong <[email protected]>
Signed-off-by: Mohammad Shuab Siddique <[email protected]>
---
 drivers/net/bnxt/bnxt_stats.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/net/bnxt/bnxt_stats.c b/drivers/net/bnxt/bnxt_stats.c
index ba858710a5..c4efcb4b17 100644
--- a/drivers/net/bnxt/bnxt_stats.c
+++ b/drivers/net/bnxt/bnxt_stats.c
@@ -1095,12 +1095,8 @@ int bnxt_flow_stats_cnt(struct bnxt *bp)
 {
        if (bp->fw_cap & BNXT_FW_CAP_ADV_FLOW_COUNTERS &&
            bp->fw_cap & BNXT_FW_CAP_ADV_FLOW_MGMT &&
-           BNXT_FLOW_XSTATS_EN(bp)) {
-               struct bnxt_xstats_name_off flow_bytes[bp->max_l2_ctx];
-               struct bnxt_xstats_name_off flow_pkts[bp->max_l2_ctx];
-
-               return RTE_DIM(flow_bytes) + RTE_DIM(flow_pkts);
-       }
+           BNXT_FLOW_XSTATS_EN(bp))
+               return 2 * bp->max_l2_ctx;
 
        return 0;
 }
-- 
2.47.3

Reply via email to