From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id DAA0D1B2F3 for ; Fri, 20 Oct 2017 02:03:58 +0200 (CEST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Oct 2017 17:03:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,404,1503385200"; d="scan'208";a="165254454" Received: from silpixa00372839.ir.intel.com (HELO silpixa00372839.ger.corp.intel.com) ([10.237.222.154]) by fmsmga006.fm.intel.com with ESMTP; 19 Oct 2017 17:03:57 -0700 From: Ferruh Yigit To: Thomas Monjalon Cc: dev@dpdk.org, Ferruh Yigit , Lee Daly Date: Fri, 20 Oct 2017 01:03:51 +0100 Message-Id: <20171020000351.57868-3-ferruh.yigit@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171020000351.57868-1-ferruh.yigit@intel.com> References: <20171020000351.57868-1-ferruh.yigit@intel.com> Subject: [dpdk-dev] [PATCH 3/3] ethdev: fix negative return values in xstats X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Oct 2017 00:03:59 -0000 Some function calls in xstat functions can return negative values to indicate the error, check return values for those cases. Coverity issue: 195028, 195026 Fixes: 8c49d5f1c219 ("ethdev: rework xstats retrieve by id") Signed-off-by: Ferruh Yigit --- Cc: Lee Daly --- lib/librte_ether/rte_ethdev.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 4ed2f6d5f..dc669362a 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -1648,11 +1648,16 @@ rte_eth_xstats_get_names_by_id(uint16_t port_id, unsigned int expected_entries; struct rte_eth_dev *dev; unsigned int i; + int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); - expected_entries = get_xstats_count(port_id); dev = &rte_eth_devices[port_id]; + ret = get_xstats_count(port_id); + if (ret < 0) + return ret; + expected_entries = (unsigned int)ret; + /* Return max number of stats if no ids given */ if (!ids) { if (!xstats_names) @@ -1792,6 +1797,7 @@ rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids, uint16_t expected_entries; struct rte_eth_dev *dev; unsigned int i; + int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); expected_entries = get_xstats_count(port_id); @@ -1828,8 +1834,10 @@ rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids, } /* Fill the xstats structure */ - num_xstats_filled = rte_eth_xstats_get(port_id, xstats, - expected_entries); + ret = rte_eth_xstats_get(port_id, xstats, expected_entries); + if (ret < 0) + return ret; + num_xstats_filled = (unsigned int)ret; /* Return all stats */ if (!ids) { -- 2.13.6