[dpdk-dev,2/2] examples/ethtool: get reg width to allocate memory

Message ID 1464158214-24733-2-git-send-email-zr@semihalf.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Commit Message

Zyta Szpak May 25, 2016, 6:36 a.m. UTC
  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(-)
  

Comments

Remy Horton May 25, 2016, 1:14 p.m. UTC | #1
On 25/05/2016 07:36, zr@semihalf.com wrote:
> From: Zyta Szpak <zr@semihalf.com>
[..]
> Signed-off-by: Zyta Szpak <zr@semihalf.com>
> ---
>   examples/ethtool/lib/rte_ethtool.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)

Acked-by: Remy Horton <remy.horton@intel.com>
  

Patch

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;
 }