diff mbox series

[v4,5/9] net/mvpp2: adjust return value of xstats-get ops

Message ID 20220513025357.52275-6-fengchengwen@huawei.com (mailing list archive)
State New
Delegated to: Andrew Rybchenko
Headers show
Series bugfix for ethdev telemetry | expand


Context Check Description
ci/checkpatch success coding style OK

Commit Message

fengchengwen May 13, 2022, 2:53 a.m. UTC
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.

In the previous patch, the framework defines that the required number
of entries should be returned when n is lower than the required number
of entries, and makes sure xstats must not be NULL when n is non-zero.

This patch removes the logic of "return zero when xstats is NULL", and
adds the logic of "return the required number of entries when n is
lower than the required number of entries".

Fixes: a77b5378cd41 ("net/mrvl: add extended statistics")
Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
 drivers/net/mvpp2/mrvl_ethdev.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
diff mbox series


diff --git a/drivers/net/mvpp2/mrvl_ethdev.c b/drivers/net/mvpp2/mrvl_ethdev.c
index f86701d248..735efb6cfc 100644
--- a/drivers/net/mvpp2/mrvl_ethdev.c
+++ b/drivers/net/mvpp2/mrvl_ethdev.c
@@ -1626,13 +1626,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))
@@ -1648,7 +1649,7 @@  mrvl_xstats_get(struct rte_eth_dev *dev,
 		stats[i].value = val;
-	return n;
+	return count;