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>
This commit is contained in:
parent
db59504d89
commit
be9742e6cb
@ -35,7 +35,6 @@
|
|||||||
#define KSYM_TRACER_MAX HBP_NUM
|
#define KSYM_TRACER_MAX HBP_NUM
|
||||||
|
|
||||||
#define KSYM_TRACER_OP_LEN 3 /* rw- */
|
#define KSYM_TRACER_OP_LEN 3 /* rw- */
|
||||||
#define KSYM_FILTER_ENTRY_LEN (KSYM_NAME_LEN + KSYM_TRACER_OP_LEN + 1)
|
|
||||||
|
|
||||||
struct trace_ksym {
|
struct trace_ksym {
|
||||||
struct hw_breakpoint *ksym_hbp;
|
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 trace_ksym *entry;
|
||||||
struct hlist_node *node;
|
struct hlist_node *node;
|
||||||
char buf[KSYM_FILTER_ENTRY_LEN * KSYM_TRACER_MAX];
|
struct trace_seq *s;
|
||||||
ssize_t ret, cnt = 0;
|
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);
|
mutex_lock(&ksym_tracer_mutex);
|
||||||
|
|
||||||
hlist_for_each_entry(entry, node, &ksym_filter_head, ksym_hlist) {
|
hlist_for_each_entry(entry, node, &ksym_filter_head, ksym_hlist) {
|
||||||
cnt += snprintf(&buf[cnt], KSYM_FILTER_ENTRY_LEN - cnt, "%s:",
|
ret = trace_seq_printf(s, "%s:", entry->ksym_hbp->info.name);
|
||||||
entry->ksym_hbp->info.name);
|
|
||||||
if (entry->ksym_hbp->info.type == HW_BREAKPOINT_WRITE)
|
if (entry->ksym_hbp->info.type == HW_BREAKPOINT_WRITE)
|
||||||
cnt += snprintf(&buf[cnt], KSYM_FILTER_ENTRY_LEN - cnt,
|
ret = trace_seq_puts(s, "-w-\n");
|
||||||
"-w-\n");
|
|
||||||
else if (entry->ksym_hbp->info.type == HW_BREAKPOINT_RW)
|
else if (entry->ksym_hbp->info.type == HW_BREAKPOINT_RW)
|
||||||
cnt += snprintf(&buf[cnt], KSYM_FILTER_ENTRY_LEN - cnt,
|
ret = trace_seq_puts(s, "rw-\n");
|
||||||
"rw-\n");
|
WARN_ON_ONCE(!ret);
|
||||||
}
|
}
|
||||||
ret = simple_read_from_buffer(ubuf, count, ppos, buf, strlen(buf));
|
|
||||||
|
cnt = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len);
|
||||||
|
|
||||||
mutex_unlock(&ksym_tracer_mutex);
|
mutex_unlock(&ksym_tracer_mutex);
|
||||||
|
|
||||||
return ret;
|
kfree(s);
|
||||||
|
|
||||||
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t ksym_trace_filter_write(struct file *file,
|
static ssize_t ksym_trace_filter_write(struct file *file,
|
||||||
|
Loading…
Reference in New Issue
Block a user