From patchwork Tue Jul 16 17:27:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 56529 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 DE8B91B950; Tue, 16 Jul 2019 19:27:55 +0200 (CEST) Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by dpdk.org (Postfix) with ESMTP id 2558D3195 for ; Tue, 16 Jul 2019 19:27:52 +0200 (CEST) Received: by mail-pl1-f196.google.com with SMTP id 4so3500488pld.10 for ; Tue, 16 Jul 2019 10:27:52 -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 :mime-version:content-transfer-encoding; bh=dcNLr0jir3vesF0krOzdG75kFT8Y5ChbO3SsnV4VN5w=; b=tMrb4Hbd72pDFNWH6Qzvkw6sheaxlMRpjbt/z+OxAMiqrOmQVg6j67yERYSBJLsAA7 fc7Yihwh5tohwby8JLRowJrv4kQw6SJa3wyEvGoV6VHRiO1i/DliRF6RvG5AOBYFLJIi DRflWBA9zRGMpjJqOsrcC/uaVAilYLhcEIibedOQ/hMCH5/m7UI4RFYoyr43IpZ2rAL7 MOvDALhgMyZdBOWziOVWeax4W5890f4lzUSnPLPN+/fbEdSDAR6zeOvPR2GkeTrQDCiK 8qpIoLfYxqQ+b3LHqX9LtPQonb+qQY4OyV14zh6n+9g2MzEgPj80I/sDEwMEgTp/Cgvz IsFw== 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:mime-version:content-transfer-encoding; bh=dcNLr0jir3vesF0krOzdG75kFT8Y5ChbO3SsnV4VN5w=; b=e3G8vxVzyu7HkKICaHlXS8SKOyVWFaP9QX5lOlCLmBDOb4xyR6cMUAKrRogvtTLb0C h8rOVkiJKZS8E7MY286OoWSLaK5im4HixLqXwXtiHzreMGxnszZHep/xhhyM51nVHcRv 7mzMg88S1YkxZ13iimxtzVUfDu0lz4wD6GvgenhqumWBRV0zEypT76AeGQ6PzlgKY5IE ntruQ3O7FWliQIEPf9o3XMI95Rk9kmsDvCOWrhWI27DDR29OEhF/jtFbE1jteVvNEb4c Xl8T4Y7uGLjXb5tA+KrXAfm9oy3lwbtlMUpPDYooKH9DhkRlZYXudlOZVcb1w1mPjnau mtkQ== X-Gm-Message-State: APjAAAXLK7RKOlFcnYupgP7XXvQ57B3i1xgjtQeI+SuWdRW+jcRRRErd N/FCLXlC4zkfN2ik4B8Zcvw= X-Google-Smtp-Source: APXvYqw6APnWUGsg1CPtqY3fBf3wMZoa5t+1bDveeNzZcsqd8+L61WlR1LP/1/BJo4P224YoMlclaw== X-Received: by 2002:a17:902:e2:: with SMTP id a89mr37494646pla.210.1563298071393; Tue, 16 Jul 2019 10:27:51 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id m6sm21173049pfb.151.2019.07.16.10.27.50 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 16 Jul 2019 10:27:50 -0700 (PDT) From: Stephen Hemminger To: cristian.dumitrescu@intel.com Cc: dev@dpdk.org, Stephen Hemminger Date: Tue, 16 Jul 2019 10:27:39 -0700 Message-Id: <20190716172741.21399-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190716172741.21399-1-stephen@networkplumber.org> References: <20190716172741.21399-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 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 Tue Jul 16 17:27:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 56530 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 446C91B974; Tue, 16 Jul 2019 19:27:58 +0200 (CEST) Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by dpdk.org (Postfix) with ESMTP id 9132A4C94 for ; Tue, 16 Jul 2019 19:27:53 +0200 (CEST) Received: by mail-pl1-f196.google.com with SMTP id y8so10446615plr.12 for ; Tue, 16 Jul 2019 10:27:53 -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 :mime-version:content-transfer-encoding; bh=2c5t78v8D8ioyCie5DWBG4mA3csgd1We6ZXYiFQAgqY=; b=BJTk3WE+kAwAuV8/mXdaOQi7/n/CjbPmq+ynFxeBSxF7RbD2hM2FaGTlrVO2cVwjUz ZD5yxdMequrNSH+x0KYsJWa+pg2e6GmLQSe34q6bhgK0nkkNaGtVsOBD+atf1EOaqpL7 uuuu3Fnpmq4mlFwmYrLErKHB6hTjDiv4D2cRmzKdFRHXQJsYraheNv/j4rLEWWQEaOxI vnFZbZdNWl+Ob+nDzQBNtWcmebWxBDkVWk5r1lqVlw+kUoT5hWyrxR+e/1E5Vq05rbQg t9hKvO6i5IeZ6O812gBrar5+hv6idebgbI0WA7ogSTWeh5qMJeX7zOwhHrNxCk7h8mLf 4SBA== 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:mime-version:content-transfer-encoding; bh=2c5t78v8D8ioyCie5DWBG4mA3csgd1We6ZXYiFQAgqY=; b=dRiE73NN3Zy5vFjLic6XQhxaXbfsqSogl/RJmRedntYFcuDkP01g3OANtjqCD6JX0z o13ZZGMQWhA5+wvyWzQz4NcT9SVfpVm/zZvFnDbLHN9cjtog5w5Fg0Mr8OhbF217a+EN ZBI/5HaWTl0mam3HW2TFZsKbIywMrmEW/yjzAmfi3dcf3HJAJO7CORyy5jPQKCtlFYJW f7IM8TuyIgBM5gFyVfQlGnBXByqmnWUdYCo3xLhn1X9t8t8khPXYVV4V/gUN2fJg6Lox k+s/gtgNI6SNnhQ2wj784BRpvLn7McRvqfyGjzdGUcBuJrLUXu2P0itPnkKKJaimlpH/ cwQA== X-Gm-Message-State: APjAAAUf226KsyvaXrb1OmiRBhEdq4V+GaSvsB5nf0qBEOKkjMH3qd4C NF6THyoXd8HB9exos+UAPaK4iPm4 X-Google-Smtp-Source: APXvYqykRQajITfrHl7fJ7Zu+oM4995jrMySe8GJFI33C3+KUBj3PTGtBZhROQqYeNxCOA4XTci/Sw== X-Received: by 2002:a17:902:76c7:: with SMTP id j7mr35876209plt.247.1563298072620; Tue, 16 Jul 2019 10:27:52 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id m6sm21173049pfb.151.2019.07.16.10.27.51 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 16 Jul 2019 10:27:51 -0700 (PDT) From: Stephen Hemminger To: cristian.dumitrescu@intel.com Cc: dev@dpdk.org, Stephen Hemminger Date: Tue, 16 Jul 2019 10:27:40 -0700 Message-Id: <20190716172741.21399-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190716172741.21399-1-stephen@networkplumber.org> References: <20190716172741.21399-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 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/librte_cfgfile/rte_cfgfile.c | 25 +++++++++++++++---------- lib/librte_eal/common/include/rte_log.h | 1 + 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c index 1ef298592fa5..c4b768b6833f 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" @@ -128,7 +129,7 @@ rte_cfgfile_check_params(const struct rte_cfgfile_parameters *params) unsigned int i; if (!params) { - printf("Error - missing cfgfile parameters\n"); + RTE_LOG(ERR, CFGFILE, "missing cfgfile parameters\n"); return -EINVAL; } @@ -141,7 +142,7 @@ rte_cfgfile_check_params(const struct rte_cfgfile_parameters *params) } if (valid_comment == 0) { - printf("Error - invalid comment characters %c\n", + RTE_LOG(ERR, CFGFILE, "invalid comment characters %c\n", params->comment_character); return -ENOTSUP; } @@ -178,7 +179,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. " + RTE_LOG(ERR, CFGFILE, " line %d - no \\n found on string. " "Check if line too long\n", lineno); goto error1; } @@ -198,8 +199,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); + RTE_LOG(ERR, CFGFILE, + "line %d - no terminating ']' character found\n", + lineno); goto error1; } *end = '\0'; @@ -213,8 +215,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); + RTE_LOG(ERR, CFGFILE, + "line %d - no '=' character found\n", + lineno); goto error1; } *split[1] = '\0'; @@ -236,8 +239,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); + RTE_LOG(ERR, CFGFILE, + "line %d - cannot use empty values\n", + lineno); goto error1; } @@ -397,7 +401,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"); + + RTE_LOG(ERR, CFGFILE, "entry name doesn't exist\n"); return -EINVAL; } diff --git a/lib/librte_eal/common/include/rte_log.h b/lib/librte_eal/common/include/rte_log.h index cbb41846aaa3..fa747d5b90ef 100644 --- a/lib/librte_eal/common/include/rte_log.h +++ b/lib/librte_eal/common/include/rte_log.h @@ -62,6 +62,7 @@ extern struct rte_logs rte_logs; #define RTE_LOGTYPE_EFD 18 /**< Log related to EFD. */ #define RTE_LOGTYPE_EVENTDEV 19 /**< Log related to eventdev. */ #define RTE_LOGTYPE_GSO 20 /**< Log related to GSO. */ +#define RTE_LOGTYPE_CFGFILE 21 /**< Log related to cfgfile. */ /* these log types can be used in an application */ #define RTE_LOGTYPE_USER1 24 /**< User-defined log type 1. */ From patchwork Tue Jul 16 17:27:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 56531 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 B8BB71B9C9; Tue, 16 Jul 2019 19:28:00 +0200 (CEST) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by dpdk.org (Postfix) with ESMTP id 7821B4CE4 for ; Tue, 16 Jul 2019 19:27:54 +0200 (CEST) Received: by mail-pg1-f196.google.com with SMTP id s1so3464957pgr.2 for ; Tue, 16 Jul 2019 10:27:54 -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 :mime-version:content-transfer-encoding; bh=vRrqhYoOD+XwrMbiwT57dAa2bgdFnmDc6NXKuyewnRk=; b=YcBQjOerHdFSZHmbUzN41G/OD4r+u2xLFf/e60MMnADkkbrklnZpwsxFUFVgnArpaZ Iptips+lxVHZ+BnEOTMnbGjgOpkNImd3Ht0hfiAmZixG2YaqHTZnHWdwso30sDuZpM2L 0EwyTCRFxFEhE9FaP6kBCDLCxxUmYfby7f4Kp0YBsBnFWIWYH1xB2Uveg0qvrF7ZA3pU t+fEfp1MDdd5SskPQg4IE2LXCP6Q+ax4T55CvcF0f9ilQWXW5yZgjqbS0zunVd7LZmGc dYU7NMhUWyOZJDBmtF2M+hOpaFhD9Qg03Pq9wKzROeuYpaosfIeYFAQQIi8zunBp6Ijz ExrA== 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:mime-version:content-transfer-encoding; bh=vRrqhYoOD+XwrMbiwT57dAa2bgdFnmDc6NXKuyewnRk=; b=M7DVwtF17+Hy3hJs9WyPrSduyxc9CazMQI2jTZB+uOCm+wERQ3sLzPn6/2kEDBKTg6 GQZC2EcGP+PBXQZLepUEtA99AnpZlhCzF7CblwGtTtcm/vhca8bEgzi5DQuMjMKea0rs 8lYVvzge0pwfe/7bu6/2efE+QrXtvJ508614UFV9KAv9ykmPKXBnc/m9ZWyEmRFRNUTU i+7I1ViX0/6c7uvxmP9DnhgZazY3HdPpm+6hqDJlWj5OnnfuPWWg8+UIvCY2UEHgqnt1 yLH4VZbIhOiTM0xif+ZVATEu2oE3bH4ibSZ3kuKv77JCWUev5oAa59yOsQSzRxFMKSE5 g5kQ== X-Gm-Message-State: APjAAAUImALSWG4U2E7qnXxfr8ugd94FL9E0MSn99ViuOYxMm192WG4z OE+lk9PIU0keCJDNuUV0m/s= X-Google-Smtp-Source: APXvYqzz2blvcVStUFfiFCgMrKA912OQ9T8vAmz289fW44gm0dY39//ONhhDr+IooEiRhIlfPygCQA== X-Received: by 2002:a17:90a:346c:: with SMTP id o99mr37460729pjb.20.1563298073654; Tue, 16 Jul 2019 10:27:53 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id m6sm21173049pfb.151.2019.07.16.10.27.52 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 16 Jul 2019 10:27:52 -0700 (PDT) From: Stephen Hemminger To: cristian.dumitrescu@intel.com Cc: dev@dpdk.org, Stephen Hemminger Date: Tue, 16 Jul 2019 10:27:41 -0700 Message-Id: <20190716172741.21399-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190716172741.21399-1-stephen@networkplumber.org> References: <20190716172741.21399-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 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 c4b768b6833f..39fec4b82bce 100644 --- a/lib/librte_cfgfile/rte_cfgfile.c +++ b/lib/librte_cfgfile/rte_cfgfile.c @@ -275,17 +275,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;