From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7D854A04C2; Mon, 25 Nov 2019 16:36:31 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DB2A92952; Mon, 25 Nov 2019 16:36:30 +0100 (CET) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id AB90D28EE for ; Mon, 25 Nov 2019 16:36:29 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Nov 2019 07:36:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,241,1571727600"; d="scan'208";a="202390493" Received: from silpixa00399126.ir.intel.com (HELO silpixa00399126.ger.corp.intel.com) ([10.237.223.2]) by orsmga008.jf.intel.com with ESMTP; 25 Nov 2019 07:36:25 -0800 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson Date: Mon, 25 Nov 2019 15:36:20 +0000 Message-Id: <20191125153620.69358-1-bruce.richardson@intel.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] examples/ioat: handle error when querying number of stats 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" To get the amount of memory needed for stats, we call the xstats_get_names function with a NULL parameter, which can return -1 on error. This negative value was not previously handled correctly, so we adjust things to quit the stats printing routine if this basic call fails. Coverity issue: 350346 Fixes: 632bcd9b5d4f ("examples/ioat: print statistics") Signed-off-by: Bruce Richardson --- examples/ioat/ioatfwd.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/ioat/ioatfwd.c b/examples/ioat/ioatfwd.c index 9fc033bc3..a0cc5c496 100644 --- a/examples/ioat/ioatfwd.c +++ b/examples/ioat/ioatfwd.c @@ -170,7 +170,7 @@ print_stats(char *prgname) unsigned int *ids_xstats, nb_xstats; char status_string[120]; /* to print at the top of the output */ int status_strlen; - + int ret; const char clr[] = { 27, '[', '2', 'J', '\0' }; const char topLeft[] = { 27, '[', '1', ';', '1', 'H', '\0' }; @@ -197,8 +197,11 @@ print_stats(char *prgname) "Ring Size = %d\n", ring_size); /* Allocate memory for xstats names and values */ - nb_xstats = rte_rawdev_xstats_names_get( + ret = rte_rawdev_xstats_names_get( cfg.ports[0].ioat_ids[0], NULL, 0); + if (ret < 0) + return; + nb_xstats = (unsigned int)ret; names_xstats = malloc(sizeof(*names_xstats) * nb_xstats); if (names_xstats == NULL) { -- 2.21.0