drivers: 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>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Acked-by: Dmitry Torokhov <dtor@mail.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Denis V. Lunev 2008-04-29 01:02:34 -07:00 committed by Linus Torvalds
parent 0fd6894682
commit 1b50221738
5 changed files with 23 additions and 28 deletions

View File

@ -82,6 +82,7 @@ static int i8k_ioctl(struct inode *, struct file *, unsigned int,
unsigned long); unsigned long);
static const struct file_operations i8k_fops = { static const struct file_operations i8k_fops = {
.owner = THIS_MODULE,
.open = i8k_open_fs, .open = i8k_open_fs,
.read = seq_read, .read = seq_read,
.llseek = seq_lseek, .llseek = seq_lseek,
@ -554,13 +555,10 @@ static int __init i8k_init(void)
return -ENODEV; return -ENODEV;
/* Register the proc entry */ /* Register the proc entry */
proc_i8k = create_proc_entry("i8k", 0, NULL); proc_i8k = proc_create("i8k", 0, NULL, &i8k_fops);
if (!proc_i8k) if (!proc_i8k)
return -ENOENT; return -ENOENT;
proc_i8k->proc_fops = &i8k_fops;
proc_i8k->owner = THIS_MODULE;
printk(KERN_INFO printk(KERN_INFO
"Dell laptop SMM driver v%s Massimo Dal Zotto (dz@debian.org)\n", "Dell laptop SMM driver v%s Massimo Dal Zotto (dz@debian.org)\n",
I8K_VERSION); I8K_VERSION);

View File

@ -263,23 +263,26 @@ EXPORT_SYMBOL(misc_deregister);
static int __init misc_init(void) static int __init misc_init(void)
{ {
#ifdef CONFIG_PROC_FS int err;
struct proc_dir_entry *ent;
ent = create_proc_entry("misc", 0, NULL); #ifdef CONFIG_PROC_FS
if (ent) proc_create("misc", 0, NULL, &misc_proc_fops);
ent->proc_fops = &misc_proc_fops;
#endif #endif
misc_class = class_create(THIS_MODULE, "misc"); misc_class = class_create(THIS_MODULE, "misc");
err = PTR_ERR(misc_class);
if (IS_ERR(misc_class)) if (IS_ERR(misc_class))
return PTR_ERR(misc_class); goto fail_remove;
if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) { err = -EIO;
printk("unable to get major %d for misc devices\n", if (register_chrdev(MISC_MAJOR,"misc",&misc_fops))
MISC_MAJOR); goto fail_printk;
class_destroy(misc_class);
return -EIO;
}
return 0; return 0;
fail_printk:
printk("unable to get major %d for misc devices\n", MISC_MAJOR);
class_destroy(misc_class);
fail_remove:
remove_proc_entry("misc", NULL);
return err;
} }
subsys_initcall(misc_init); subsys_initcall(misc_init);

View File

@ -1069,10 +1069,8 @@ no_irq:
} }
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
ent = create_proc_entry("driver/rtc", 0, NULL); ent = proc_create("driver/rtc", 0, NULL, &rtc_proc_fops);
if (ent) if (!ent)
ent->proc_fops = &rtc_proc_fops;
else
printk(KERN_WARNING "rtc: Failed to register with procfs.\n"); printk(KERN_WARNING "rtc: Failed to register with procfs.\n");
#endif #endif

View File

@ -520,12 +520,11 @@ static int __init toshiba_init(void)
{ {
struct proc_dir_entry *pde; struct proc_dir_entry *pde;
pde = create_proc_entry("toshiba", 0, NULL); pde = proc_create("toshiba", 0, NULL, &proc_toshiba_fops);
if (!pde) { if (!pde) {
misc_deregister(&tosh_device); misc_deregister(&tosh_device);
return -ENOMEM; return -ENOMEM;
} }
pde->proc_fops = &proc_toshiba_fops;
} }
#endif #endif

View File

@ -249,6 +249,7 @@ static int proc_viotape_open(struct inode *inode, struct file *file)
} }
static const struct file_operations proc_viotape_operations = { static const struct file_operations proc_viotape_operations = {
.owner = THIS_MODULE,
.open = proc_viotape_open, .open = proc_viotape_open,
.read = seq_read, .read = seq_read,
.llseek = seq_lseek, .llseek = seq_lseek,
@ -915,7 +916,6 @@ static struct vio_driver viotape_driver = {
int __init viotap_init(void) int __init viotap_init(void)
{ {
int ret; int ret;
struct proc_dir_entry *e;
if (!firmware_has_feature(FW_FEATURE_ISERIES)) if (!firmware_has_feature(FW_FEATURE_ISERIES))
return -ENODEV; return -ENODEV;
@ -968,11 +968,8 @@ int __init viotap_init(void)
if (ret) if (ret)
goto unreg_class; goto unreg_class;
e = create_proc_entry("iSeries/viotape", S_IFREG|S_IRUGO, NULL); proc_create("iSeries/viotape", S_IFREG|S_IRUGO, NULL,
if (e) { &proc_viotape_operations);
e->owner = THIS_MODULE;
e->proc_fops = &proc_viotape_operations;
}
return 0; return 0;