From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <zr@semihalf.com>
Received: from mail-lf0-f51.google.com (mail-lf0-f51.google.com
 [209.85.215.51]) by dpdk.org (Postfix) with ESMTP id A96B65684
 for <dev@dpdk.org>; Wed, 25 May 2016 08:36:48 +0200 (CEST)
Received: by mail-lf0-f51.google.com with SMTP id w16so2048012lfd.2
 for <dev@dpdk.org>; Tue, 24 May 2016 23:36:48 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=semihalf-com.20150623.gappssmtp.com; s=20150623;
 h=from:to:cc:subject:date:message-id:in-reply-to:references;
 bh=vMoRI3K4mbKoozuvOJEjVBDqSwnH1A2wezCPvp9FJog=;
 b=Fs27hQP4+GNzokaMShuHAiBnXbLVY7xWjNeIlZu9SwMjoPddttNRNN40UarOSbwfrP
 Ja15sgxO2JrNPb07JAviBHSiZNgTCtNvL6NnfPgCWWju1tWxFi2LAVtqb8UyogIO5PHg
 IY4MZtHk0BZy+eZOCNU1gP+QKB5z3cJJuWHezn+yyGVrxQ558PZKy8PkFoqVeJESqlUz
 yIe2Jns6l6XhtPyxL3K2pA2LwhDfhkbsUK0bL30As5siYVQT8FB4hvFk17z5ZQnu9iV3
 L/ElNvWPLYKGjslRKTPMz0zq934HDqsXSYXehnaT+fRdqrciAPlXX9LDqhsmlVSvvtUD
 ZSTg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20130820;
 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
 :references;
 bh=vMoRI3K4mbKoozuvOJEjVBDqSwnH1A2wezCPvp9FJog=;
 b=WimAPz3/1vj9I6duxCw/rEh6vJVofekQylgmjXHCGohSHYOp5UajuNdzi6Lvveq5ck
 71idVsQu2Qq4oshCo+t1wbtIZafi+0TVbpRGz60vPqgEpFuZXfmRzajwa8RaSMRf+Fr/
 +D1XoNfKAKpUEV6N4qojakSN2YqFaFC7u2h0sxOOk+NQ7wv61NzBc6vJGpTCYaFv6QxL
 qWNjNLIGyG0vqh/RJtEARxs7GpV3Hja3guLLyvNSoJBWZo+C5OIBf/L0ga9VEwenRdJD
 1rXsCJjE+Y8OTE1hyUUWzDMVY7uMu98sCBT1pq1LnlocdR7pQb4ZG5jXxB3yW1quIYrw
 YaMg==
X-Gm-Message-State: ALyK8tJhuxzFRUHWGV71ri5POzi8yaNH9l6Po0iK+nX4qyFS8ANcUS2ZVJZVbg2PoGJdDQ==
X-Received: by 10.25.10.2 with SMTP id 2mr477181lfk.170.1464158208394;
 Tue, 24 May 2016 23:36:48 -0700 (PDT)
Received: from zr-HP-Pro-3500-Series.semihalf.local ([80.82.22.190])
 by smtp.gmail.com with ESMTPSA id r16sm1160378lfd.35.2016.05.24.23.36.47
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
 Tue, 24 May 2016 23:36:47 -0700 (PDT)
From: zr@semihalf.com
To: remy.horton@intel.com,
	thomas.monjalon@6wind.com
Cc: dev@dpdk.org,
	Zyta Szpak <zr@semihalf.com>
Date: Wed, 25 May 2016 08:36:54 +0200
Message-Id: <1464158214-24733-2-git-send-email-zr@semihalf.com>
X-Mailer: git-send-email 1.9.1
In-Reply-To: <1464158214-24733-1-git-send-email-zr@semihalf.com>
References: <1462963714-21022-1-git-send-email-zr@semihalf.com>
 <1464158214-24733-1-git-send-email-zr@semihalf.com>
Subject: [dpdk-dev] [PATCH 2/2] examples/ethtool: get reg width to allocate
	memory
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Wed, 25 May 2016 06:36:48 -0000

From: Zyta Szpak <zr@semihalf.com>

Version 2 of fixing the fixed register width assumption.
Not every device uses 32-bit wide register. The app was allocating too
little space for 64-bit registers which resulted in memory corruption.
This commit resolves this by getting the size of register in bytes for
a specific device. If the device does not implement this function, it
fallsback to sizeof(uint32_t)

Signed-off-by: Zyta Szpak <zr@semihalf.com>
---
 examples/ethtool/lib/rte_ethtool.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/examples/ethtool/lib/rte_ethtool.c b/examples/ethtool/lib/rte_ethtool.c
index 42e05f1..59191ca 100644
--- a/examples/ethtool/lib/rte_ethtool.c
+++ b/examples/ethtool/lib/rte_ethtool.c
@@ -88,10 +88,14 @@ int
 rte_ethtool_get_regs_len(uint8_t port_id)
 {
 	int count_regs;
+	int reg_width;
 
 	count_regs = rte_eth_dev_get_reg_length(port_id);
+	reg_width = rte_eth_dev_get_reg_width(port_id);
+	if (reg_width < 0)
+		reg_width = sizeof(uint32_t);
 	if (count_regs > 0)
-		return count_regs * sizeof(uint32_t);
+		return count_regs * reg_width;
 	return count_regs;
 }
 
-- 
1.9.1