Skip to content

Commit

Permalink
net/mvpp2: fix xstats get return if xstats is null
Browse files Browse the repository at this point in the history
[ upstream commit d853d24b27d6524f26a2a830c7ef678ba739cfce ]

Many user (e.g. telemetry) invokes rte_eth_xstats_get(port_id, NULL, 0)
to retrieve the required number of elements, but currently mvpp2 PMD
returns zero when xstats is null.

Remove the logic of "return zero when xstats is NULL", and add the logic
of "return the required number of entries when n is lower than the
required number of entries".

Fixes: a77b537 ("net/mrvl: add extended statistics")

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
  • Loading branch information
fengchengwen authored and cpaelzer committed Jul 7, 2022
1 parent d00e51a commit 5894d7a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions drivers/net/mvpp2/mrvl_ethdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1376,13 +1376,14 @@ mrvl_xstats_get(struct rte_eth_dev *dev,
{
struct mrvl_priv *priv = dev->data->dev_private;
struct pp2_ppio_statistics ppio_stats;
unsigned int i;
unsigned int i, count;

if (!stats)
return 0;
count = RTE_DIM(mrvl_xstats_tbl);
if (n < count)
return count;

pp2_ppio_get_statistics(priv->ppio, &ppio_stats, 0);
for (i = 0; i < n && i < RTE_DIM(mrvl_xstats_tbl); i++) {
for (i = 0; i < count; i++) {
uint64_t val;

if (mrvl_xstats_tbl[i].size == sizeof(uint32_t))
Expand All @@ -1398,7 +1399,7 @@ mrvl_xstats_get(struct rte_eth_dev *dev,
stats[i].value = val;
}

return n;
return count;
}

/**
Expand Down

0 comments on commit 5894d7a

Please sign in to comment.