public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "K.Prasad" <prasad@linux.vnet.ibm.com>
To: Li Zefan <lizf@cn.fujitsu.com>
Cc: Ingo Molnar <mingo@elte.hu>,
	Alan Stern <stern@rowland.harvard.edu>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/8] ksym_tracer: Rewrite ksym_trace_filter_read()
Date: Sat, 11 Jul 2009 11:24:18 +0530	[thread overview]
Message-ID: <20090711055418.GA7686@in.ibm.com> (raw)
In-Reply-To: <4A52E2B4.6030706@cn.fujitsu.com>

On Tue, Jul 07, 2009 at 01:52:52PM +0800, Li Zefan wrote:
> Reading ksym_trace_filter gave me some arbitrary characters,
> when it should show nothing. It's because buf is not initialized
> when there's no filter.
> 

I started noticing this behaviour recently.

A simple
char buf[KSYM_FILTER_ENTRY_LEN * KSYM_TRACER_MAX] = "\0";
solves the problem.

> Also reduce stack usage by about 512 bytes.
> 

The stack usage would be much lesser on other architectures with fewer
breakpoint registers (like PPC64), and should really be an issue.

> Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
> ---
>  kernel/trace/trace_ksym.c |   29 ++++++++++++++++++-----------
>  1 files changed, 18 insertions(+), 11 deletions(-)
> 
> diff --git a/kernel/trace/trace_ksym.c b/kernel/trace/trace_ksym.c
> index 085ff05..b6710d3 100644
> --- a/kernel/trace/trace_ksym.c
> +++ b/kernel/trace/trace_ksym.c
> @@ -35,7 +35,6 @@
>  #define KSYM_TRACER_MAX HBP_NUM
> 
>  #define KSYM_TRACER_OP_LEN 3 /* rw- */
> -#define KSYM_FILTER_ENTRY_LEN (KSYM_NAME_LEN + KSYM_TRACER_OP_LEN + 1)
> 
>  struct trace_ksym {
>  	struct hw_breakpoint	*ksym_hbp;
> @@ -230,25 +229,33 @@ static ssize_t ksym_trace_filter_read(struct file *filp, char __user *ubuf,
>  {
>  	struct trace_ksym *entry;
>  	struct hlist_node *node;
> -	char buf[KSYM_FILTER_ENTRY_LEN * KSYM_TRACER_MAX];
> -	ssize_t ret, cnt = 0;
> +	struct trace_seq *s;
> +	ssize_t cnt = 0;
> +	int ret;
> +
> +	s = kmalloc(sizeof(*s), GFP_KERNEL);
> +	if (!s)
> +		return -ENOMEM;
> +	trace_seq_init(s);
> 
>  	mutex_lock(&ksym_tracer_mutex);
> 
>  	hlist_for_each_entry(entry, node, &ksym_filter_head, ksym_hlist) {
> -		cnt += snprintf(&buf[cnt], KSYM_FILTER_ENTRY_LEN - cnt, "%s:",
> -				entry->ksym_hbp->info.name);
> +		ret = trace_seq_printf(s, "%s:", entry->ksym_hbp->info.name);
>  		if (entry->ksym_hbp->info.type == HW_BREAKPOINT_WRITE)
> -			cnt += snprintf(&buf[cnt], KSYM_FILTER_ENTRY_LEN - cnt,
> -								"-w-\n");
> +			ret = trace_seq_puts(s, "-w-\n");
>  		else if (entry->ksym_hbp->info.type == HW_BREAKPOINT_RW)
> -			cnt += snprintf(&buf[cnt], KSYM_FILTER_ENTRY_LEN - cnt,
> -								"rw-\n");
> +			ret = trace_seq_puts(s, "rw-\n");
> +		WARN_ON_ONCE(!ret);

Given that this change uses the tracer defined functions and a seq-file
implementation, the patch is welcome.

Thanks,
K.Prasad


  parent reply	other threads:[~2009-07-11  5:54 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-07  5:52 [PATCH 0/8] ksym_tracer: various fixes Li Zefan
2009-07-07  5:52 ` [PATCH 1/8] ksym_tracer: Extract trace entry from struct trace_ksym Li Zefan
2009-07-07 21:25   ` Frederic Weisbecker
2009-07-08  0:55     ` Li Zefan
2009-11-21 13:33   ` [tip:perf/core] " tip-bot for Li Zefan
2009-07-07  5:52 ` [PATCH 2/8] ksym_tracer: Rewrite ksym_trace_filter_read() Li Zefan
2009-07-07 21:29   ` Frederic Weisbecker
2009-07-11  5:54   ` K.Prasad [this message]
2009-11-21 13:34   ` [tip:perf/core] " tip-bot for Li Zefan
2009-07-07  5:53 ` [PATCH 3/8] ksym_tracer: Fix validation of access type Li Zefan
2009-11-21 13:34   ` [tip:perf/core] " tip-bot for Li Zefan
2009-07-07  5:53 ` [PATCH 4/8] ksym_tracer: Fix validation of length " Li Zefan
2009-11-21 13:34   ` [tip:perf/core] " tip-bot for Li Zefan
2009-07-07  5:54 ` [PATCH 5/8] ksym_tracer: NIL-terminate user input filter Li Zefan
2009-11-21 13:34   ` [tip:perf/core] " tip-bot for Li Zefan
2009-07-07  5:54 ` [PATCH 6/8] ksym_tracer: Report error when failed to re-register hbp Li Zefan
2009-11-21 13:34   ` [tip:perf/core] " tip-bot for Li Zefan
2009-07-07  5:54 ` [PATCH 7/8] ksym_tracer: Fix memory leak Li Zefan
2009-11-21 13:35   ` [tip:perf/core] " tip-bot for Li Zefan
2009-07-07  5:55 ` [PATCH 8/8] ksym_tracer: Fix the output of stat tracing Li Zefan
2009-11-21 13:35   ` [tip:perf/core] " tip-bot for Li Zefan
2009-07-07 23:18 ` [PATCH 0/8] ksym_tracer: various fixes Frederic Weisbecker
2009-07-10 10:01   ` Ingo Molnar
2009-07-11  5:54   ` K.Prasad

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=20090711055418.GA7686@in.ibm.com \
    --to=prasad@linux.vnet.ibm.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.org \
    --cc=stern@rowland.harvard.edu \
    /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