From patchwork Thu Jul 18 17:18:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 56734 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 DE0DE325F; Thu, 18 Jul 2019 19:18:21 +0200 (CEST) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by dpdk.org (Postfix) with ESMTP id 70F8814E8 for ; Thu, 18 Jul 2019 19:18:17 +0200 (CEST) Received: by mail-pf1-f193.google.com with SMTP id 19so12926380pfa.4 for ; Thu, 18 Jul 2019 10:18:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZpBjrOtCmw2GHEvi4Mm+NmlrCugLddmyXCS13mXxICw=; b=eTpnM5DBP2DH/NtiuQr5aYiVF+2w4T+bnVCytPBYXJbQOuPTRWrXKaEW4YIdrdC4iB hgyayS7PYrVXX22Rj02rRzs3yNefH5sgBzM7UqES36UijIIM1G0FNtTD7//EKBK8CHj/ RFsarzy84Q+Ts4Q4+ibXtKfM/beVTA228AZu5pV+c9WZzSa5MJy1zRlYg+aCrOa6fYaZ TaXhe+dHn6asAqvld5hvidvIuz/LTNdDa9+ZIQDNzXBjoWQFMM2ywiHty9TUHa2ZuDB+ 1ncFbhgwRskd21O4PigfgQMxvg0IqQCgIrFkUs84vNEZKTx1Pap83GfyLY9TUdH4B59v mzPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZpBjrOtCmw2GHEvi4Mm+NmlrCugLddmyXCS13mXxICw=; b=ETA4VT2Al3iY+F2UF742uMgrvtzA8P8NZusHuANCmLo3TrTyFdqBEM6B0nAQ2ArujR O41k1kIwJmP7KbPu3W2o2eirTDqxk/4ujks+A3YPyKIRO+Ien9gzkg7yp4MmrmQDdLTS cGmNX9U/F/AOfaB8q8AKDXbhXyYUIPv73uxYSQmsQz574WzhXtdc2R6z6yHgPVTiNdYM FmeSr3MZyulkc2J1WwwnVY2/0WtyUa/ZjSfOoXVnxNNAr/IrN59cwAEgXg5iLf0dJHID IMxCi5kC/obCdP8G9tEtiXPzP5LD2DZTgXRoI8IN9Y/Zdwmpy2wxL+jsQQwwJ2FykSkq ocfQ== X-Gm-Message-State: APjAAAUUc8npe2GQkq0dxSE4Ham6uyRn+ViR4T/BBfZbxpEGudin/q1k /0VZkZWmEw8ZYumWRtnFpXzs7PyZ X-Google-Smtp-Source: APXvYqyxkCfVUkN9nAnMi6wehFz1fHD4XXnL3ZQzGF9/rsllU4Mn1pCjRNLYAVj3kBEI63fLHuCQiQ== X-Received: by 2002:a17:90a:dac3:: with SMTP id g3mr52002034pjx.45.1563470296325; Thu, 18 Jul 2019 10:18:16 -0700 (PDT) Received: from localhost.localdomain ([67.23.203.6]) by smtp.gmail.com with ESMTPSA id 137sm36038021pfz.112.2019.07.18.10.18.15 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 18 Jul 2019 10:18:15 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Thu, 18 Jul 2019 10:18:10 -0700 Message-Id: <20190718171812.3209-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190718171812.3209-1-stephen@networkplumber.org> References: <20190716172741.21399-1-stephen@networkplumber.org> <20190718171812.3209-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH v3 1/3] cfgfile: remove unnecessary initialization 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" No need to initialize variable if it is immediately overwritten. It is better style not do unnecessary initialization with modern tools since it lets compiler and other static checkers detect uninitialized data. Signed-off-by: Stephen Hemminger --- lib/librte_cfgfile/rte_cfgfile.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c index f8e7627a5169..1ef298592fa5 100644 --- a/lib/librte_cfgfile/rte_cfgfile.c +++ b/lib/librte_cfgfile/rte_cfgfile.c @@ -160,9 +160,9 @@ struct rte_cfgfile * rte_cfgfile_load_with_params(const char *filename, int flags, const struct rte_cfgfile_parameters *params) { - char buffer[CFG_NAME_LEN + CFG_VALUE_LEN + 4] = {0}; + char buffer[CFG_NAME_LEN + CFG_VALUE_LEN + 4]; int lineno = 0; - struct rte_cfgfile *cfg = NULL; + struct rte_cfgfile *cfg; if (rte_cfgfile_check_params(params)) return NULL; @@ -174,7 +174,7 @@ rte_cfgfile_load_with_params(const char *filename, int flags, cfg = rte_cfgfile_create(flags); while (fgets(buffer, sizeof(buffer), f) != NULL) { - char *pos = NULL; + char *pos; size_t len = strnlen(buffer, sizeof(buffer)); lineno++; if ((len >= sizeof(buffer) - 1) && (buffer[len-1] != '\n')) { @@ -260,7 +260,7 @@ struct rte_cfgfile * rte_cfgfile_create(int flags) { int i; - struct rte_cfgfile *cfg = NULL; + struct rte_cfgfile *cfg; cfg = malloc(sizeof(*cfg)); From patchwork Thu Jul 18 17:18:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 56735 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 1D39D4C94; Thu, 18 Jul 2019 19:18:26 +0200 (CEST) Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by dpdk.org (Postfix) with ESMTP id 09D7F231E for ; Thu, 18 Jul 2019 19:18:18 +0200 (CEST) Received: by mail-pf1-f194.google.com with SMTP id p184so12916693pfp.7 for ; Thu, 18 Jul 2019 10:18:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tMQ3l7eSh2IG5E3ZjmkQhbshkvLKRygnPBc/DveCeQk=; b=Tk/6BlUa6AWXm1T+Wxc7kJfnV69w9pQ8rtP6Giw2ZcseKCzPU7o6uy2cUu5Ngge6Ki EfyALPZNnOFkKetUPGyWqtTniqUG4ekV0drMuh7aIb7syZNPchmKXv3Gza3YI8JPsvJI JriW8BKPf9bCYJ4Noi9sd1Oe0HW/B/MV5eF1Kl9urwux+ah7eSVT14wNRE1VfykOe8cP fQWtcnjo3m/pr1GWgaTxllkEZfyishvPJLaTu4WPJHQJdESBMWX6bMBGdnxQFE2CAZNv U/XwdaHZ2ZXvgLjBLXKGtyWF2/QnxYpqDI/QBJ8nCrVabtD1hhtq7aSWMRnyfn34+q8E Hznw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tMQ3l7eSh2IG5E3ZjmkQhbshkvLKRygnPBc/DveCeQk=; b=akOQY5CVt6xGcaZr9nIFtl67U4EmNQmt/T7XvN0EGaQ+bJzaG/sr7RzZf+yQApAfvW MhyqKrwmYXHtph5hL8Zt9k3B1PahVw59hLQzX4E+S2uRFJT93YhvYuPLsIOu/XTudy/j pSm8cNmoh/j+H8hoOQmxETJkBYMmlhPyNzEP1vTw2GRvIKSJcsQjtVUShf9c0uQxQnKa unDOTdmoQMmzz0CN+qXwYs8JYf4uLCZsfoatFwQZEAf+YKP8QHdzu1SXtjMviqm+2odX Pakd4Zn/VZc9M7zQKkcDoJcDAWT0ETbVU6jiwUEVe9/Y1QZP/IBmiuTJ5c0rZIucmcpu TYFQ== X-Gm-Message-State: APjAAAVxBg3jOWUY/DMpqA6SXTK+aMWxc6JuJHMiSYY31VDtlBIP6Lqq FgrazZyajTNukqfaAgGxcwCYWgAX X-Google-Smtp-Source: APXvYqyQSjGWtOzYEQtoa1mKc5pr3HL9GgBupDcJlWQ22mDZUm+n9T7D7D1YXVzb9GL9i7NtVmdYUA== X-Received: by 2002:a63:6ec6:: with SMTP id j189mr50033703pgc.168.1563470297824; Thu, 18 Jul 2019 10:18:17 -0700 (PDT) Received: from localhost.localdomain ([67.23.203.6]) by smtp.gmail.com with ESMTPSA id 137sm36038021pfz.112.2019.07.18.10.18.16 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 18 Jul 2019 10:18:16 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Thu, 18 Jul 2019 10:18:11 -0700 Message-Id: <20190718171812.3209-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190718171812.3209-1-stephen@networkplumber.org> References: <20190716172741.21399-1-stephen@networkplumber.org> <20190718171812.3209-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH v3 2/3] cfgfile: use RTE_LOG for errors 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" In general, DPDK libraries to not print error messages to stdout because that is often redirected to /dev/null for daemons. This patch changes cfgfile library to use RTE_LOG with its own type. Signed-off-by: Stephen Hemminger --- lib/Makefile | 1 + lib/librte_cfgfile/rte_cfgfile.c | 38 +++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index bdb8a67e2d9d..41c463d92139 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -19,6 +19,7 @@ DEPDIRS-librte_mbuf := librte_eal librte_mempool DIRS-$(CONFIG_RTE_LIBRTE_TIMER) += librte_timer DEPDIRS-librte_timer := librte_eal DIRS-$(CONFIG_RTE_LIBRTE_CFGFILE) += librte_cfgfile +DEPDIRS-librte_cfgfile := librte_eal DIRS-$(CONFIG_RTE_LIBRTE_CMDLINE) += librte_cmdline DEPDIRS-librte_cmdline := librte_eal librte_net DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c index 1ef298592fa5..388415147930 100644 --- a/lib/librte_cfgfile/rte_cfgfile.c +++ b/lib/librte_cfgfile/rte_cfgfile.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "rte_cfgfile.h" @@ -26,6 +27,12 @@ struct rte_cfgfile { struct rte_cfgfile_section *sections; }; +static int cfgfile_logtype; + +#define CFG_LOG(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, cfgfile_logtype, "%s(): " fmt "\n", \ + __func__, ## args) + /** when we resize a file structure, how many extra entries * for new sections do we add in */ #define CFG_ALLOC_SECTION_BATCH 8 @@ -128,7 +135,7 @@ rte_cfgfile_check_params(const struct rte_cfgfile_parameters *params) unsigned int i; if (!params) { - printf("Error - missing cfgfile parameters\n"); + CFG_LOG(ERR, "missing cfgfile parameters\n"); return -EINVAL; } @@ -141,7 +148,7 @@ rte_cfgfile_check_params(const struct rte_cfgfile_parameters *params) } if (valid_comment == 0) { - printf("Error - invalid comment characters %c\n", + CFG_LOG(ERR, "invalid comment characters %c\n", params->comment_character); return -ENOTSUP; } @@ -178,7 +185,7 @@ rte_cfgfile_load_with_params(const char *filename, int flags, size_t len = strnlen(buffer, sizeof(buffer)); lineno++; if ((len >= sizeof(buffer) - 1) && (buffer[len-1] != '\n')) { - printf("Error line %d - no \\n found on string. " + CFG_LOG(ERR, " line %d - no \\n found on string. " "Check if line too long\n", lineno); goto error1; } @@ -198,8 +205,9 @@ rte_cfgfile_load_with_params(const char *filename, int flags, /* section heading line */ char *end = memchr(buffer, ']', len); if (end == NULL) { - printf("Error line %d - no terminating ']'" - "character found\n", lineno); + CFG_LOG(ERR, + "line %d - no terminating ']' character found\n", + lineno); goto error1; } *end = '\0'; @@ -213,8 +221,9 @@ rte_cfgfile_load_with_params(const char *filename, int flags, split[0] = buffer; split[1] = memchr(buffer, '=', len); if (split[1] == NULL) { - printf("Error line %d - no '='" - "character found\n", lineno); + CFG_LOG(ERR, + "line %d - no '=' character found\n", + lineno); goto error1; } *split[1] = '\0'; @@ -236,8 +245,9 @@ rte_cfgfile_load_with_params(const char *filename, int flags, if (!(flags & CFG_FLAG_EMPTY_VALUES) && (*split[1] == '\0')) { - printf("Error at line %d - cannot use empty " - "values\n", lineno); + CFG_LOG(ERR, + "line %d - cannot use empty values\n", + lineno); goto error1; } @@ -397,7 +407,8 @@ int rte_cfgfile_set_entry(struct rte_cfgfile *cfg, const char *sectionname, sizeof(curr_section->entries[i].value)); return 0; } - printf("Error - entry name doesn't exist\n"); + + CFG_LOG(ERR, "entry name doesn't exist\n"); return -EINVAL; } @@ -552,3 +563,10 @@ rte_cfgfile_has_entry(struct rte_cfgfile *cfg, const char *sectionname, { return rte_cfgfile_get_entry(cfg, sectionname, entryname) != NULL; } + +RTE_INIT(cfgfile_init) +{ + cfgfile_logtype = rte_log_register("lib.cfgfile"); + if (cfgfile_logtype >= 0) + rte_log_set_level(cfgfile_logtype, RTE_LOG_INFO); +} From patchwork Thu Jul 18 17:18:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 56736 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 EBFF9532C; Thu, 18 Jul 2019 19:18:28 +0200 (CEST) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by dpdk.org (Postfix) with ESMTP id 2A8C03977 for ; Thu, 18 Jul 2019 19:18:22 +0200 (CEST) Received: by mail-pg1-f193.google.com with SMTP id i70so2444597pgd.4 for ; Thu, 18 Jul 2019 10:18:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=N1WVl4UQRTpsyytnCtNAVwaiTrTPmL/dbLCjaW6bKtI=; b=07rsIpMvaw3Jf7ySy6COdZlMLbrjnBvxVG2ARZ/bvTy55xAhnCpzRC3/2mndptV+Ol gGiqnAD9pTsSoToeAoHR6tH8OCAWyE5+6p3DW3YIIxXLJPRdQrXyKTr/Dq6xvJ7xe747 7VuKcPVTwGPXCPqZkgzvP+SmsIg00uxXzkf2HkLETI4DHicoGGPLvxQBto/ZS6xFgNa0 moiYujchoKZ2q9mOk+vfN7N3xjAkgBOBB5i6TanHDL/6Umpt92VtcrVXhdmH/8ec4NaN tPnLHFLqBuRgBTcTeGEy5XuwT7xvnZX7VpTFbnRwh3YrpJ6iLK7ZQj83gLhz9omf8f3i BbvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=N1WVl4UQRTpsyytnCtNAVwaiTrTPmL/dbLCjaW6bKtI=; b=itTc0MdzL2n0WigYjQazS3GblBfoK7q/Wu0GWrynGtMNZbBGKc1CWsBquwS4gJnaqa sUF5CZt+uCAOeFQ7eFCUnb+0CpmiJ6yF5tZUHMgxPnbjDi4bpaC8NueehDkStwqk2CJu afIDw7j02pVUUFHE4CJPzPosa787uJ5HzMWXvk8PS7Jo91hmbD6Jjp+sagPVCxy+O5Av /zuAyhvkP6GTlv0hTfOJxgT1AiXk7w+pVqJ2JxUJlM/OeuF6MJLAhZeQrqiVUuhEH/dJ K1b6V3yv7jlI/Sb6pOtCniqQxB3VdhLf5vWFzjRcI67ho37w0WIlA4a1Z8ntn+fEE3y5 9rZQ== X-Gm-Message-State: APjAAAV/ptOfAxOmcNfGIaqpnKDHy269XdCHMZ5n2pQzbpOdHxpYGGoE X9TS/gRsHOEQRxX7DsVmHvY9QX/Q X-Google-Smtp-Source: APXvYqxmOnhGIqcbfke3PAx8nBV5sXFxjIuqRNB2GRcLY+hTQWgPJNfMPST+fncIQf9X8wUGgyhguA== X-Received: by 2002:a17:90a:cb81:: with SMTP id a1mr50872227pju.81.1563470301011; Thu, 18 Jul 2019 10:18:21 -0700 (PDT) Received: from localhost.localdomain ([67.23.203.6]) by smtp.gmail.com with ESMTPSA id 137sm36038021pfz.112.2019.07.18.10.18.17 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 18 Jul 2019 10:18:18 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Thu, 18 Jul 2019 10:18:12 -0700 Message-Id: <20190718171812.3209-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190718171812.3209-1-stephen@networkplumber.org> References: <20190716172741.21399-1-stephen@networkplumber.org> <20190718171812.3209-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH v3 3/3] cfgfile: use calloc 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" Better to use calloc when allocating arrays. Signed-off-by: Stephen Hemminger --- lib/librte_cfgfile/rte_cfgfile.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c index 388415147930..9049fd9c2319 100644 --- a/lib/librte_cfgfile/rte_cfgfile.c +++ b/lib/librte_cfgfile/rte_cfgfile.c @@ -281,17 +281,16 @@ rte_cfgfile_create(int flags) cfg->num_sections = 0; /* allocate first batch of sections and entries */ - cfg->sections = malloc(sizeof(struct rte_cfgfile_section) * - CFG_ALLOC_SECTION_BATCH); - + cfg->sections = calloc(CFG_ALLOC_SECTION_BATCH, + sizeof(struct rte_cfgfile_section)); if (cfg->sections == NULL) goto error1; cfg->allocated_sections = CFG_ALLOC_SECTION_BATCH; for (i = 0; i < CFG_ALLOC_SECTION_BATCH; i++) { - cfg->sections[i].entries = malloc(sizeof( - struct rte_cfgfile_entry) * CFG_ALLOC_ENTRY_BATCH); + cfg->sections[i].entries = calloc(CFG_ALLOC_ENTRY_BATCH, + sizeof(struct rte_cfgfile_entry)); if (cfg->sections[i].entries == NULL) goto error1;