[v3,06/10] net/axgbe: adjust retval when xstats is null of get xstats

Message ID 20220505080233.12737-7-fengchengwen@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: Andrew Rybchenko
Headers
Series bugfix for ethdev telemetry |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

fengchengwen May 5, 2022, 8:02 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 axgbe PMD
returns zero when xstats is NULL.

This patch adjusts that the return value was the required number of
elements when stats is NULL.

Fixes: 9d1ef6b2e731 ("net/axgbe: add xstats")
Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
 drivers/net/axgbe/axgbe_ethdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Andrew Rybchenko May 12, 2022, 10 a.m. UTC | #1
On 5/5/22 11:02, Chengwen Feng wrote:
> Many user (e.g. telemetry) invokes rte_eth_xstats_get(port_id, NULL, 0)
> to retrieve the required number of elements, but currently axgbe PMD
> returns zero when xstats is NULL.
> 
> This patch adjusts that the return value was the required number of
> elements when stats is NULL.
> 
> Fixes: 9d1ef6b2e731 ("net/axgbe: add xstats")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
> ---
>   drivers/net/axgbe/axgbe_ethdev.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/axgbe/axgbe_ethdev.c b/drivers/net/axgbe/axgbe_ethdev.c
> index 951da5cc26..f6a3a52430 100644
> --- a/drivers/net/axgbe/axgbe_ethdev.c
> +++ b/drivers/net/axgbe/axgbe_ethdev.c
> @@ -1014,7 +1014,7 @@ axgbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *stats,
>   	unsigned int i;
>   
>   	if (!stats)

I think the right condition is: n < AXGBE_XSTATS_COUNT
Otherwise the function break contract to return required
number of xstats if space is insufficient.

> -		return 0;
> +		return AXGBE_XSTATS_COUNT;
>   
>   	axgbe_read_mmc_stats(pdata);
>
  

Patch

diff --git a/drivers/net/axgbe/axgbe_ethdev.c b/drivers/net/axgbe/axgbe_ethdev.c
index 951da5cc26..f6a3a52430 100644
--- a/drivers/net/axgbe/axgbe_ethdev.c
+++ b/drivers/net/axgbe/axgbe_ethdev.c
@@ -1014,7 +1014,7 @@  axgbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *stats,
 	unsigned int i;
 
 	if (!stats)
-		return 0;
+		return AXGBE_XSTATS_COUNT;
 
 	axgbe_read_mmc_stats(pdata);