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.ilche...@oktetlabs.ru
Signed-off-by: Stephen Hemminger <step...@networkplumber.org>
---
 drivers/net/sfc/sfc_ethdev.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

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)
-- 
2.45.2

Reply via email to