From patchwork Wed Aug 9 13:30:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wiles, Keith" X-Patchwork-Id: 27497 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 494212B88; Wed, 9 Aug 2017 15:30:12 +0200 (CEST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id B37E42A5D for ; Wed, 9 Aug 2017 15:30:10 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP; 09 Aug 2017 06:30:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.41,348,1498546800"; d="scan'208"; a="1160857408" Received: from aacharya-mobl1.amr.corp.intel.com ([10.255.230.19]) by orsmga001.jf.intel.com with ESMTP; 09 Aug 2017 06:30:08 -0700 From: Keith Wiles To: dev@dpdk.org Date: Wed, 9 Aug 2017 08:30:04 -0500 Message-Id: <20170809133004.3307-1-keith.wiles@intel.com> X-Mailer: git-send-email 2.10.1 Subject: [dpdk-dev] [PATCH] kvargs: return error if key not find in kvlist 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" rte_kvargs_process() should return error if the key is not found in the kvlist or kvlist is NULL. Minor documentation changes and update for when an error is returned. Signed-off-by: Keith Wiles --- lib/librte_kvargs/rte_kvargs.c | 7 ++++--- lib/librte_kvargs/rte_kvargs.h | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c index 854ac83f5..c8e8f4b28 100755 --- a/lib/librte_kvargs/rte_kvargs.c +++ b/lib/librte_kvargs/rte_kvargs.c @@ -158,16 +158,17 @@ rte_kvargs_process(const struct rte_kvargs *kvlist, void *opaque_arg) { const struct rte_kvargs_pair *pair; - unsigned i; + unsigned int i, found = 0; for (i = 0; i < kvlist->count; i++) { pair = &kvlist->pairs[i]; - if (key_match == NULL || strcmp(pair->key, key_match) == 0) { + if (!key_match || strcmp(pair->key, key_match) == 0) { + found++; if ((*handler)(pair->key, pair->value, opaque_arg) < 0) return -1; } } - return 0; + return (!found) ? -1 : 0; } /* free the rte_kvargs structure */ diff --git a/lib/librte_kvargs/rte_kvargs.h b/lib/librte_kvargs/rte_kvargs.h index 5821c726a..260d4db5b 100755 --- a/lib/librte_kvargs/rte_kvargs.h +++ b/lib/librte_kvargs/rte_kvargs.h @@ -115,9 +115,9 @@ void rte_kvargs_free(struct rte_kvargs *kvlist); * Call a handler function for each key/value matching the key * * For each key/value association that matches the given key, calls the - * handler function with the for a given arg_name passing the value on the + * handler function with the given arg_name passing the value in the * dictionary for that key and a given extra argument. If *kvlist* is NULL - * function does nothing. + * function does nothing and returns error. * * @param kvlist * The rte_kvargs structure @@ -131,7 +131,8 @@ void rte_kvargs_free(struct rte_kvargs *kvlist); * * @return * - 0 on success - * - Negative on error + * - Negative on error or + * if *key_match* does not match an entry in *kvlist* */ int rte_kvargs_process(const struct rte_kvargs *kvlist, const char *key_match, arg_handler_t handler, void *opaque_arg);