[RFC,5/5] net/sfc: fix handling of xstats_get queries
Checks
Commit Message
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
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?
@@ -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)