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>
This commit is contained in:
@@ -89,19 +89,11 @@ struct file *anon_inode_getfile(const char *name,
|
||||
struct qstr this;
|
||||
struct path path;
|
||||
struct file *file;
|
||||
fmode_t mode;
|
||||
int error;
|
||||
|
||||
if (IS_ERR(anon_inode_inode))
|
||||
return ERR_PTR(-ENODEV);
|
||||
|
||||
switch (flags & O_ACCMODE) {
|
||||
case O_RDONLY: mode = FMODE_READ; break;
|
||||
case O_WRONLY: mode = FMODE_WRITE; break;
|
||||
case O_RDWR: mode = FMODE_READ | FMODE_WRITE; break;
|
||||
default: return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
if (fops->owner && !try_module_get(fops->owner))
|
||||
return ERR_PTR(-ENOENT);
|
||||
|
||||
@@ -129,7 +121,7 @@ struct file *anon_inode_getfile(const char *name,
|
||||
d_instantiate(path.dentry, anon_inode_inode);
|
||||
|
||||
error = -ENFILE;
|
||||
file = alloc_file(&path, mode, fops);
|
||||
file = alloc_file(&path, OPEN_FMODE(flags), fops);
|
||||
if (!file)
|
||||
goto err_dput;
|
||||
file->f_mapping = anon_inode_inode->i_mapping;
|
||||
|
Reference in New Issue
Block a user