From patchwork Mon Jul 2 14:55:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Remy Horton X-Patchwork-Id: 42098 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 [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 451251B39C; Mon, 2 Jul 2018 16:55:53 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id 0A33E7EB4 for ; Mon, 2 Jul 2018 16:55:50 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jul 2018 07:55:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,299,1526367600"; d="scan'208";a="242003989" Received: from rhorton-mobl1.ger.corp.intel.com (HELO FC23.ir.intel.com) ([163.33.178.248]) by fmsmga005.fm.intel.com with ESMTP; 02 Jul 2018 07:55:48 -0700 From: Remy Horton To: dev@dpdk.org Cc: Reshma Pattan Date: Mon, 2 Jul 2018 15:55:47 +0100 Message-Id: <20180702145547.8376-1-remy.horton@intel.com> X-Mailer: git-send-email 2.9.5 Subject: [dpdk-dev] [PATCH v1] lib/metrics: fix silent fail when uninitialised 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" If rte_metrics_init() had not been called and hence the internal metric storage is not allocated, rte_metrics_get_values() and rte_metrics_get_name() would silently fail by returning zero (i.e. no metrics registered). This patch changes the result of this scenario to an explicit fail by returning -EIO. Fixes: 349950ddb9c5 ("metrics: add information metrics library") Signed-off-by: Remy Horton --- lib/librte_metrics/rte_metrics.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/librte_metrics/rte_metrics.c b/lib/librte_metrics/rte_metrics.c index 258f058..fed0a33 100644 --- a/lib/librte_metrics/rte_metrics.c +++ b/lib/librte_metrics/rte_metrics.c @@ -200,9 +200,8 @@ rte_metrics_get_names(struct rte_metric_name *names, int return_value; memzone = rte_memzone_lookup(RTE_METRICS_MEMZONE_NAME); - /* If not allocated, fail silently */ if (memzone == NULL) - return 0; + return -EIO; stats = memzone->addr; rte_spinlock_lock(&stats->lock); @@ -238,9 +237,9 @@ rte_metrics_get_values(int port_id, return -EINVAL; memzone = rte_memzone_lookup(RTE_METRICS_MEMZONE_NAME); - /* If not allocated, fail silently */ if (memzone == NULL) - return 0; + return -EIO; + stats = memzone->addr; rte_spinlock_lock(&stats->lock);