From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 82A1845AE3;
	Tue,  8 Oct 2024 18:02:42 +0200 (CEST)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id D274940DCA;
	Tue,  8 Oct 2024 18:02:26 +0200 (CEST)
Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com
 [209.85.210.178])
 by mails.dpdk.org (Postfix) with ESMTP id 6A04E40691
 for <dev@dpdk.org>; Tue,  8 Oct 2024 18:02:23 +0200 (CEST)
Received: by mail-pf1-f178.google.com with SMTP id
 d2e1a72fcca58-71dea49e808so3522747b3a.1
 for <dev@dpdk.org>; Tue, 08 Oct 2024 09:02:23 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1728403342;
 x=1729008142; darn=dpdk.org; 
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=GRzuKgNG4ZiTpe9DKuig3YnWZuhEjVT3NU3VmTR8TRw=;
 b=QB2Rn6wDqpicF/sqDN/rc6NgyYC3wWGoTZnT6R4HFkb3StxoKqG7iTkh12VG9WJR8q
 pKoH9rkxnXT1d17GEDHjEbbck8vzY5KOwKCo7/xsiZKUaQtDKnsMIQ68G6S41G0fYpu3
 P94xgNUZRKCb/9JaRZ4e2PzVHP9sL0IC77bglx/kR/qye2GVAWKJKiKFrbjiT2LYILAq
 2R/zC+DJuXtcqPzOm/fclRSgfD6lxxIwGafq6n3YybTbLkQJ5sm2po6XG3y8P4oL6pip
 v5az5wU940KHEqElEz5pDLjsdx0sGb59GsUXTwTmZ1xmtQIDeT5BX0FeYxcu4wCGtWYN
 OvNA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1728403342; x=1729008142;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=GRzuKgNG4ZiTpe9DKuig3YnWZuhEjVT3NU3VmTR8TRw=;
 b=m90yxDyTm/y3UHJcfU7Xl1Qmpwyikv5KFMHb5vYYHeICrGW9SjfphkS7NMPgnjj5Ak
 nkfe1amUs2dE03gAVFeF3QHoPCgeaRmbty2jsn4cl96D4GrkGPbskj1O1V8nZ0NYSNI3
 b5CbGX5V/q2s/7DceHYqpqrRnNBea5gbqQWLCRbWW/lvev+Hgi/XrTjFYRfba1DaR5jc
 tgo0qPqC1ZslKRTNuVYAwLjrL9T2ehxin12MCebSe0xjootSW5egSoPxAE3XdsAJzwUH
 EwrmW3yEdtMJzac7gXPTCQGmETlB6PtaBvy+DFbhyi31vQmX1UAjOtR0GNfIfH8UKNry
 iAUA==
X-Gm-Message-State: AOJu0YwQrAJQFy/VyBcYmq4YgwEouaIBeEwJAgcpJ6JFlf1seWq5k1Ww
 8BvgYAKTvHsGVgLdw3MHrOKzfO9i2u6T5pvRVzsH1Y6W3iNTI1ZqNDY/k9ObYJPi73CCiPJdist
 hk0l5Lg==
X-Google-Smtp-Source: AGHT+IFMbu5QWdqs/gDKqco91IvtLSBeEMBpjHUTGjAPQIhMHz+h7sdm9lR3cgp8wPS4oR8QDg5TbQ==
X-Received: by 2002:a05:6a00:2d0c:b0:71e:cd0:cc99 with SMTP id
 d2e1a72fcca58-71e0cd0d976mr9303034b3a.4.1728403341108; 
 Tue, 08 Oct 2024 09:02:21 -0700 (PDT)
Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226])
 by smtp.gmail.com with ESMTPSA id
 41be03b00d2f7-7e9f6c3758esm7028267a12.74.2024.10.08.09.02.20
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 08 Oct 2024 09:02:20 -0700 (PDT)
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	jiawenwu@trustnetic.com
Subject: [RFC 2/5] net/ngbe: fix query handling in xstats_get
Date: Tue,  8 Oct 2024 08:59:56 -0700
Message-ID: <20241008160209.68000-3-stephen@networkplumber.org>
X-Mailer: git-send-email 2.45.2
In-Reply-To: <20241008160209.68000-1-stephen@networkplumber.org>
References: <20241008160209.68000-1-stephen@networkplumber.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

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.

Bugzilla ID: 1560
Fixes: 8b433d04adc9 ("net/ngbe: support device xstats")
Cc: jiawenwu@trustnetic.com

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/ngbe/ngbe_ethdev.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ngbe/ngbe_ethdev.c b/drivers/net/ngbe/ngbe_ethdev.c
index 6c45ffaad3..ee65829aa0 100644
--- a/drivers/net/ngbe/ngbe_ethdev.c
+++ b/drivers/net/ngbe/ngbe_ethdev.c
@@ -1693,19 +1693,16 @@ ngbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
 	struct ngbe_hw_stats *hw_stats = NGBE_DEV_STATS(dev);
 	unsigned int i, count;
 
-	ngbe_read_stats_registers(hw, hw_stats);
-
-	/* If this is a reset xstats is NULL, and we have cleared the
-	 * registers by reading them.
-	 */
 	count = ngbe_xstats_calc_num(dev);
-	if (xstats == NULL)
+	if (limit < count)
 		return count;
 
+	ngbe_read_stats_registers(hw, hw_stats);
+
 	limit = min(limit, ngbe_xstats_calc_num(dev));
 
 	/* Extended stats from ngbe_hw_stats */
-	for (i = 0; i < limit; i++) {
+	for (i = 0; i < count; i++) {
 		uint32_t offset = 0;
 
 		if (ngbe_get_offset_by_id(i, &offset)) {
-- 
2.45.2