All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tracing: use match_string() to simplify the code
@ 2018-05-17  8:36 Yisheng Xie
  2018-06-05 16:32 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Yisheng Xie @ 2018-05-17  8:36 UTC (permalink / raw)
  To: rostedt, mingo; +Cc: linux-kernel, Yisheng Xie

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 <xieyisheng1@huawei.com>
---
 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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] tracing: use match_string() to simplify the code
  2018-05-17  8:36 [PATCH] tracing: use match_string() to simplify the code Yisheng Xie
@ 2018-06-05 16:32 ` Andy Shevchenko
  2018-06-05 20:19   ` Steven Rostedt
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2018-06-05 16:32 UTC (permalink / raw)
  To: Yisheng Xie; +Cc: Steven Rostedt, Ingo Molnar, Linux Kernel Mailing List

On Thu, May 17, 2018 at 11:36 AM, Yisheng Xie <xieyisheng1@huawei.com> 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 <andy.shevchenko@gmail.com>

> Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
> ---
>  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
>



-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tracing: use match_string() to simplify the code
  2018-06-05 16:32 ` Andy Shevchenko
@ 2018-06-05 20:19   ` Steven Rostedt
  0 siblings, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2018-06-05 20:19 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Yisheng Xie, Ingo Molnar, Linux Kernel Mailing List

On Tue, 5 Jun 2018 19:32:57 +0300
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:

> On Thu, May 17, 2018 at 11:36 AM, Yisheng Xie <xieyisheng1@huawei.com> 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 <andy.shevchenko@gmail.com>

Thanks for the reminder, I was going to add this patch, but haven't
gotten to it.

-- Steve

> 
> > Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
> > ---
> >  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
> >  
> 
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-06-05 20:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-17  8:36 [PATCH] tracing: use match_string() to simplify the code Yisheng Xie
2018-06-05 16:32 ` Andy Shevchenko
2018-06-05 20:19   ` Steven Rostedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.