Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1362304imm; Tue, 5 Jun 2018 13:21:19 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLO9AOOiP3n1vxA9uWUaF2r+YT3dbMyJq0vo0hVtidu6n5tvWnwpfLDk+6sD4ZCnv1GVVJf X-Received: by 2002:a17:902:714e:: with SMTP id u14-v6mr88603plm.289.1528230079794; Tue, 05 Jun 2018 13:21:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528230079; cv=none; d=google.com; s=arc-20160816; b=RX5Xlwc1qrmSEr3qQKBC6NAZTQQ25a1eCjhlj+fKVBBywS2A2RE0SzS8t6Y0dIpdwA FfPqyOiHnzAHOz6/CfxuR31L4R2/uxFgAuiGWyT7MujnSesT86MRYzmdFMxfA3bbWPgY 8O++/WP6/ve9jfo+de/j46CAcbrMNzhwAFnPnbXj33JFzlzZX/AieOMiYkIWvjC4sGwT Jn93TrMaT2SBcT+Z0zqWczKZ+w7TvDzb/U4gss4GJrGAMbzZIxqKgjAvpifMo2fdWhDk PhLAHjQBWjX5LlIWP6O8fJZLnnS+lYaloOQGDpih5v7JFnNXCsBU7rOKmKrQWGt0fw3n bVjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=g1E4r2+o5G8vL8wHsG/49IDghwmXEowW8fSHE4NBB+A=; b=IROGe0i45MmN4noG6NcUuOmMJhT5Xhi1fRWGpHa4nvo3uJdFMBxE5NWsOalXlWO/yh qbDY+Old1uNWBCf2TFsUfoz/ZqAWc2yhvnDFSddviPLo0iUdd/QUyNlozNEuhkkKgIzD gJQmJkIkPgnz6NCFoOHIk82FYAEfYiEehRjkhGpNe4QH2E+MRGVsjEpwSO4vZy5Td9dG pE02EhfKtnmM2Sv9au0HFk/+62KxWUl2CFmOhuY+TkzKw0or/052HdKcuWdQyeokMg1w O0wPOD1V6AWa8+44RmsGJLz6fB5zAsvlTB65VDlIlEVydDpc3Z8EeRAUWzMoBoRNpf+5 786Q== 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 o9-v6si48616549plk.434.2018.06.05.13.21.05; Tue, 05 Jun 2018 13:21:19 -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 S1752638AbeFEUTZ (ORCPT + 99 others); Tue, 5 Jun 2018 16:19:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:40902 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752305AbeFEUTX (ORCPT ); Tue, 5 Jun 2018 16:19:23 -0400 Received: from gandalf.local.home (cpe-66-24-56-78.stny.res.rr.com [66.24.56.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5425D2083B; Tue, 5 Jun 2018 20:19:22 +0000 (UTC) Date: Tue, 5 Jun 2018 16:19:20 -0400 From: Steven Rostedt To: Andy Shevchenko Cc: Yisheng Xie , Ingo Molnar , Linux Kernel Mailing List Subject: Re: [PATCH] tracing: use match_string() to simplify the code Message-ID: <20180605161920.1f57aad1@gandalf.local.home> In-Reply-To: References: <1526546163-4609-1-git-send-email-xieyisheng1@huawei.com> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 5 Jun 2018 19:32:57 +0300 Andy Shevchenko wrote: > On Thu, May 17, 2018 at 11:36 AM, Yisheng Xie wrote: > > match_string() returns the index of an array for a matching string, > > which can be used to simplify the code. > > > > FWIW, > Reviewed-by: Andy Shevchenko Thanks for the reminder, I was going to add this patch, but haven't gotten to it. -- Steve > > > 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 > > > > >