Commit 5300990c0370e804e49d9a59d928c5d53fb73487

Authored by Al Viro
1 parent 482928d59d

Sanitize f_flags helpers

* pull ACC_MODE to fs.h; we have several copies all over the place
* nightmarish expression calculating f_mode by f_flags deserves a helper
too (OPEN_FMODE(flags))

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Showing 6 changed files with 5 additions and 14 deletions Side-by-side Diff

... ... @@ -89,19 +89,11 @@
89 89 struct qstr this;
90 90 struct path path;
91 91 struct file *file;
92   - fmode_t mode;
93 92 int error;
94 93  
95 94 if (IS_ERR(anon_inode_inode))
96 95 return ERR_PTR(-ENODEV);
97 96  
98   - switch (flags & O_ACCMODE) {
99   - case O_RDONLY: mode = FMODE_READ; break;
100   - case O_WRONLY: mode = FMODE_WRITE; break;
101   - case O_RDWR: mode = FMODE_READ | FMODE_WRITE; break;
102   - default: return ERR_PTR(-EINVAL);
103   - }
104   -
105 97 if (fops->owner && !try_module_get(fops->owner))
106 98 return ERR_PTR(-ENOENT);
107 99  
... ... @@ -129,7 +121,7 @@
129 121 d_instantiate(path.dentry, anon_inode_inode);
130 122  
131 123 error = -ENFILE;
132   - file = alloc_file(&path, mode, fops);
  124 + file = alloc_file(&path, OPEN_FMODE(flags), fops);
133 125 if (!file)
134 126 goto err_dput;
135 127 file->f_mapping = anon_inode_inode->i_mapping;
... ... @@ -37,8 +37,6 @@
37 37  
38 38 #include "internal.h"
39 39  
40   -#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
41   -
42 40 /* [Feb-1997 T. Schoebel-Theuer]
43 41 * Fundamental changes in the pathname lookup mechanisms (namei)
44 42 * were necessary because of omirr. The reason is that omirr needs
... ... @@ -828,7 +828,7 @@
828 828 struct inode *inode;
829 829 int error;
830 830  
831   - f->f_mode = (__force fmode_t)((f->f_flags+1) & O_ACCMODE) | FMODE_LSEEK |
  831 + f->f_mode = OPEN_FMODE(f->f_flags) | FMODE_LSEEK |
832 832 FMODE_PREAD | FMODE_PWRITE;
833 833 inode = dentry->d_inode;
834 834 if (f->f_mode & FMODE_WRITE) {
... ... @@ -2464,6 +2464,9 @@
2464 2464  
2465 2465 int __init get_filesystem_list(char *buf);
2466 2466  
  2467 +#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
  2468 +#define OPEN_FMODE(flag) ((__force fmode_t)((flag + 1) & O_ACCMODE))
  2469 +
2467 2470 #endif /* __KERNEL__ */
2468 2471 #endif /* _LINUX_FS_H */
... ... @@ -250,7 +250,6 @@
250 250 #endif
251 251 };
252 252  
253   -#define ACC_MODE(x) ("\004\002\006\006"[(x)&O_ACCMODE])
254 253 static inline int open_arg(int flags, int mask)
255 254 {
256 255 int n = ACC_MODE(flags);
security/tomoyo/file.c
... ... @@ -12,7 +12,6 @@
12 12 #include "common.h"
13 13 #include "tomoyo.h"
14 14 #include "realpath.h"
15   -#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
16 15  
17 16 /*
18 17 * tomoyo_globally_readable_file_entry is a structure which is used for holding