Skip to content

Commit 0588fa3

Browse files
Steven Rostedtrostedt
authored andcommitted
tracing: Convert trace_printk() formats for module to const char *
The trace_printk() formats for modules do not show up in the debugfs/tracing/printk_formats file. Only the formats that are for trace_printk()s that are in the kernel core. To facilitate the change to add trace_printk() formats from modules into that file as well, we need to convert the structure that holds the formats from char fmt[], into const char *fmt, and allocate them separately. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 176fcc5 commit 0588fa3

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

‎kernel/trace/trace_printk.c‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static DEFINE_MUTEX(btrace_mutex);
3232

3333
struct trace_bprintk_fmt {
3434
struct list_head list;
35-
char fmt[0];
35+
const char *fmt;
3636
};
3737

3838
static inline struct trace_bprintk_fmt *lookup_format(const char *fmt)
@@ -49,6 +49,7 @@ static
4949
void hold_module_trace_bprintk_format(const char **start, const char **end)
5050
{
5151
const char **iter;
52+
char *fmt;
5253

5354
mutex_lock(&btrace_mutex);
5455
for (iter = start; iter < end; iter++) {
@@ -58,14 +59,18 @@ void hold_module_trace_bprintk_format(const char **start, const char **end)
5859
continue;
5960
}
6061

61-
tb_fmt = kmalloc(offsetof(struct trace_bprintk_fmt, fmt)
62-
+ strlen(*iter) + 1, GFP_KERNEL);
63-
if (tb_fmt) {
62+
tb_fmt = kmalloc(sizeof(*tb_fmt), GFP_KERNEL);
63+
if (tb_fmt)
64+
fmt = kmalloc(strlen(*iter) + 1, GFP_KERNEL);
65+
if (tb_fmt && fmt) {
6466
list_add_tail(&tb_fmt->list, &trace_bprintk_fmt_list);
65-
strcpy(tb_fmt->fmt, *iter);
67+
strcpy(fmt, *iter);
68+
tb_fmt->fmt = fmt;
6669
*iter = tb_fmt->fmt;
67-
} else
70+
} else {
71+
kfree(tb_fmt);
6872
*iter = NULL;
73+
}
6974
}
7075
mutex_unlock(&btrace_mutex);
7176
}

0 commit comments

Comments
 (0)