Skip to content

Commit

Permalink
net/bnxt: fix xstats get
Browse files Browse the repository at this point in the history
[ upstream commit eac4fc7 ]

Fix to return count in xstats get op in all cases.
Driver was returning 0 if the 'xstats' parameter being passed to
xstats_get_op was NULL. This won't work on some applications that
rely on a valid count being passed even in this case so that it can
allocate memory accordingly followed by a reissue of the xstats_get_op
to get the actual stats populated by the driver.

Fixes: 063e59d ("net/bnxt: fix crash in xstats get")

Reviewed-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Reviewed-by: Lance Richardson <lance.richardson@broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
Signed-off-by: Somnath Kotur <somnath.kotur@broadcom.com>
  • Loading branch information
skotur-brcm authored and steevenlee committed May 8, 2021
1 parent f061789 commit 7c69b27
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions drivers/net/bnxt/bnxt_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,15 @@ int bnxt_dev_xstats_get_op(struct rte_eth_dev *eth_dev,
if (rc)
return rc;

if (xstats == NULL)
return 0;
stat_count = RTE_DIM(bnxt_rx_stats_strings) +
RTE_DIM(bnxt_tx_stats_strings) +
RTE_DIM(bnxt_func_stats_strings) +
RTE_DIM(bnxt_rx_ext_stats_strings) +
RTE_DIM(bnxt_tx_ext_stats_strings) +
bnxt_flow_stats_cnt(bp);

memset(xstats, 0, sizeof(*xstats));
if (n < stat_count || xstats == NULL)
return stat_count;

bnxt_hwrm_func_qstats(bp, 0xffff, NULL, &func_qstats);
bnxt_hwrm_port_qstats(bp);
Expand All @@ -609,17 +614,7 @@ int bnxt_dev_xstats_get_op(struct rte_eth_dev *eth_dev,
(bp->fw_tx_port_stats_ext_size /
stat_size));

count = RTE_DIM(bnxt_rx_stats_strings) +
RTE_DIM(bnxt_tx_stats_strings) +
RTE_DIM(bnxt_func_stats_strings) +
RTE_DIM(bnxt_rx_ext_stats_strings) +
RTE_DIM(bnxt_tx_ext_stats_strings) +
bnxt_flow_stats_cnt(bp);

stat_count = count;

if (n < count)
return count;
memset(xstats, 0, sizeof(*xstats));

count = 0;
for (i = 0; i < RTE_DIM(bnxt_rx_stats_strings); i++) {
Expand Down

0 comments on commit 7c69b27

Please sign in to comment.