mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: jolsa@redhat.com
Cc: mingo@elte.hu, linux-kernel@vger.kernel.org,
	Frederic Weisbecker <fweisbec@gmail.com>
Subject: Re: [PATCHv2 2/3] tracing - buf iterator support for set_event
Date: Thu, 10 Sep 2009 16:35:33 -0400	[thread overview]
Message-ID: <1252614934.18996.29.camel@gandalf.stny.rr.com> (raw)
In-Reply-To: <1252113181-3325-3-git-send-email-jolsa@redhat.com>

On Sat, 2009-09-05 at 03:13 +0200, jolsa@redhat.com wrote:
> Updated 'set_event' write method to use the 'trace_get_user' function.
> 
> wbr,
> jirka
> 
> Signed-off-by: Jiri Olsa <jolsa@redhat.com>
> 
> ---
>  kernel/trace/trace_events.c |   58 +++++++++---------------------------------
>  1 files changed, 13 insertions(+), 45 deletions(-)
> 
> diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
> index d33bcde..7e5703c 100644
> --- a/kernel/trace/trace_events.c
> +++ b/kernel/trace/trace_events.c
> @@ -230,11 +230,9 @@ static ssize_t
>  ftrace_event_write(struct file *file, const char __user *ubuf,
>  		   size_t cnt, loff_t *ppos)
>  {
> +	struct trace_biter biter;

s/biter/parser/g

>  	size_t read = 0;
> -	int i, set = 1;
>  	ssize_t ret;
> -	char *buf;
> -	char ch;
>  
>  	if (!cnt || cnt < 0)
>  		return 0;
> @@ -243,60 +241,30 @@ ftrace_event_write(struct file *file, const char __user *ubuf,
>  	if (ret < 0)
>  		return ret;
>  
> -	ret = get_user(ch, ubuf++);
> -	if (ret)
> -		return ret;
> -	read++;
> -	cnt--;
> -
> -	/* skip white space */
> -	while (cnt && isspace(ch)) {
> -		ret = get_user(ch, ubuf++);
> -		if (ret)
> -			return ret;
> -		read++;
> -		cnt--;
> -	}
> -
> -	/* Only white space found? */
> -	if (isspace(ch)) {
> -		file->f_pos += read;
> -		ret = read;
> -		return ret;
> -	}
> -
> -	buf = kmalloc(EVENT_BUF_SIZE+1, GFP_KERNEL);
> -	if (!buf)
> +	if (trace_biter_alloc(&biter, EVENT_BUF_SIZE + 1))
>  		return -ENOMEM;
>  
> -	if (cnt > EVENT_BUF_SIZE)
> -		cnt = EVENT_BUF_SIZE;
> +	read = trace_get_user(&biter, ubuf, cnt, ppos);
> +
> +	if (TRACE_BITER_LOADED((&biter))) {
> +		char *buf = biter.buffer;

If you have encapsulated the access to parser with trace_parser_loaded,
might as well do the same for getting the buffer:

static inline char *trace_parser_buffer(struct trace_parser *parser)
{
	return parser->buffer;
}


> +		int set = 1;
>  
> -	i = 0;
> -	while (cnt && !isspace(ch)) {
> -		if (!i && ch == '!')
> +		if (*buf == '!') {
>  			set = 0;
> -		else
> -			buf[i++] = ch;
> +			buf++;

I had a funny trick in my patches to instead of incrementing buf here, I
passed in below a:

	ftrace_set_clr_event(buf + !!set, set);

But whatever ;-)

> +		}
> +		biter.buffer[biter.idx] = 0;

here you are accessing both the buffer and idx directly. Might as well
do it everywhere like this and don't use the helper functions.

-- Steve

>  
> -		ret = get_user(ch, ubuf++);
> +		ret = ftrace_set_clr_event(buf, set);
>  		if (ret)
>  			goto out_free;
> -		read++;
> -		cnt--;
>  	}
> -	buf[i] = 0;
> -
> -	file->f_pos += read;
> -
> -	ret = ftrace_set_clr_event(buf, set);
> -	if (ret)
> -		goto out_free;
>  
>  	ret = read;
>  
>   out_free:
> -	kfree(buf);
> +	trace_biter_free(&biter);
>  
>  	return ret;
>  }


  reply	other threads:[~2009-09-10 20:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-05  1:12 [PATCHv2 0/3] tracing - adding common method for reading/parsing user input jolsa
2009-09-05  1:12 ` [PATCHv2 1/3] tracing - buf iterator definition, parsing function jolsa
2009-09-08 13:47   ` Steven Rostedt
2009-09-10 20:29   ` Steven Rostedt
2009-09-05  1:13 ` [PATCHv2 2/3] tracing - buf iterator support for set_event jolsa
2009-09-10 20:35   ` Steven Rostedt [this message]
2009-09-05  1:13 ` [PATCHv2 3/3] tracing - buf iterator support for set_graph_function set_ftrace_filter set_ftrace_notrace jolsa
2009-09-10 20:43   ` Steven Rostedt
2009-09-05  2:41 ` [PATCHv2 0/3] tracing - adding common method for reading/parsing user input Daniel Walker
2009-09-05  6:40   ` Jiri Olsa
2009-09-05 13:02     ` Steven Rostedt
2009-09-08 14:01 ` Steven Rostedt
2009-09-08 14:37   ` Jiri Olsa
2009-09-08 14:44     ` Steven Rostedt
2009-09-08 14:46       ` Jiri Olsa

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=1252614934.18996.29.camel@gandalf.stny.rr.com \
    --to=rostedt@goodmis.org \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®