Skip to content

Commit

Permalink
net/sfc: fix xstats query by ID according to ethdev
Browse files Browse the repository at this point in the history
[ upstream commit 8232cc2 ]

Fix xstats by ID callbacks according to ethdev usage.
Handle combinations of input arguments that are required by ethdev
and sanity check and reject other combinations on callback entry.

Fixes: 73280c1 ("net/sfc: support xstats retrieval by ID")

Signed-off-by: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Reviewed-by: Andy Moreton <amoreton@xilinx.com>
  • Loading branch information
ol-vanyaio authored and bluca committed Jul 26, 2021
1 parent 99bcdae commit e4ebfde
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions drivers/net/sfc/sfc_ethdev.c
Expand Up @@ -785,13 +785,10 @@ sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
int ret;
int rc;

sfc_adapter_lock(sa);
if (unlikely(ids == NULL || values == NULL))
return -EINVAL;

if (unlikely(values == NULL) ||
unlikely(ids == NULL && n < port->mac_stats_nb_supported)) {
ret = port->mac_stats_nb_supported;
goto unlock;
}
sfc_adapter_lock(sa);

rc = sfc_port_update_mac_stats(sa);
if (rc != 0) {
Expand All @@ -806,7 +803,7 @@ sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
if (!EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i))
continue;

if ((ids == NULL) || (ids[nb_written] == nb_supported))
if (ids[nb_written] == nb_supported)
values[nb_written++] = mac_stats[i];

++nb_supported;
Expand All @@ -831,10 +828,13 @@ sfc_xstats_get_names_by_id(struct rte_eth_dev *dev,
unsigned int nb_written = 0;
unsigned int i;

if (unlikely(xstats_names == NULL && ids != NULL) ||
unlikely(xstats_names != NULL && ids == NULL))
return -EINVAL;

sfc_adapter_lock(sa);

if (unlikely(xstats_names == NULL) ||
unlikely((ids == NULL) && (size < port->mac_stats_nb_supported))) {
if (unlikely(xstats_names == NULL && ids == NULL)) {
nb_supported = port->mac_stats_nb_supported;
sfc_adapter_unlock(sa);
return nb_supported;
Expand All @@ -844,7 +844,7 @@ sfc_xstats_get_names_by_id(struct rte_eth_dev *dev,
if (!EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i))
continue;

if ((ids == NULL) || (ids[nb_written] == nb_supported)) {
if (ids[nb_written] == nb_supported) {
char *name = xstats_names[nb_written++].name;

strlcpy(name, efx_mac_stat_name(sa->nic, i),
Expand Down

0 comments on commit e4ebfde

Please sign in to comment.