Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2999834AbdDZMWz (ORCPT ); Wed, 26 Apr 2017 08:22:55 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34422 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2999702AbdDZMVn (ORCPT ); Wed, 26 Apr 2017 08:21:43 -0400 From: Taeung Song To: Arnaldo Carvalho de Melo Cc: linux-kernel@vger.kernel.org, Jiri Olsa , Namhyung Kim , Taeung Song Subject: [PATCH 4/7] perf config: Invert if statements to reduce nesting in cmd_config() Date: Wed, 26 Apr 2017 21:21:05 +0900 Message-Id: <1493209268-5543-5-git-send-email-treeze.taeung@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1493209268-5543-1-git-send-email-treeze.taeung@gmail.com> References: <1493209268-5543-1-git-send-email-treeze.taeung@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1670 Lines: 74 Cc: Jiri Olsa Cc: Namhyung Kim Signed-off-by: Taeung Song --- tools/perf/builtin-config.c | 50 ++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c index ad0a112..f4596ef 100644 --- a/tools/perf/builtin-config.c +++ b/tools/perf/builtin-config.c @@ -203,33 +203,37 @@ int cmd_config(int argc, const char **argv) } break; default: - if (argc) { - for (i = 0; argv[i]; i++) { - char *var, *value; - char *arg = strdup(argv[i]); - - if (!arg) { - pr_err("%s: strdup failed\n", __func__); - ret = -1; - break; - } + if (!argc) { + usage_with_options(config_usage, config_options); + break; + } - if (parse_config_arg(arg, &var, &value) < 0) { - free(arg); - ret = -1; - break; - } + for (i = 0; argv[i]; i++) { + char *var, *value; + char *arg = strdup(argv[i]); + + if (!arg) { + pr_err("%s: strdup failed\n", __func__); + ret = -1; + break; + } - if (value == NULL) { - ret = show_spec_config(set, var); - if (ret < 0) - goto none_err; - } else - ret = set_config(set, config_filename, var, value); + if (parse_config_arg(arg, &var, &value) < 0) { free(arg); + ret = -1; + break; } - } else - usage_with_options(config_usage, config_options); + + if (value) { + ret = set_config(set, config_filename, var, value); + continue; + } + ret = show_spec_config(set, var); + if (ret < 0) + goto none_err; + + free(arg); + } } none_err: -- 2.7.4