aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2007-10-08 13:24:05 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2008-10-21 07:49:06 -0400
commit572c48921574dbe6dceb958cf965aa962baefde4 (patch)
treec1d889288d567cb6b596d10041526d2a8031bae3
parente5eb8caa83a76191feb9705c1a0a689ca260b91e (diff)
[PATCH] sanitize blkdev_get() and friends
* get rid of fake struct file/struct dentry in __blkdev_get() * merge __blkdev_get() and do_open() * get rid of flags argument of blkdev_get() Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--drivers/block/pktcdvd.c4
-rw-r--r--drivers/char/raw.c2
-rw-r--r--drivers/s390/block/dasd_genhd.c2
-rw-r--r--fs/block_dev.c65
-rw-r--r--fs/ocfs2/cluster/heartbeat.c2
-rw-r--r--fs/partitions/check.c2
-rw-r--r--include/linux/fs.h2
-rw-r--r--kernel/power/swap.c2
8 files changed, 30 insertions, 51 deletions
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index ce8c71901923..f20bf359b84f 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -2332,7 +2332,7 @@ static int pkt_open_dev(struct pktcdvd_device *pd, fmode_t write)
2332 * so bdget() can't fail. 2332 * so bdget() can't fail.
2333 */ 2333 */
2334 bdget(pd->bdev->bd_dev); 2334 bdget(pd->bdev->bd_dev);
2335 if ((ret = blkdev_get(pd->bdev, FMODE_READ, O_RDONLY))) 2335 if ((ret = blkdev_get(pd->bdev, FMODE_READ)))
2336 goto out; 2336 goto out;
2337 2337
2338 if ((ret = bd_claim(pd->bdev, pd))) 2338 if ((ret = bd_claim(pd->bdev, pd)))
@@ -2765,7 +2765,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
2765 bdev = bdget(dev); 2765 bdev = bdget(dev);
2766 if (!bdev) 2766 if (!bdev)
2767 return -ENOMEM; 2767 return -ENOMEM;
2768 ret = blkdev_get(bdev, FMODE_READ, O_RDONLY | O_NONBLOCK); 2768 ret = blkdev_get(bdev, FMODE_READ | FMODE_NDELAY);
2769 if (ret) 2769 if (ret)
2770 return ret; 2770 return ret;
2771 2771
diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index bfd59e6bf54f..f3cf5eb9b7fb 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -65,7 +65,7 @@ static int raw_open(struct inode *inode, struct file *filp)
65 if (!bdev) 65 if (!bdev)
66 goto out; 66 goto out;
67 igrab(bdev->bd_inode); 67 igrab(bdev->bd_inode);
68 err = blkdev_get(bdev, filp->f_mode, 0); 68 err = blkdev_get(bdev, filp->f_mode);
69 if (err) 69 if (err)
70 goto out; 70 goto out;
71 err = bd_claim(bdev, raw_open); 71 err = bd_claim(bdev, raw_open);
diff --git a/drivers/s390/block/dasd_genhd.c b/drivers/s390/block/dasd_genhd.c
index 3c1b6915c9ad..e99d566b69cc 100644
--- a/drivers/s390/block/dasd_genhd.c
+++ b/drivers/s390/block/dasd_genhd.c
@@ -99,7 +99,7 @@ int dasd_scan_partitions(struct dasd_block *block)
99 struct block_device *bdev; 99 struct block_device *bdev;
100 100
101 bdev = bdget_disk(block->gdp, 0); 101 bdev = bdget_disk(block->gdp, 0);
102 if (!bdev || blkdev_get(bdev, FMODE_READ, 1) < 0) 102 if (!bdev || blkdev_get(bdev, FMODE_READ) < 0)
103 return -ENODEV; 103 return -ENODEV;
104 /* 104 /*
105 * See fs/partition/check.c:register_disk,rescan_partitions 105 * See fs/partition/check.c:register_disk,rescan_partitions
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 4b595904cefd..b89c956e04f6 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -844,9 +844,8 @@ struct block_device *open_by_devnum(dev_t dev, fmode_t mode)
844{ 844{
845 struct block_device *bdev = bdget(dev); 845 struct block_device *bdev = bdget(dev);
846 int err = -ENOMEM; 846 int err = -ENOMEM;
847 int flags = mode & FMODE_WRITE ? O_RDWR : O_RDONLY;
848 if (bdev) 847 if (bdev)
849 err = blkdev_get(bdev, mode, flags); 848 err = blkdev_get(bdev, mode);
850 return err ? ERR_PTR(err) : bdev; 849 return err ? ERR_PTR(err) : bdev;
851} 850}
852 851
@@ -975,8 +974,6 @@ void bd_set_size(struct block_device *bdev, loff_t size)
975} 974}
976EXPORT_SYMBOL(bd_set_size); 975EXPORT_SYMBOL(bd_set_size);
977 976
978static int __blkdev_get(struct block_device *bdev, fmode_t mode, unsigned flags,
979 int for_part);
980static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part); 977static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part);
981 978
982/* 979/*
@@ -986,7 +983,7 @@ static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part);
986 * mutex_lock_nested(whole->bd_mutex, 1) 983 * mutex_lock_nested(whole->bd_mutex, 1)
987 */ 984 */
988 985
989static int do_open(struct block_device *bdev, struct file *file, int for_part) 986static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
990{ 987{
991 struct gendisk *disk; 988 struct gendisk *disk;
992 struct hd_struct *part = NULL; 989 struct hd_struct *part = NULL;
@@ -994,9 +991,9 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
994 int partno; 991 int partno;
995 int perm = 0; 992 int perm = 0;
996 993
997 if (file->f_mode & FMODE_READ) 994 if (mode & FMODE_READ)
998 perm |= MAY_READ; 995 perm |= MAY_READ;
999 if (file->f_mode & FMODE_WRITE) 996 if (mode & FMODE_WRITE)
1000 perm |= MAY_WRITE; 997 perm |= MAY_WRITE;
1001 /* 998 /*
1002 * hooks: /n/, see "layering violations". 999 * hooks: /n/, see "layering violations".
@@ -1007,15 +1004,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
1007 return ret; 1004 return ret;
1008 } 1005 }
1009 1006
1010 if (file->f_flags & O_NDELAY)
1011 file->f_mode |= FMODE_NDELAY;
1012 if (file->f_flags & O_EXCL)
1013 file->f_mode |= FMODE_EXCL;
1014 if ((file->f_flags & O_ACCMODE) == 3)
1015 file->f_mode |= FMODE_WRITE_IOCTL;
1016
1017 ret = -ENXIO; 1007 ret = -ENXIO;
1018 file->f_mapping = bdev->bd_inode->i_mapping;
1019 1008
1020 lock_kernel(); 1009 lock_kernel();
1021 1010
@@ -1034,7 +1023,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
1034 if (!partno) { 1023 if (!partno) {
1035 struct backing_dev_info *bdi; 1024 struct backing_dev_info *bdi;
1036 if (disk->fops->open) { 1025 if (disk->fops->open) {
1037 ret = disk->fops->open(bdev, file->f_mode); 1026 ret = disk->fops->open(bdev, mode);
1038 if (ret) 1027 if (ret)
1039 goto out_clear; 1028 goto out_clear;
1040 } 1029 }
@@ -1054,7 +1043,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
1054 if (!whole) 1043 if (!whole)
1055 goto out_clear; 1044 goto out_clear;
1056 BUG_ON(for_part); 1045 BUG_ON(for_part);
1057 ret = __blkdev_get(whole, file->f_mode, file->f_flags, 1); 1046 ret = __blkdev_get(whole, mode, 1);
1058 if (ret) 1047 if (ret)
1059 goto out_clear; 1048 goto out_clear;
1060 bdev->bd_contains = whole; 1049 bdev->bd_contains = whole;
@@ -1075,7 +1064,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
1075 disk = NULL; 1064 disk = NULL;
1076 if (bdev->bd_contains == bdev) { 1065 if (bdev->bd_contains == bdev) {
1077 if (bdev->bd_disk->fops->open) { 1066 if (bdev->bd_disk->fops->open) {
1078 ret = bdev->bd_disk->fops->open(bdev, file->f_mode); 1067 ret = bdev->bd_disk->fops->open(bdev, mode);
1079 if (ret) 1068 if (ret)
1080 goto out_unlock_bdev; 1069 goto out_unlock_bdev;
1081 } 1070 }
@@ -1095,7 +1084,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
1095 bdev->bd_part = NULL; 1084 bdev->bd_part = NULL;
1096 bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info; 1085 bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info;
1097 if (bdev != bdev->bd_contains) 1086 if (bdev != bdev->bd_contains)
1098 __blkdev_put(bdev->bd_contains, file->f_mode, 1); 1087 __blkdev_put(bdev->bd_contains, mode, 1);
1099 bdev->bd_contains = NULL; 1088 bdev->bd_contains = NULL;
1100 out_unlock_bdev: 1089 out_unlock_bdev:
1101 mutex_unlock(&bdev->bd_mutex); 1090 mutex_unlock(&bdev->bd_mutex);
@@ -1111,28 +1100,9 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
1111 return ret; 1100 return ret;
1112} 1101}
1113 1102
1114static int __blkdev_get(struct block_device *bdev, fmode_t mode, unsigned flags, 1103int blkdev_get(struct block_device *bdev, fmode_t mode)
1115 int for_part)
1116{
1117 /*
1118 * This crockload is due to bad choice of ->open() type.
1119 * It will go away.
1120 * For now, block device ->open() routine must _not_
1121 * examine anything in 'inode' argument except ->i_rdev.
1122 */
1123 struct file fake_file = {};
1124 struct dentry fake_dentry = {};
1125 fake_file.f_mode = mode;
1126 fake_file.f_flags = flags;
1127 fake_file.f_path.dentry = &fake_dentry;
1128 fake_dentry.d_inode = bdev->bd_inode;
1129
1130 return do_open(bdev, &fake_file, for_part);
1131}
1132
1133int blkdev_get(struct block_device *bdev, fmode_t mode, unsigned flags)
1134{ 1104{
1135 return __blkdev_get(bdev, mode, flags, 0); 1105 return __blkdev_get(bdev, mode, 0);
1136} 1106}
1137EXPORT_SYMBOL(blkdev_get); 1107EXPORT_SYMBOL(blkdev_get);
1138 1108
@@ -1149,15 +1119,24 @@ static int blkdev_open(struct inode * inode, struct file * filp)
1149 */ 1119 */
1150 filp->f_flags |= O_LARGEFILE; 1120 filp->f_flags |= O_LARGEFILE;
1151 1121
1122 if (filp->f_flags & O_NDELAY)
1123 filp->f_mode |= FMODE_NDELAY;
1124 if (filp->f_flags & O_EXCL)
1125 filp->f_mode |= FMODE_EXCL;
1126 if ((filp->f_flags & O_ACCMODE) == 3)
1127 filp->f_mode |= FMODE_WRITE_IOCTL;
1128
1152 bdev = bd_acquire(inode); 1129 bdev = bd_acquire(inode);
1153 if (bdev == NULL) 1130 if (bdev == NULL)
1154 return -ENOMEM; 1131 return -ENOMEM;
1155 1132
1156 res = do_open(bdev, filp, 0); 1133 filp->f_mapping = bdev->bd_inode->i_mapping;
1134
1135 res = blkdev_get(bdev, filp->f_mode);
1157 if (res) 1136 if (res)
1158 return res; 1137 return res;
1159 1138
1160 if (!(filp->f_flags & O_EXCL) ) 1139 if (!(filp->f_mode & FMODE_EXCL))
1161 return 0; 1140 return 0;
1162 1141
1163 if (!(res = bd_claim(bdev, filp))) 1142 if (!(res = bd_claim(bdev, filp)))
@@ -1327,7 +1306,7 @@ struct block_device *open_bdev_exclusive(const char *path, fmode_t mode, void *h
1327 if (IS_ERR(bdev)) 1306 if (IS_ERR(bdev))
1328 return bdev; 1307 return bdev;
1329 1308
1330 error = blkdev_get(bdev, mode, 0); 1309 error = blkdev_get(bdev, mode);
1331 if (error) 1310 if (error)
1332 return ERR_PTR(error); 1311 return ERR_PTR(error);
1333 error = -EACCES; 1312 error = -EACCES;
diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index 4b6fdf591eed..6ebaa58e2c03 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -1268,7 +1268,7 @@ static ssize_t o2hb_region_dev_write(struct o2hb_region *reg,
1268 goto out; 1268 goto out;
1269 1269
1270 reg->hr_bdev = I_BDEV(filp->f_mapping->host); 1270 reg->hr_bdev = I_BDEV(filp->f_mapping->host);
1271 ret = blkdev_get(reg->hr_bdev, FMODE_WRITE | FMODE_READ, 0); 1271 ret = blkdev_get(reg->hr_bdev, FMODE_WRITE | FMODE_READ);
1272 if (ret) { 1272 if (ret) {
1273 reg->hr_bdev = NULL; 1273 reg->hr_bdev = NULL;
1274 goto out; 1274 goto out;
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 5a35ff2e1a9b..633f7a0ebb2c 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -485,7 +485,7 @@ void register_disk(struct gendisk *disk)
485 goto exit; 485 goto exit;
486 486
487 bdev->bd_invalidated = 1; 487 bdev->bd_invalidated = 1;
488 err = blkdev_get(bdev, FMODE_READ, 0); 488 err = blkdev_get(bdev, FMODE_READ);
489 if (err < 0) 489 if (err < 0)
490 goto exit; 490 goto exit;
491 blkdev_put(bdev, FMODE_READ); 491 blkdev_put(bdev, FMODE_READ);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index c6766314dc5e..cb78e389699b 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1722,7 +1722,7 @@ extern int blkdev_driver_ioctl(struct inode *inode, struct file *file,
1722 struct gendisk *disk, unsigned cmd, 1722 struct gendisk *disk, unsigned cmd,
1723 unsigned long arg); 1723 unsigned long arg);
1724extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long); 1724extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long);
1725extern int blkdev_get(struct block_device *, fmode_t, unsigned); 1725extern int blkdev_get(struct block_device *, fmode_t);
1726extern int blkdev_put(struct block_device *, fmode_t); 1726extern int blkdev_put(struct block_device *, fmode_t);
1727extern int bd_claim(struct block_device *, void *); 1727extern int bd_claim(struct block_device *, void *);
1728extern void bd_release(struct block_device *); 1728extern void bd_release(struct block_device *);
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index 178b001a4f17..b7713b53d07a 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -172,7 +172,7 @@ static int swsusp_swap_check(void) /* This is called before saving image */
172 return res; 172 return res;
173 173
174 root_swap = res; 174 root_swap = res;
175 res = blkdev_get(resume_bdev, FMODE_WRITE, O_RDWR); 175 res = blkdev_get(resume_bdev, FMODE_WRITE);
176 if (res) 176 if (res)
177 return res; 177 return res;
178 178