diff options
author | Li Zefan <lizf@cn.fujitsu.com> | 2009-07-07 01:52:52 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-07-10 05:59:40 -0400 |
commit | be9742e6cb107fe1d77db7a081ea4eb25e79e1ad (patch) | |
tree | 02730de2546677700ba98944b755c1bfbeee27ed /kernel/trace | |
parent | db59504d89db1462a5281fb55b1d962cb74a398f (diff) |
ksym_tracer: Rewrite ksym_trace_filter_read()
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.
Also reduce stack usage by about 512 bytes.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: "K.Prasad" <prasad@linux.vnet.ibm.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <4A52E2B4.6030706@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/trace')
-rw-r--r-- | 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 085ff055fdfa..b6710d31bdf0 100644 --- a/kernel/trace/trace_ksym.c +++ b/kernel/trace/trace_ksym.c | |||
@@ -35,7 +35,6 @@ | |||
35 | #define KSYM_TRACER_MAX HBP_NUM | 35 | #define KSYM_TRACER_MAX HBP_NUM |
36 | 36 | ||
37 | #define KSYM_TRACER_OP_LEN 3 /* rw- */ | 37 | #define KSYM_TRACER_OP_LEN 3 /* rw- */ |
38 | #define KSYM_FILTER_ENTRY_LEN (KSYM_NAME_LEN + KSYM_TRACER_OP_LEN + 1) | ||
39 | 38 | ||
40 | struct trace_ksym { | 39 | struct trace_ksym { |
41 | struct hw_breakpoint *ksym_hbp; | 40 | struct hw_breakpoint *ksym_hbp; |
@@ -230,25 +229,33 @@ static ssize_t ksym_trace_filter_read(struct file *filp, char __user *ubuf, | |||
230 | { | 229 | { |
231 | struct trace_ksym *entry; | 230 | struct trace_ksym *entry; |
232 | struct hlist_node *node; | 231 | struct hlist_node *node; |
233 | char buf[KSYM_FILTER_ENTRY_LEN * KSYM_TRACER_MAX]; | 232 | struct trace_seq *s; |
234 | ssize_t ret, cnt = 0; | 233 | ssize_t cnt = 0; |
234 | int ret; | ||
235 | |||
236 | s = kmalloc(sizeof(*s), GFP_KERNEL); | ||
237 | if (!s) | ||
238 | return -ENOMEM; | ||
239 | trace_seq_init(s); | ||
235 | 240 | ||
236 | mutex_lock(&ksym_tracer_mutex); | 241 | mutex_lock(&ksym_tracer_mutex); |
237 | 242 | ||
238 | hlist_for_each_entry(entry, node, &ksym_filter_head, ksym_hlist) { | 243 | hlist_for_each_entry(entry, node, &ksym_filter_head, ksym_hlist) { |
239 | cnt += snprintf(&buf[cnt], KSYM_FILTER_ENTRY_LEN - cnt, "%s:", | 244 | ret = trace_seq_printf(s, "%s:", entry->ksym_hbp->info.name); |
240 | entry->ksym_hbp->info.name); | ||
241 | if (entry->ksym_hbp->info.type == HW_BREAKPOINT_WRITE) | 245 | if (entry->ksym_hbp->info.type == HW_BREAKPOINT_WRITE) |
242 | cnt += snprintf(&buf[cnt], KSYM_FILTER_ENTRY_LEN - cnt, | 246 | ret = trace_seq_puts(s, "-w-\n"); |
243 | "-w-\n"); | ||
244 | else if (entry->ksym_hbp->info.type == HW_BREAKPOINT_RW) | 247 | else if (entry->ksym_hbp->info.type == HW_BREAKPOINT_RW) |
245 | cnt += snprintf(&buf[cnt], KSYM_FILTER_ENTRY_LEN - cnt, | 248 | ret = trace_seq_puts(s, "rw-\n"); |
246 | "rw-\n"); | 249 | WARN_ON_ONCE(!ret); |
247 | } | 250 | } |
248 | ret = simple_read_from_buffer(ubuf, count, ppos, buf, strlen(buf)); | 251 | |
252 | cnt = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len); | ||
253 | |||
249 | mutex_unlock(&ksym_tracer_mutex); | 254 | mutex_unlock(&ksym_tracer_mutex); |
250 | 255 | ||
251 | return ret; | 256 | kfree(s); |
257 | |||
258 | return cnt; | ||
252 | } | 259 | } |
253 | 260 | ||
254 | static ssize_t ksym_trace_filter_write(struct file *file, | 261 | static ssize_t ksym_trace_filter_write(struct file *file, |