[RFC,5/5] net/sfc: fix handling of xstats_get queries

Message ID 20241008160209.68000-6-stephen@networkplumber.org (mailing list archive)
State Rejected
Delegated to: Stephen Hemminger
Headers
Series make PMD xstat_get alike |

Checks

Context Check Description
ci/loongarch-compilation success Compilation OK
ci/checkpatch success coding style OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS

Commit Message

Stephen Hemminger Oct. 8, 2024, 3:59 p.m. UTC
The xstats_get function in this driver did not act the same
as other drivers when queried. The correct check is to look
at the requested number of stats and compare it to the available
stats and if the request is too small, return the correct size.

Fixes: fdd7719eb3c1 ("net/sfc: add xstats for Rx/Tx doorbells")
Cc: ivan.ilchenko@oktetlabs.ru
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/sfc/sfc_ethdev.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
  

Comments

Stephen Hemminger Dec. 4, 2024, 10:18 p.m. UTC | #1
On Tue,  8 Oct 2024 08:59:59 -0700
Stephen Hemminger <stephen@networkplumber.org> wrote:

> The xstats_get function in this driver did not act the same
> as other drivers when queried. The correct check is to look
> at the requested number of stats and compare it to the available
> stats and if the request is too small, return the correct size.
> 
> Fixes: fdd7719eb3c1 ("net/sfc: add xstats for Rx/Tx doorbells")
> Cc: ivan.ilchenko@oktetlabs.ru
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

Could someone with Solarflare hardware test this please?
  

Patch

diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c
index 3480a51642..f0710dab5c 100644
--- a/drivers/net/sfc/sfc_ethdev.c
+++ b/drivers/net/sfc/sfc_ethdev.c
@@ -833,11 +833,12 @@  sfc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
 {
 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
 	unsigned int nb_written = 0;
-	unsigned int nb_supported = 0;
+	unsigned int nb_supported;
 	int rc;
 
-	if (unlikely(xstats == NULL))
-		return sfc_xstats_get_nb_supported(sa);
+	nb_supported = sfc_xstats_get_nb_supported(sa);
+	if (xstats_count < nb_supported)
+		return nb_supported;
 
 	rc = sfc_port_get_mac_stats(sa, xstats, xstats_count, &nb_written);
 	if (rc < 0)