forked from luck/tmp_suning_uos_patched
do_last(): simplify the liveness analysis past finish_open_created
Don't mess with got_write there - it is guaranteed to be false on entry and it will be set true if and only if we decide to go for truncation and manage to get write access for that. Don't carry acc_mode through the entire thing - it's only used in that part. And don't bother with gotos in there - compiler is quite capable of optimizing that. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
5a2d3edd8d
commit
8795e7d482
28
fs/namei.c
28
fs/namei.c
|
@ -3122,9 +3122,9 @@ static const char *do_last(struct nameidata *nd,
|
||||||
kuid_t dir_uid = nd->inode->i_uid;
|
kuid_t dir_uid = nd->inode->i_uid;
|
||||||
umode_t dir_mode = nd->inode->i_mode;
|
umode_t dir_mode = nd->inode->i_mode;
|
||||||
int open_flag = op->open_flag;
|
int open_flag = op->open_flag;
|
||||||
bool will_truncate = (open_flag & O_TRUNC) != 0;
|
bool do_truncate;
|
||||||
bool got_write = false;
|
bool got_write = false;
|
||||||
int acc_mode = op->acc_mode;
|
int acc_mode;
|
||||||
unsigned seq;
|
unsigned seq;
|
||||||
struct inode *inode;
|
struct inode *inode;
|
||||||
struct dentry *dentry;
|
struct dentry *dentry;
|
||||||
|
@ -3243,36 +3243,30 @@ static const char *do_last(struct nameidata *nd,
|
||||||
return ERR_PTR(-ENOTDIR);
|
return ERR_PTR(-ENOTDIR);
|
||||||
|
|
||||||
finish_open_created:
|
finish_open_created:
|
||||||
|
do_truncate = false;
|
||||||
|
acc_mode = op->acc_mode;
|
||||||
if (file->f_mode & FMODE_CREATED) {
|
if (file->f_mode & FMODE_CREATED) {
|
||||||
/* Don't check for write permission, don't truncate */
|
/* Don't check for write permission, don't truncate */
|
||||||
open_flag &= ~O_TRUNC;
|
open_flag &= ~O_TRUNC;
|
||||||
will_truncate = false;
|
|
||||||
acc_mode = 0;
|
acc_mode = 0;
|
||||||
} else if (!d_is_reg(nd->path.dentry)) {
|
} else if (d_is_reg(nd->path.dentry) && open_flag & O_TRUNC) {
|
||||||
will_truncate = false;
|
|
||||||
}
|
|
||||||
if (will_truncate) {
|
|
||||||
error = mnt_want_write(nd->path.mnt);
|
error = mnt_want_write(nd->path.mnt);
|
||||||
if (error)
|
if (error)
|
||||||
return ERR_PTR(error);
|
return ERR_PTR(error);
|
||||||
got_write = true;
|
do_truncate = true;
|
||||||
}
|
}
|
||||||
error = may_open(&nd->path, acc_mode, open_flag);
|
error = may_open(&nd->path, acc_mode, open_flag);
|
||||||
if (error)
|
if (!error && !(file->f_mode & FMODE_OPENED))
|
||||||
goto out;
|
|
||||||
if (!(file->f_mode & FMODE_OPENED))
|
|
||||||
error = vfs_open(&nd->path, file);
|
error = vfs_open(&nd->path, file);
|
||||||
if (error)
|
if (!error)
|
||||||
goto out;
|
error = ima_file_check(file, op->acc_mode);
|
||||||
error = ima_file_check(file, op->acc_mode);
|
if (!error && do_truncate)
|
||||||
if (!error && will_truncate)
|
|
||||||
error = handle_truncate(file);
|
error = handle_truncate(file);
|
||||||
out:
|
|
||||||
if (unlikely(error > 0)) {
|
if (unlikely(error > 0)) {
|
||||||
WARN_ON(1);
|
WARN_ON(1);
|
||||||
error = -EINVAL;
|
error = -EINVAL;
|
||||||
}
|
}
|
||||||
if (got_write)
|
if (do_truncate)
|
||||||
mnt_drop_write(nd->path.mnt);
|
mnt_drop_write(nd->path.mnt);
|
||||||
return ERR_PTR(error);
|
return ERR_PTR(error);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user