From patchwork Mon May 20 14:47:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10951577 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 836F2933 for ; Mon, 20 May 2019 14:48:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 713C1287E0 for ; Mon, 20 May 2019 14:48:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 65BAE288E0; Mon, 20 May 2019 14:48:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E1FC828911 for ; Mon, 20 May 2019 14:48:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B9488892C6; Mon, 20 May 2019 14:48:12 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0BAF08929D; Mon, 20 May 2019 14:47:59 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 May 2019 07:47:59 -0700 X-ExtLoop1: 1 Received: from dmironox-mobl5.ccr.corp.intel.com (HELO localhost.localdomain) ([10.252.20.122]) by fmsmga007.fm.intel.com with ESMTP; 20 May 2019 07:47:58 -0700 From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org Date: Mon, 20 May 2019 15:47:25 +0100 Message-Id: <20190520144739.13111-14-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190520144739.13111-1-tvrtko.ursulin@linux.intel.com> References: <20190520144739.13111-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t 13/27] gem_wsim: Save some lines by changing to implicit NULL checking X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin We can improve the parsing loop readability a bit more by avoiding some line breaks caused by explicit NULL checks. Signed-off-by: Tvrtko Ursulin Reviewed-by: Chris Wilson --- benchmarks/gem_wsim.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/benchmarks/gem_wsim.c b/benchmarks/gem_wsim.c index e5b12e37490e..baa389c3f0e7 100644 --- a/benchmarks/gem_wsim.c +++ b/benchmarks/gem_wsim.c @@ -391,7 +391,7 @@ parse_workload(struct w_arg *arg, unsigned int flags, struct workload *app_w) igt_assert(desc); - while ((_token = strtok_r(tstart, ",", &tctx)) != NULL) { + while ((_token = strtok_r(tstart, ",", &tctx))) { tstart = NULL; token = strdup(_token); igt_assert(token); @@ -399,12 +399,11 @@ parse_workload(struct w_arg *arg, unsigned int flags, struct workload *app_w) valid = 0; memset(&step, 0, sizeof(step)); - if ((field = strtok_r(fstart, ".", &fctx)) != NULL) { + if ((field = strtok_r(fstart, ".", &fctx))) { fstart = NULL; if (!strcmp(field, "d")) { - if ((field = strtok_r(fstart, ".", &fctx)) != - NULL) { + if ((field = strtok_r(fstart, ".", &fctx))) { tmp = atoi(field); check_arg(tmp <= 0, "Invalid delay at step %u!\n", @@ -414,8 +413,7 @@ parse_workload(struct w_arg *arg, unsigned int flags, struct workload *app_w) goto add_step; } } else if (!strcmp(field, "p")) { - if ((field = strtok_r(fstart, ".", &fctx)) != - NULL) { + if ((field = strtok_r(fstart, ".", &fctx))) { tmp = atoi(field); check_arg(tmp <= 0, "Invalid period at step %u!\n", @@ -426,8 +424,7 @@ parse_workload(struct w_arg *arg, unsigned int flags, struct workload *app_w) } } else if (!strcmp(field, "P")) { unsigned int nr = 0; - while ((field = strtok_r(fstart, ".", &fctx)) != - NULL) { + while ((field = strtok_r(fstart, ".", &fctx))) { tmp = atoi(field); check_arg(nr == 0 && tmp <= 0, "Invalid context at step %u!\n", @@ -447,8 +444,7 @@ parse_workload(struct w_arg *arg, unsigned int flags, struct workload *app_w) step.type = CTX_PRIORITY; goto add_step; } else if (!strcmp(field, "s")) { - if ((field = strtok_r(fstart, ".", &fctx)) != - NULL) { + if ((field = strtok_r(fstart, ".", &fctx))) { tmp = atoi(field); check_arg(tmp >= 0 || ((int)nr_steps + tmp) < 0, @@ -459,8 +455,7 @@ parse_workload(struct w_arg *arg, unsigned int flags, struct workload *app_w) goto add_step; } } else if (!strcmp(field, "t")) { - if ((field = strtok_r(fstart, ".", &fctx)) != - NULL) { + if ((field = strtok_r(fstart, ".", &fctx))) { tmp = atoi(field); check_arg(tmp < 0, "Invalid throttle at step %u!\n", @@ -470,8 +465,7 @@ parse_workload(struct w_arg *arg, unsigned int flags, struct workload *app_w) goto add_step; } } else if (!strcmp(field, "q")) { - if ((field = strtok_r(fstart, ".", &fctx)) != - NULL) { + if ((field = strtok_r(fstart, ".", &fctx))) { tmp = atoi(field); check_arg(tmp < 0, "Invalid qd throttle at step %u!\n", @@ -481,8 +475,7 @@ parse_workload(struct w_arg *arg, unsigned int flags, struct workload *app_w) goto add_step; } } else if (!strcmp(field, "a")) { - if ((field = strtok_r(fstart, ".", &fctx)) != - NULL) { + if ((field = strtok_r(fstart, ".", &fctx))) { tmp = atoi(field); check_arg(tmp >= 0, "Invalid sw fence signal at step %u!\n", @@ -496,8 +489,7 @@ parse_workload(struct w_arg *arg, unsigned int flags, struct workload *app_w) goto add_step; } else if (!strcmp(field, "M")) { unsigned int nr = 0; - while ((field = strtok_r(fstart, ".", &fctx)) != - NULL) { + while ((field = strtok_r(fstart, ".", &fctx))) { tmp = atoi(field); check_arg(nr == 0 && tmp <= 0, "Invalid context at step %u!\n", @@ -523,8 +515,7 @@ parse_workload(struct w_arg *arg, unsigned int flags, struct workload *app_w) goto add_step; } else if (!strcmp(field, "X")) { unsigned int nr = 0; - while ((field = strtok_r(fstart, ".", &fctx)) != - NULL) { + while ((field = strtok_r(fstart, ".", &fctx))) { tmp = atoi(field); check_arg(nr == 0 && tmp <= 0, "Invalid context at step %u!\n", @@ -564,7 +555,7 @@ parse_workload(struct w_arg *arg, unsigned int flags, struct workload *app_w) valid++; } - if ((field = strtok_r(fstart, ".", &fctx)) != NULL) { + if ((field = strtok_r(fstart, ".", &fctx))) { fstart = NULL; i = str_to_engine(field); @@ -579,7 +570,7 @@ parse_workload(struct w_arg *arg, unsigned int flags, struct workload *app_w) bcs_used = true; } - if ((field = strtok_r(fstart, ".", &fctx)) != NULL) { + if ((field = strtok_r(fstart, ".", &fctx))) { char *sep = NULL; long int tmpl; @@ -607,7 +598,7 @@ parse_workload(struct w_arg *arg, unsigned int flags, struct workload *app_w) valid++; } - if ((field = strtok_r(fstart, ".", &fctx)) != NULL) { + if ((field = strtok_r(fstart, ".", &fctx))) { fstart = NULL; tmp = parse_dependencies(nr_steps, &step, field); @@ -617,7 +608,7 @@ parse_workload(struct w_arg *arg, unsigned int flags, struct workload *app_w) valid++; } - if ((field = strtok_r(fstart, ".", &fctx)) != NULL) { + if ((field = strtok_r(fstart, ".", &fctx))) { fstart = NULL; check_arg(strlen(field) != 1 ||