Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3016403imm; Thu, 17 May 2018 01:47:12 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr7TEyO/yTwFQdjCw0oR/lcNRpre3ax5lk3tb64BW2CdpePjAJJYF9sSW/aPsyDvDOxI2Yu X-Received: by 2002:a63:7341:: with SMTP id d1-v6mr3378975pgn.404.1526546831913; Thu, 17 May 2018 01:47:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526546831; cv=none; d=google.com; s=arc-20160816; b=rvxDdX7nNDyVNQoBRXIQZQJMvEgeVSlX+yATMoIH3/D8Z5wE/5nay8N8HkuQ9tREm4 n9Fp0EV1780NvVB8LYSYOMfZIXodx5F6ZTho9GjOoySEQvBBiexhpzkJD4u0lxPCK6I3 zsXw1erHJP0cioTIGF5QUED7pqMfL6N5OATwa8K5Jk++hbOQToe3zxba3eXVW97dxCzO CCt5AU7zNDmuhFhLNRcEnjNwwf4yxCDxUILJGrbIUfq/sstnHFonBPnQcAo+mjD5SJff m+oRMmX7AJKH3fuNhs30Q9FRYh5LsTaF20SVeTPt3tYFSmVwSKsUlFoAIyjtOi2b8OEf 0IBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=wFfjpSndUwrCy9ay8WMbVG0+fU9Z5HfTd52AKS+FRdI=; b=qCT2b3Ce7RHoH1DSE9SSqnrU7XlkCTy14z87R7v3MIotlzvADawSPzvfj/PuqXq6wC grwP1X0b3XWkOloC8S/HBFiEtlaCt67PWhI5DfA+l7zWKXu8/gT3eu65Id0TjNZ3Hus3 L8mVEhHwKeWSJWGLFvZ4rNyHBPXi+0haUskYe1JY2x8mIVgnVQMOnvy/g+jnZb0Hv085 G8lQAqURnaHvBsoLrRDcRPM9fmNiBPe/8xZlxvW9q13qpsCMjb2wYAiffLY+Z/C3/xGW PiB69lWvgXhCOnPmGj4Mgh4vCUkU2H3+en7btP8UzEqw35yku3LrmBVJzIVmEqlF1UKJ ztCw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a98-v6si4609362pla.239.2018.05.17.01.46.57; Thu, 17 May 2018 01:47:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751427AbeEQIql (ORCPT + 99 others); Thu, 17 May 2018 04:46:41 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:57718 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750891AbeEQIqj (ORCPT ); Thu, 17 May 2018 04:46:39 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 26AC94792B97E; Thu, 17 May 2018 16:46:36 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.382.0; Thu, 17 May 2018 16:46:31 +0800 From: Yisheng Xie To: , CC: , Yisheng Xie Subject: [PATCH] tracing: use match_string() to simplify the code Date: Thu, 17 May 2018 16:36:03 +0800 Message-ID: <1526546163-4609-1-git-send-email-xieyisheng1@huawei.com> X-Mailer: git-send-email 1.7.12.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.102.37] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org match_string() returns the index of an array for a matching string, which can be used to simplify the code. Signed-off-by: Yisheng Xie --- kernel/trace/trace.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 414d721..4bd653a 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -4395,8 +4395,7 @@ static int trace_set_options(struct trace_array *tr, char *option) { char *cmp; int neg = 0; - int ret = -ENODEV; - int i; + int ret; size_t orig_len = strlen(option); cmp = strstrip(option); @@ -4408,16 +4407,12 @@ static int trace_set_options(struct trace_array *tr, char *option) mutex_lock(&trace_types_lock); - for (i = 0; trace_options[i]; i++) { - if (strcmp(cmp, trace_options[i]) == 0) { - ret = set_tracer_flag(tr, 1 << i, !neg); - break; - } - } - + ret = match_string(trace_options, -1, cmp); /* If no option could be set, test the specific tracer options */ - if (!trace_options[i]) + if (ret < 0) ret = set_tracer_option(tr, cmp, neg); + else + ret = set_tracer_flag(tr, 1 << ret, !neg); mutex_unlock(&trace_types_lock); -- 1.7.12.4