LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [RFC][PATCH v2 3/7] trace_events_filter.c: switch to memcmp() and memmem() for matching
Date: Fri, 6 Feb 2015 11:24:29 -0500	[thread overview]
Message-ID: <20150206112429.6772a254@gandalf.local.home> (raw)
In-Reply-To: <1423195215-25134-3-git-send-email-viro@ZenIV.linux.org.uk>

On Fri,  6 Feb 2015 04:00:11 +0000
Al Viro <viro@ZenIV.linux.org.uk> wrote:

> From: Al Viro <viro@zeniv.linux.org.uk>
> 
> we know the lengths in advance...
> 
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> ---
>  kernel/trace/trace_events_filter.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
> index ced69da..6c4a96b 100644
> --- a/kernel/trace/trace_events_filter.c
> +++ b/kernel/trace/trace_events_filter.c
> @@ -271,21 +271,25 @@ static int filter_pred_none(struct filter_pred *pred, void *event)
>  
>  static int regex_match_full(char *str, struct regex *r, int len)
>  {
> -	if (strncmp(str, r->pattern, len) == 0)
> +	if (len - 1 != r->len)
> +		return 0;
> +	if (memcmp(str, r->pattern, r->len) == 0)
>  		return 1;
>  	return 0;
>  }
>  
>  static int regex_match_front(char *str, struct regex *r, int len)
>  {
> -	if (strncmp(str, r->pattern, r->len) == 0)
> +	if (len - 1 < r->len)
> +		return 0;
> +	if (memcmp(str, r->pattern, r->len) == 0)
>  		return 1;
>  	return 0;
>  }
>  
>  static int regex_match_middle(char *str, struct regex *r, int len)
>  {
> -	if (strnstr(str, r->pattern, len))
> +	if (memmem(str, len, r->pattern, r->len))

Since len includes '\0', shouldn't this be:

	if (memmem(str, len - 1, r->pattern, r->len);

It doesn't break the code either way, the algorithm still works, and
the original code did not pass in len-1 either. But if this is
optimizing the code, might as well eliminate one extra loop.

-- Steve

>  		return 1;
>  	return 0;
>  }


  reply	other threads:[~2015-02-06 16:24 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-05 19:49 [RFC][PATCHES] constifying ftrace globs Al Viro
2015-02-05 19:56 ` [RFC][PATCH 1/7] trace: fix the glob match in __unregister_ftrace_function_probe() Al Viro
2015-02-05 20:43   ` Steven Rostedt
2015-02-05 22:30     ` Al Viro
2015-02-05 22:52       ` Steven Rostedt
2015-02-05 19:56 ` [RFC][PATCH 2/7] implement memmem() Al Viro
2015-02-05 19:56 ` [RFC][PATCH 3/7] trace_events_filter.c: switch to memcmp() and memmem() for matching Al Viro
2015-02-05 19:56 ` [RFC][PATCH 4/7] ftrace: switch matching to memcmp() and memmem() Al Viro
2015-02-05 19:56 ` [RFC][PATCH 5/7] trace: make filter_parse_regex() provide the length of substring to compare with Al Viro
2015-02-05 21:29   ` Steven Rostedt
2015-02-05 21:44     ` Al Viro
2015-02-05 22:07       ` Steven Rostedt
2015-02-05 22:46         ` Al Viro
2015-02-06  4:00           ` [RFC][PATCH v2 1/7] trace: fix the glob match in __unregister_ftrace_function_probe() Al Viro
2015-02-06  4:00           ` [RFC][PATCH v2 2/7] implement memmem() Al Viro
2015-02-06 16:19             ` Steven Rostedt
2015-02-06 22:30             ` Rasmus Villemoes
2015-02-06 22:55               ` Steven Rostedt
2015-02-06 23:14                 ` Rasmus Villemoes
2015-02-06  4:00           ` [RFC][PATCH v2 3/7] trace_events_filter.c: switch to memcmp() and memmem() for matching Al Viro
2015-02-06 16:24             ` Steven Rostedt [this message]
2015-02-06  4:00           ` [RFC][PATCH v2 4/7] ftrace: switch matching to memcmp() and memmem() Al Viro
2015-02-06  4:00           ` [RFC][PATCH v2 5/7] trace: make filter_parse_regex() provide the length of substring to compare with Al Viro
2015-02-06 18:55             ` Steven Rostedt
2015-02-06  4:00           ` [RFC][PATCH v2 6/7] trace: constify filter_parse_regex(), match_records(), ftrace_match() and ftrace_match_record() Al Viro
2015-02-06 18:56             ` Steven Rostedt
2015-02-06  4:00           ` [RFC][PATCH v2 7/7] trace: constify glob arguments all way up to ftrace_function_set_regexp() Al Viro
2015-02-05 19:56 ` [RFC][PATCH 6/7] trace: constify filter_parse_regex(), match_records(), ftrace_match() and ftrace_match_record() Al Viro
2015-02-05 21:31   ` Steven Rostedt
2015-02-05 19:56 ` [RFC][PATCH 7/7] trace: constify glob arguments all way up to ftrace_function_set_regexp() Al Viro
2020-01-24 23:45 ` [RFC][PATCHES] constifying ftrace globs Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150206112429.6772a254@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@ZenIV.linux.org.uk \
    --subject='Re: [RFC][PATCH v2 3/7] trace_events_filter.c: switch to memcmp() and memmem() for matching' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).