diff options
author | Denis V. Lunev <den@openvz.org> | 2008-04-29 04:02:17 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-29 11:06:21 -0400 |
commit | a973909fc32be90884280b7a8cd2f2e093c97890 (patch) | |
tree | 32ceca146f9a6de03bb7cf91a141d0f445da04ab /drivers | |
parent | 16e70f64a9358133a14872eb72cf39b6f38b6212 (diff) |
scsi: use non-racy method for proc entries creation
Use proc_create() to make sure that ->proc_fops be setup before gluing PDE to
main tree.
Add correct ->owner to proc_fops to fix reading/module unloading race.
Signed-off-by: Denis V. Lunev <den@openvz.org>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/scsi/scsi_proc.c | 4 | ||||
-rw-r--r-- | drivers/scsi/sg.c | 12 |
2 files changed, 6 insertions, 10 deletions
diff --git a/drivers/scsi/scsi_proc.c b/drivers/scsi/scsi_proc.c index 3a1c99d5c775..e4a0d2f9b357 100644 --- a/drivers/scsi/scsi_proc.c +++ b/drivers/scsi/scsi_proc.c | |||
@@ -413,6 +413,7 @@ static int proc_scsi_open(struct inode *inode, struct file *file) | |||
413 | } | 413 | } |
414 | 414 | ||
415 | static const struct file_operations proc_scsi_operations = { | 415 | static const struct file_operations proc_scsi_operations = { |
416 | .owner = THIS_MODULE, | ||
416 | .open = proc_scsi_open, | 417 | .open = proc_scsi_open, |
417 | .read = seq_read, | 418 | .read = seq_read, |
418 | .write = proc_scsi_write, | 419 | .write = proc_scsi_write, |
@@ -431,10 +432,9 @@ int __init scsi_init_procfs(void) | |||
431 | if (!proc_scsi) | 432 | if (!proc_scsi) |
432 | goto err1; | 433 | goto err1; |
433 | 434 | ||
434 | pde = create_proc_entry("scsi/scsi", 0, NULL); | 435 | pde = proc_create("scsi/scsi", 0, NULL, &proc_scsi_operations); |
435 | if (!pde) | 436 | if (!pde) |
436 | goto err2; | 437 | goto err2; |
437 | pde->proc_fops = &proc_scsi_operations; | ||
438 | 438 | ||
439 | return 0; | 439 | return 0; |
440 | 440 | ||
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 2029422bc04d..c9d7f721b9e2 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c | |||
@@ -2667,7 +2667,6 @@ sg_proc_init(void) | |||
2667 | { | 2667 | { |
2668 | int k, mask; | 2668 | int k, mask; |
2669 | int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr); | 2669 | int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr); |
2670 | struct proc_dir_entry *pdep; | ||
2671 | struct sg_proc_leaf * leaf; | 2670 | struct sg_proc_leaf * leaf; |
2672 | 2671 | ||
2673 | sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL); | 2672 | sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL); |
@@ -2676,13 +2675,10 @@ sg_proc_init(void) | |||
2676 | for (k = 0; k < num_leaves; ++k) { | 2675 | for (k = 0; k < num_leaves; ++k) { |
2677 | leaf = &sg_proc_leaf_arr[k]; | 2676 | leaf = &sg_proc_leaf_arr[k]; |
2678 | mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO; | 2677 | mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO; |
2679 | pdep = create_proc_entry(leaf->name, mask, sg_proc_sgp); | 2678 | leaf->fops->owner = THIS_MODULE; |
2680 | if (pdep) { | 2679 | leaf->fops->read = seq_read; |
2681 | leaf->fops->owner = THIS_MODULE, | 2680 | leaf->fops->llseek = seq_lseek; |
2682 | leaf->fops->read = seq_read, | 2681 | proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops); |
2683 | leaf->fops->llseek = seq_lseek, | ||
2684 | pdep->proc_fops = leaf->fops; | ||
2685 | } | ||
2686 | } | 2682 | } |
2687 | return 0; | 2683 | return 0; |
2688 | } | 2684 | } |