Skip to content

Commit c33fff0

Browse files
dlunevtorvalds
authored andcommitted
kernel: use non-racy method for proc entries creation
Use proc_create()/proc_create_data() to make sure that ->proc_fops and ->data be setup before gluing PDE to main tree. Signed-off-by: Denis V. Lunev <den@openvz.org> Cc: Alexey Dobriyan <adobriyan@gmail.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Ingo Molnar <mingo@elte.hu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ac41cfd commit c33fff0

10 files changed

Lines changed: 16 additions & 55 deletions

File tree

‎kernel/configs.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ static int __init ikconfig_init(void)
7979
struct proc_dir_entry *entry;
8080

8181
/* create the current config file */
82-
entry = create_proc_entry("config.gz", S_IFREG | S_IRUGO, NULL);
82+
entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
83+
&ikconfig_file_ops);
8384
if (!entry)
8485
return -ENOMEM;
8586

86-
entry->proc_fops = &ikconfig_file_ops;
8787
entry->size = kernel_config_data_size;
8888

8989
return 0;

‎kernel/dma.c‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,7 @@ static const struct file_operations proc_dma_operations = {
149149

150150
static int __init proc_dma_init(void)
151151
{
152-
struct proc_dir_entry *e;
153-
154-
e = create_proc_entry("dma", 0, NULL);
155-
if (e)
156-
e->proc_fops = &proc_dma_operations;
157-
152+
proc_create("dma", 0, NULL, &proc_dma_operations);
158153
return 0;
159154
}
160155

‎kernel/kallsyms.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,7 @@ static const struct file_operations kallsyms_operations = {
472472

473473
static int __init kallsyms_init(void)
474474
{
475-
struct proc_dir_entry *entry;
476-
477-
entry = create_proc_entry("kallsyms", 0444, NULL);
478-
if (entry)
479-
entry->proc_fops = &kallsyms_operations;
475+
proc_create("kallsyms", 0444, NULL, &kallsyms_operations);
480476
return 0;
481477
}
482478
__initcall(kallsyms_init);

‎kernel/latencytop.c‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,7 @@ static struct file_operations lstats_fops = {
233233

234234
static int __init init_lstats_procfs(void)
235235
{
236-
struct proc_dir_entry *pe;
237-
238-
pe = create_proc_entry("latency_stats", 0644, NULL);
239-
if (!pe)
240-
return -ENOMEM;
241-
242-
pe->proc_fops = &lstats_fops;
243-
236+
proc_create("latency_stats", 0644, NULL, &lstats_fops);
244237
return 0;
245238
}
246239
__initcall(init_lstats_procfs);

‎kernel/lockdep_proc.c‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -660,20 +660,12 @@ static const struct file_operations proc_lock_stat_operations = {
660660

661661
static int __init lockdep_proc_init(void)
662662
{
663-
struct proc_dir_entry *entry;
664-
665-
entry = create_proc_entry("lockdep", S_IRUSR, NULL);
666-
if (entry)
667-
entry->proc_fops = &proc_lockdep_operations;
668-
669-
entry = create_proc_entry("lockdep_stats", S_IRUSR, NULL);
670-
if (entry)
671-
entry->proc_fops = &proc_lockdep_stats_operations;
663+
proc_create("lockdep", S_IRUSR, NULL, &proc_lockdep_operations);
664+
proc_create("lockdep_stats", S_IRUSR, NULL,
665+
&proc_lockdep_stats_operations);
672666

673667
#ifdef CONFIG_LOCK_STAT
674-
entry = create_proc_entry("lock_stat", S_IRUSR, NULL);
675-
if (entry)
676-
entry->proc_fops = &proc_lock_stat_operations;
668+
proc_create("lock_stat", S_IRUSR, NULL, &proc_lock_stat_operations);
677669
#endif
678670

679671
return 0;

‎kernel/profile.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,10 +587,10 @@ static int __init create_proc_profile(void)
587587
return 0;
588588
if (create_hash_tables())
589589
return -1;
590-
entry = create_proc_entry("profile", S_IWUSR | S_IRUGO, NULL);
590+
entry = proc_create("profile", S_IWUSR | S_IRUGO,
591+
NULL, &proc_profile_operations);
591592
if (!entry)
592593
return 0;
593-
entry->proc_fops = &proc_profile_operations;
594594
entry->size = (1+prof_len) * sizeof(atomic_t);
595595
hotcpu_notifier(profile_cpu_callback, 0);
596596
return 0;

‎kernel/resource.c‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,8 @@ static const struct file_operations proc_iomem_operations = {
131131

132132
static int __init ioresources_init(void)
133133
{
134-
struct proc_dir_entry *entry;
135-
136-
entry = create_proc_entry("ioports", 0, NULL);
137-
if (entry)
138-
entry->proc_fops = &proc_ioports_operations;
139-
entry = create_proc_entry("iomem", 0, NULL);
140-
if (entry)
141-
entry->proc_fops = &proc_iomem_operations;
134+
proc_create("ioports", 0, NULL, &proc_ioports_operations);
135+
proc_create("iomem", 0, NULL, &proc_iomem_operations);
142136
return 0;
143137
}
144138
__initcall(ioresources_init);

‎kernel/sched_debug.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,9 @@ static int __init init_sched_debug_procfs(void)
277277
{
278278
struct proc_dir_entry *pe;
279279

280-
pe = create_proc_entry("sched_debug", 0644, NULL);
280+
pe = proc_create("sched_debug", 0644, NULL, &sched_debug_fops);
281281
if (!pe)
282282
return -ENOMEM;
283-
284-
pe->proc_fops = &sched_debug_fops;
285-
286283
return 0;
287284
}
288285

‎kernel/time/timer_list.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,9 @@ static int __init init_timer_list_procfs(void)
278278
{
279279
struct proc_dir_entry *pe;
280280

281-
pe = create_proc_entry("timer_list", 0644, NULL);
281+
pe = proc_create("timer_list", 0644, NULL, &timer_list_fops);
282282
if (!pe)
283283
return -ENOMEM;
284-
285-
pe->proc_fops = &timer_list_fops;
286-
287284
return 0;
288285
}
289286
__initcall(init_timer_list_procfs);

‎kernel/time/timer_stats.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,9 @@ static int __init init_tstats_procfs(void)
415415
{
416416
struct proc_dir_entry *pe;
417417

418-
pe = create_proc_entry("timer_stats", 0644, NULL);
418+
pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
419419
if (!pe)
420420
return -ENOMEM;
421-
422-
pe->proc_fops = &tstats_fops;
423-
424421
return 0;
425422
}
426423
__initcall(init_tstats_procfs);

0 commit comments

Comments
 (0)