From patchwork Thu Jun 23 13:26:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zyta Szpak X-Patchwork-Id: 14271 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id B9F3CC53A; Thu, 23 Jun 2016 15:26:58 +0200 (CEST) Received: from mail-lf0-f41.google.com (mail-lf0-f41.google.com [209.85.215.41]) by dpdk.org (Postfix) with ESMTP id E3873C538 for ; Thu, 23 Jun 2016 15:26:57 +0200 (CEST) Received: by mail-lf0-f41.google.com with SMTP id f6so95398364lfg.0 for ; Thu, 23 Jun 2016 06:26:57 -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=p316yf+FuQkZgIfXSxdMAB3tuL2+bUMxRN+nfyOLyCY=; b=ma1xaCsm9XtazaBkKAl8lxmAYTgwlbkwcCrOGJ3FPA+YwF5ziLJDtPwhU9/gyewdoW x6VzvB4/lIoTFvGVMYLUgIJKHOU3btjH3wjSVp22uF2J3d6TtVNlKuRILJPCGUEynFmQ fKGcgyOh/9apPfai9u2FjxSEE54dbPE6w8A9rrh+R5b1ViYnHvm5czKFBGNu48GvFMYV z7Rx7Ac0ikJb86K12fwu7bltrBhL3qG+wH/a85gpOEe+rmjpifZjpOV4Z50p+PJ6sRww QQSCMngKH6EoAAsivONEK36eANJTnamUmb0ilBtDM1dlLeyHpP8KN0huy3FYHF5CHotK DsJw== 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=p316yf+FuQkZgIfXSxdMAB3tuL2+bUMxRN+nfyOLyCY=; b=LqMEGryIald/8IrlIYtzBVdiK9NkMKwktUcTrUoUgzJ1BWoybL5wEaD1XEKGnU6KWj qVU9ntToX6PML55thaQyFIAKklj/+g4jesj1NIG/55b3sokJQL6lPtjEGwXcaE/DjqUD 6HNORoa+qxi3Wfo5exAJCH1IfqkpQKp8IWLxHZMw7Rm0GdYpajONRdbQdakrDOakbEqG J7aqtBZsoynI3dRE0C/I6fGMAYlNAuSFsFEQg4A1juwi9JFGeKusFSl4dx5iknDgSxDI hlMalrLmvq4HrXckKFH5TJ13+WuueAEm91G8rv8GMqh72iDpatm/9bJXXaPZJPmzeerY S6WQ== X-Gm-Message-State: ALyK8tIMdAPX1eb26Fy2GRfbHSL6lkY02uQLksfOogzaH9O1a1yWg2lOoXthFdwjDNmjgg== X-Received: by 10.46.0.219 with SMTP id e88mr11387619lji.55.1466688417647; Thu, 23 Jun 2016 06:26:57 -0700 (PDT) Received: from zr-HP-Pro-3500-Series.semihalf.local (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id p6sm20255lbj.24.2016.06.23.06.26.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Jun 2016 06:26:56 -0700 (PDT) From: zr@semihalf.com To: remy.horton@intel.com, thomas.monjalon@6wind.com, wenzhuo.lu@intel.com, helin.zhang@intel.com, konstantin.ananyev@intel.com, jingjing.wu@intel.com Cc: dev@dpdk.org, Zyta Szpak Date: Thu, 23 Jun 2016 15:26:50 +0200 Message-Id: <1466688410-13826-2-git-send-email-zr@semihalf.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1466688410-13826-1-git-send-email-zr@semihalf.com> References: <1466688410-13826-1-git-send-email-zr@semihalf.com> Subject: [dpdk-dev] [PATCH v4 2/2] examples/ethtool: use rte_eth_dev_get_reg_info for reg params X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Zyta Szpak Version 4 of fixing the fixed register width assumption. The app was allocating too little space for 64-bit registers which resulted in memory corruption. This commit resolves this by getting the number of registers and size of register by rte_eth_dev_get_reg_info function called first time with data=NULL. Signed-off-by: Zyta Szpak Acked-by: Remy Horton --- examples/ethtool/lib/rte_ethtool.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/examples/ethtool/lib/rte_ethtool.c b/examples/ethtool/lib/rte_ethtool.c index 54391f2..a1f91d4 100644 --- a/examples/ethtool/lib/rte_ethtool.c +++ b/examples/ethtool/lib/rte_ethtool.c @@ -46,6 +46,7 @@ int rte_ethtool_get_drvinfo(uint8_t port_id, struct ethtool_drvinfo *drvinfo) { struct rte_eth_dev_info dev_info; + struct rte_dev_reg_info reg_info; int n; if (drvinfo == NULL) @@ -65,7 +66,9 @@ rte_ethtool_get_drvinfo(uint8_t port_id, struct ethtool_drvinfo *drvinfo) dev_info.pci_dev->addr.domain, dev_info.pci_dev->addr.bus, dev_info.pci_dev->addr.devid, dev_info.pci_dev->addr.function); - n = rte_eth_dev_get_reg_length(port_id); + memset(®_info, 0, sizeof(reg_info)); + rte_eth_dev_get_reg_info(port_id, ®_info); + n = reg_info.length; if (n > 0) drvinfo->regdump_len = n; else @@ -86,12 +89,16 @@ rte_ethtool_get_drvinfo(uint8_t port_id, struct ethtool_drvinfo *drvinfo) int rte_ethtool_get_regs_len(uint8_t port_id) { - int count_regs; + struct rte_dev_reg_info reg_info; + int ret; + + memset(®_info, 0, sizeof(reg_info)); + + ret = rte_eth_dev_get_reg_info(port_id, ®_info); + if (ret) + return ret; - count_regs = rte_eth_dev_get_reg_length(port_id); - if (count_regs > 0) - return count_regs * sizeof(uint32_t); - return count_regs; + return reg_info.length * reg_info.width; } int