Re: [RFC][PATCH 5/7] trace: make filter_parse_regex() provide the length of substring to compare with

From: Steven Rostedt
Date: Thu Feb 05 2015 - 16:29:42 EST


On Thu, 5 Feb 2015 19:56:38 +0000
Al Viro <viro@xxxxxxxxxxxxxxxxxx> wrote:

> From: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
>
> ... by passing len by address and using it to report the length of
> substring in question.

You certainly are very verbose in your change logs.

What exactly is the purpose of this patch? Clean up? Optimization?

I can't really tell. Seems like you are just moving the strlen() from
outside the function into it.


> --- a/kernel/trace/trace.h
> +++ b/kernel/trace/trace.h
> @@ -1051,7 +1051,7 @@ struct filter_pred {
> };
>
> extern enum regex_type
> -filter_parse_regex(char *buff, int len, char **search, int *not);
> +filter_parse_regex(char *buff, int *len, char **search, int *not);
> extern void print_event_filter(struct ftrace_event_file *file,
> struct trace_seq *s);
> extern int apply_event_filter(struct ftrace_event_file *file,
> diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
> index 6c4a96b..6a659e1 100644
> --- a/kernel/trace/trace_events_filter.c
> +++ b/kernel/trace/trace_events_filter.c
> @@ -321,7 +321,7 @@ static int regex_match_end(char *str, struct regex *r, int len)
> * not returns 1 if buff started with a '!'
> * 0 otherwise.
> */

@len above needs to be updated for kernel doc. The description should
also note what *len gets set to at the end.

> -enum regex_type filter_parse_regex(char *buff, int len, char **search, int *not)
> +enum regex_type filter_parse_regex(char *buff, int *len, char **search, int *not)
> {
> int type = MATCH_FULL;
> int i;
> @@ -329,13 +329,13 @@ enum regex_type filter_parse_regex(char *buff, int len, char **search, int *not)
> if (buff[0] == '!') {
> *not = 1;
> buff++;
> - len--;
> + (*len)--;
> } else
> *not = 0;
>
> *search = buff;
>
> - for (i = 0; i < len; i++) {
> + for (i = 0; i < *len; i++) {
> if (buff[i] == '*') {
> if (!i) {
> *search = buff + 1;
> @@ -350,6 +350,7 @@ enum regex_type filter_parse_regex(char *buff, int len, char **search, int *not)
> }
> }
> }
> + *len = strlen(*search);

We could optimize this even further:

*len = &buff[i] - *search;

-- Steve

>
> return type;
> }
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/