From patchwork Thu Jul 22 09:54:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Rybchenko X-Patchwork-Id: 96202 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6F2B3A0C4E; Thu, 22 Jul 2021 11:55:22 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 548D041109; Thu, 22 Jul 2021 11:55:11 +0200 (CEST) Received: from shelob.oktetlabs.ru (shelob.oktetlabs.ru [91.220.146.113]) by mails.dpdk.org (Postfix) with ESMTP id 6682040E50; Thu, 22 Jul 2021 11:55:10 +0200 (CEST) Received: by shelob.oktetlabs.ru (Postfix, from userid 122) id 3DB157F6D4; Thu, 22 Jul 2021 12:55:10 +0300 (MSK) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on shelob.oktetlabs.ru X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=ALL_TRUSTED, DKIM_ADSP_DISCARD, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from aros.oktetlabs.ru (aros.oktetlabs.ru [192.168.38.17]) by shelob.oktetlabs.ru (Postfix) with ESMTP id 519F97F6BF; Thu, 22 Jul 2021 12:54:45 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 shelob.oktetlabs.ru 519F97F6BF Authentication-Results: shelob.oktetlabs.ru/519F97F6BF; dkim=none; dkim-atps=neutral From: Andrew Rybchenko To: dev@dpdk.org, Ivan Malov , Remy Horton Cc: David Marchand , Ivan Ilchenko , stable@dpdk.org, Andy Moreton Date: Thu, 22 Jul 2021 12:54:27 +0300 Message-Id: <20210722095433.1898589-6-andrew.rybchenko@oktetlabs.ru> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210722095433.1898589-1-andrew.rybchenko@oktetlabs.ru> References: <20210604144225.287678-1-andrew.rybchenko@oktetlabs.ru> <20210722095433.1898589-1-andrew.rybchenko@oktetlabs.ru> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2 05/11] net/sfc: fix xstats by ID callbacks according to ethdev X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Ivan Ilchenko 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: 73280c1e4ff ("net/sfc: support xstats retrieval by ID") Cc: stable@dpdk.org Signed-off-by: Ivan Ilchenko Signed-off-by: Andrew Rybchenko Reviewed-by: Andy Moreton --- drivers/net/sfc/sfc_ethdev.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c index d5417e5e65..fca3f524a1 100644 --- a/drivers/net/sfc/sfc_ethdev.c +++ b/drivers/net/sfc/sfc_ethdev.c @@ -794,13 +794,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) { @@ -815,7 +812,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; @@ -840,10 +837,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; @@ -853,7 +853,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),