Skip to content

Commit 5452af6

Browse files
fweisbecIngo Molnar
authored andcommitted
tracing/ftrace: factorize the tracing files creation
Impact: cleanup Most of the tracing files creation follow the same pattern: ret = debugfs_create_file(...) if (!ret) pr_warning("Couldn't create ... entry\n") Unify it! Reported-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> LKML-Reference: <1238109938-11840-1-git-send-email-fweisbec@gmail.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent a5dec55 commit 5452af6

8 files changed

Lines changed: 86 additions & 151 deletions

File tree

kernel/trace/ftrace.c

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2698,38 +2698,23 @@ static const struct file_operations ftrace_graph_fops = {
26982698

26992699
static __init int ftrace_init_dyn_debugfs(struct dentry *d_tracer)
27002700
{
2701-
struct dentry *entry;
27022701

2703-
entry = debugfs_create_file("available_filter_functions", 0444,
2704-
d_tracer, NULL, &ftrace_avail_fops);
2705-
if (!entry)
2706-
pr_warning("Could not create debugfs "
2707-
"'available_filter_functions' entry\n");
2702+
trace_create_file("available_filter_functions", 0444,
2703+
d_tracer, NULL, &ftrace_avail_fops);
27082704

2709-
entry = debugfs_create_file("failures", 0444,
2710-
d_tracer, NULL, &ftrace_failures_fops);
2711-
if (!entry)
2712-
pr_warning("Could not create debugfs 'failures' entry\n");
2705+
trace_create_file("failures", 0444,
2706+
d_tracer, NULL, &ftrace_failures_fops);
27132707

2714-
entry = debugfs_create_file("set_ftrace_filter", 0644, d_tracer,
2715-
NULL, &ftrace_filter_fops);
2716-
if (!entry)
2717-
pr_warning("Could not create debugfs "
2718-
"'set_ftrace_filter' entry\n");
2708+
trace_create_file("set_ftrace_filter", 0644, d_tracer,
2709+
NULL, &ftrace_filter_fops);
27192710

2720-
entry = debugfs_create_file("set_ftrace_notrace", 0644, d_tracer,
2711+
trace_create_file("set_ftrace_notrace", 0644, d_tracer,
27212712
NULL, &ftrace_notrace_fops);
2722-
if (!entry)
2723-
pr_warning("Could not create debugfs "
2724-
"'set_ftrace_notrace' entry\n");
27252713

27262714
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
2727-
entry = debugfs_create_file("set_graph_function", 0444, d_tracer,
2715+
trace_create_file("set_graph_function", 0444, d_tracer,
27282716
NULL,
27292717
&ftrace_graph_fops);
2730-
if (!entry)
2731-
pr_warning("Could not create debugfs "
2732-
"'set_graph_function' entry\n");
27332718
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
27342719

27352720
return 0;
@@ -2987,19 +2972,15 @@ static const struct file_operations ftrace_pid_fops = {
29872972
static __init int ftrace_init_debugfs(void)
29882973
{
29892974
struct dentry *d_tracer;
2990-
struct dentry *entry;
29912975

29922976
d_tracer = tracing_init_dentry();
29932977
if (!d_tracer)
29942978
return 0;
29952979

29962980
ftrace_init_dyn_debugfs(d_tracer);
29972981

2998-
entry = debugfs_create_file("set_ftrace_pid", 0644, d_tracer,
2999-
NULL, &ftrace_pid_fops);
3000-
if (!entry)
3001-
pr_warning("Could not create debugfs "
3002-
"'set_ftrace_pid' entry\n");
2982+
trace_create_file("set_ftrace_pid", 0644, d_tracer,
2983+
NULL, &ftrace_pid_fops);
30032984

30042985
ftrace_profile_debugfs(d_tracer);
30052986

kernel/trace/ring_buffer.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2845,14 +2845,11 @@ static const struct file_operations rb_simple_fops = {
28452845
static __init int rb_init_debugfs(void)
28462846
{
28472847
struct dentry *d_tracer;
2848-
struct dentry *entry;
28492848

28502849
d_tracer = tracing_init_dentry();
28512850

2852-
entry = debugfs_create_file("tracing_on", 0644, d_tracer,
2853-
&ring_buffer_flags, &rb_simple_fops);
2854-
if (!entry)
2855-
pr_warning("Could not create debugfs 'tracing_on' entry\n");
2851+
trace_create_file("tracing_on", 0644, d_tracer,
2852+
&ring_buffer_flags, &rb_simple_fops);
28562853

28572854
return 0;
28582855
}

kernel/trace/trace.c

Lines changed: 62 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -3581,7 +3581,7 @@ struct dentry *tracing_dentry_percpu(void)
35813581
static void tracing_init_debugfs_percpu(long cpu)
35823582
{
35833583
struct dentry *d_percpu = tracing_dentry_percpu();
3584-
struct dentry *entry, *d_cpu;
3584+
struct dentry *d_cpu;
35853585
/* strlen(cpu) + MAX(log10(cpu)) + '\0' */
35863586
char cpu_dir[7];
35873587

@@ -3596,21 +3596,15 @@ static void tracing_init_debugfs_percpu(long cpu)
35963596
}
35973597

35983598
/* per cpu trace_pipe */
3599-
entry = debugfs_create_file("trace_pipe", 0444, d_cpu,
3600-
(void *) cpu, &tracing_pipe_fops);
3601-
if (!entry)
3602-
pr_warning("Could not create debugfs 'trace_pipe' entry\n");
3599+
trace_create_file("trace_pipe", 0444, d_cpu,
3600+
(void *) cpu, &tracing_pipe_fops);
36033601

36043602
/* per cpu trace */
3605-
entry = debugfs_create_file("trace", 0644, d_cpu,
3606-
(void *) cpu, &tracing_fops);
3607-
if (!entry)
3608-
pr_warning("Could not create debugfs 'trace' entry\n");
3603+
trace_create_file("trace", 0644, d_cpu,
3604+
(void *) cpu, &tracing_fops);
36093605

3610-
entry = debugfs_create_file("trace_pipe_raw", 0444, d_cpu,
3611-
(void *) cpu, &tracing_buffers_fops);
3612-
if (!entry)
3613-
pr_warning("Could not create debugfs 'trace_pipe_raw' entry\n");
3606+
trace_create_file("trace_pipe_raw", 0444, d_cpu,
3607+
(void *) cpu, &tracing_buffers_fops);
36143608
}
36153609

36163610
#ifdef CONFIG_FTRACE_SELFTEST
@@ -3766,6 +3760,22 @@ static const struct file_operations trace_options_core_fops = {
37663760
.write = trace_options_core_write,
37673761
};
37683762

3763+
struct dentry *trace_create_file(const char *name,
3764+
mode_t mode,
3765+
struct dentry *parent,
3766+
void *data,
3767+
const struct file_operations *fops)
3768+
{
3769+
struct dentry *ret;
3770+
3771+
ret = debugfs_create_file(name, mode, parent, data, fops);
3772+
if (!ret)
3773+
pr_warning("Could not create debugfs '%s' entry\n", name);
3774+
3775+
return ret;
3776+
}
3777+
3778+
37693779
static struct dentry *trace_options_init_dentry(void)
37703780
{
37713781
struct dentry *d_tracer;
@@ -3793,7 +3803,6 @@ create_trace_option_file(struct trace_option_dentry *topt,
37933803
struct tracer_opt *opt)
37943804
{
37953805
struct dentry *t_options;
3796-
struct dentry *entry;
37973806

37983807
t_options = trace_options_init_dentry();
37993808
if (!t_options)
@@ -3802,11 +3811,9 @@ create_trace_option_file(struct trace_option_dentry *topt,
38023811
topt->flags = flags;
38033812
topt->opt = opt;
38043813

3805-
entry = debugfs_create_file(opt->name, 0644, t_options, topt,
3814+
topt->entry = trace_create_file(opt->name, 0644, t_options, topt,
38063815
&trace_options_fops);
38073816

3808-
topt->entry = entry;
3809-
38103817
}
38113818

38123819
static struct trace_option_dentry *
@@ -3861,123 +3868,81 @@ static struct dentry *
38613868
create_trace_option_core_file(const char *option, long index)
38623869
{
38633870
struct dentry *t_options;
3864-
struct dentry *entry;
38653871

38663872
t_options = trace_options_init_dentry();
38673873
if (!t_options)
38683874
return NULL;
38693875

3870-
entry = debugfs_create_file(option, 0644, t_options, (void *)index,
3876+
return trace_create_file(option, 0644, t_options, (void *)index,
38713877
&trace_options_core_fops);
3872-
3873-
return entry;
38743878
}
38753879

38763880
static __init void create_trace_options_dir(void)
38773881
{
38783882
struct dentry *t_options;
3879-
struct dentry *entry;
38803883
int i;
38813884

38823885
t_options = trace_options_init_dentry();
38833886
if (!t_options)
38843887
return;
38853888

3886-
for (i = 0; trace_options[i]; i++) {
3887-
entry = create_trace_option_core_file(trace_options[i], i);
3888-
if (!entry)
3889-
pr_warning("Could not create debugfs %s entry\n",
3890-
trace_options[i]);
3891-
}
3889+
for (i = 0; trace_options[i]; i++)
3890+
create_trace_option_core_file(trace_options[i], i);
38923891
}
38933892

38943893
static __init int tracer_init_debugfs(void)
38953894
{
38963895
struct dentry *d_tracer;
3897-
struct dentry *entry;
38983896
int cpu;
38993897

39003898
d_tracer = tracing_init_dentry();
39013899

3902-
entry = debugfs_create_file("tracing_enabled", 0644, d_tracer,
3903-
&global_trace, &tracing_ctrl_fops);
3904-
if (!entry)
3905-
pr_warning("Could not create debugfs 'tracing_enabled' entry\n");
3900+
trace_create_file("tracing_enabled", 0644, d_tracer,
3901+
&global_trace, &tracing_ctrl_fops);
39063902

3907-
entry = debugfs_create_file("trace_options", 0644, d_tracer,
3908-
NULL, &tracing_iter_fops);
3909-
if (!entry)
3910-
pr_warning("Could not create debugfs 'trace_options' entry\n");
3903+
trace_create_file("trace_options", 0644, d_tracer,
3904+
NULL, &tracing_iter_fops);
39113905

3912-
create_trace_options_dir();
3906+
trace_create_file("tracing_cpumask", 0644, d_tracer,
3907+
NULL, &tracing_cpumask_fops);
3908+
3909+
trace_create_file("trace", 0644, d_tracer,
3910+
(void *) TRACE_PIPE_ALL_CPU, &tracing_fops);
3911+
3912+
trace_create_file("available_tracers", 0444, d_tracer,
3913+
&global_trace, &show_traces_fops);
3914+
3915+
trace_create_file("current_tracer", 0444, d_tracer,
3916+
&global_trace, &set_tracer_fops);
3917+
3918+
trace_create_file("tracing_max_latency", 0644, d_tracer,
3919+
&tracing_max_latency, &tracing_max_lat_fops);
3920+
3921+
trace_create_file("tracing_thresh", 0644, d_tracer,
3922+
&tracing_thresh, &tracing_max_lat_fops);
39133923

3914-
entry = debugfs_create_file("tracing_cpumask", 0644, d_tracer,
3915-
NULL, &tracing_cpumask_fops);
3916-
if (!entry)
3917-
pr_warning("Could not create debugfs 'tracing_cpumask' entry\n");
3918-
3919-
entry = debugfs_create_file("trace", 0644, d_tracer,
3920-
(void *) TRACE_PIPE_ALL_CPU, &tracing_fops);
3921-
if (!entry)
3922-
pr_warning("Could not create debugfs 'trace' entry\n");
3923-
3924-
entry = debugfs_create_file("available_tracers", 0444, d_tracer,
3925-
&global_trace, &show_traces_fops);
3926-
if (!entry)
3927-
pr_warning("Could not create debugfs 'available_tracers' entry\n");
3928-
3929-
entry = debugfs_create_file("current_tracer", 0444, d_tracer,
3930-
&global_trace, &set_tracer_fops);
3931-
if (!entry)
3932-
pr_warning("Could not create debugfs 'current_tracer' entry\n");
3933-
3934-
entry = debugfs_create_file("tracing_max_latency", 0644, d_tracer,
3935-
&tracing_max_latency,
3936-
&tracing_max_lat_fops);
3937-
if (!entry)
3938-
pr_warning("Could not create debugfs "
3939-
"'tracing_max_latency' entry\n");
3940-
3941-
entry = debugfs_create_file("tracing_thresh", 0644, d_tracer,
3942-
&tracing_thresh, &tracing_max_lat_fops);
3943-
if (!entry)
3944-
pr_warning("Could not create debugfs "
3945-
"'tracing_thresh' entry\n");
3946-
entry = debugfs_create_file("README", 0644, d_tracer,
3947-
NULL, &tracing_readme_fops);
3948-
if (!entry)
3949-
pr_warning("Could not create debugfs 'README' entry\n");
3950-
3951-
entry = debugfs_create_file("trace_pipe", 0444, d_tracer,
3924+
trace_create_file("README", 0644, d_tracer,
3925+
NULL, &tracing_readme_fops);
3926+
3927+
trace_create_file("trace_pipe", 0444, d_tracer,
39523928
(void *) TRACE_PIPE_ALL_CPU, &tracing_pipe_fops);
3953-
if (!entry)
3954-
pr_warning("Could not create debugfs "
3955-
"'trace_pipe' entry\n");
3956-
3957-
entry = debugfs_create_file("buffer_size_kb", 0644, d_tracer,
3958-
&global_trace, &tracing_entries_fops);
3959-
if (!entry)
3960-
pr_warning("Could not create debugfs "
3961-
"'buffer_size_kb' entry\n");
3962-
3963-
entry = debugfs_create_file("trace_marker", 0220, d_tracer,
3964-
NULL, &tracing_mark_fops);
3965-
if (!entry)
3966-
pr_warning("Could not create debugfs "
3967-
"'trace_marker' entry\n");
3929+
3930+
trace_create_file("buffer_size_kb", 0644, d_tracer,
3931+
&global_trace, &tracing_entries_fops);
3932+
3933+
trace_create_file("trace_marker", 0220, d_tracer,
3934+
NULL, &tracing_mark_fops);
39683935

39693936
#ifdef CONFIG_DYNAMIC_FTRACE
3970-
entry = debugfs_create_file("dyn_ftrace_total_info", 0444, d_tracer,
3971-
&ftrace_update_tot_cnt,
3972-
&tracing_dyn_info_fops);
3973-
if (!entry)
3974-
pr_warning("Could not create debugfs "
3975-
"'dyn_ftrace_total_info' entry\n");
3937+
trace_create_file("dyn_ftrace_total_info", 0444, d_tracer,
3938+
&ftrace_update_tot_cnt, &tracing_dyn_info_fops);
39763939
#endif
39773940
#ifdef CONFIG_SYSPROF_TRACER
39783941
init_tracer_sysprof_debugfs(d_tracer);
39793942
#endif
39803943

3944+
create_trace_options_dir();
3945+
39813946
for_each_tracing_cpu(cpu)
39823947
tracing_init_debugfs_percpu(cpu);
39833948

kernel/trace/trace.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,12 @@ void trace_wake_up(void);
470470
void tracing_reset(struct trace_array *tr, int cpu);
471471
void tracing_reset_online_cpus(struct trace_array *tr);
472472
int tracing_open_generic(struct inode *inode, struct file *filp);
473+
struct dentry *trace_create_file(const char *name,
474+
mode_t mode,
475+
struct dentry *parent,
476+
void *data,
477+
const struct file_operations *fops);
478+
473479
struct dentry *tracing_init_dentry(void);
474480
void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
475481

kernel/trace/trace_event_profile.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,3 @@ void ftrace_profile_disable(int event_id)
2828
return event->profile_disable(event);
2929
}
3030
}
31-

kernel/trace/trace_printk.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,13 @@ static const struct file_operations ftrace_formats_fops = {
245245
static __init int init_trace_printk_function_export(void)
246246
{
247247
struct dentry *d_tracer;
248-
struct dentry *entry;
249248

250249
d_tracer = tracing_init_dentry();
251250
if (!d_tracer)
252251
return 0;
253252

254-
entry = debugfs_create_file("printk_formats", 0444, d_tracer,
253+
trace_create_file("printk_formats", 0444, d_tracer,
255254
NULL, &ftrace_formats_fops);
256-
if (!entry)
257-
pr_warning("Could not create debugfs "
258-
"'printk_formats' entry\n");
259255

260256
return 0;
261257
}

kernel/trace/trace_stack.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -352,19 +352,14 @@ __setup("stacktrace", enable_stacktrace);
352352
static __init int stack_trace_init(void)
353353
{
354354
struct dentry *d_tracer;
355-
struct dentry *entry;
356355

357356
d_tracer = tracing_init_dentry();
358357

359-
entry = debugfs_create_file("stack_max_size", 0644, d_tracer,
360-
&max_stack_size, &stack_max_size_fops);
361-
if (!entry)
362-
pr_warning("Could not create debugfs 'stack_max_size' entry\n");
358+
trace_create_file("stack_max_size", 0644, d_tracer,
359+
&max_stack_size, &stack_max_size_fops);
363360

364-
entry = debugfs_create_file("stack_trace", 0444, d_tracer,
365-
NULL, &stack_trace_fops);
366-
if (!entry)
367-
pr_warning("Could not create debugfs 'stack_trace' entry\n");
361+
trace_create_file("stack_trace", 0444, d_tracer,
362+
NULL, &stack_trace_fops);
368363

369364
if (stack_tracer_enabled)
370365
register_ftrace_function(&trace_ops);

0 commit comments

Comments
 (0)