diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2022-10-06 17:13:18 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2022-10-06 17:13:18 -0700 |
commit | 7a3353c5c441175582cf0d17f855b2ffd83fb9db (patch) | |
tree | e19ee5ba7a4062636ac765c97dbe7ba15daf1ca9 /fs/open.c | |
parent | 70df64d6c6c2f76be47311fa6630d6edbefa711e (diff) | |
parent | 47091e4ed9af648d6cfa3a5f0809ece371294ecb (diff) |
Merge tag 'pull-file' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull vfs file updates from Al Viro:
"struct file-related stuff"
* tag 'pull-file' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
dma_buf_getfile(): don't bother with ->f_flags reassignments
Change calling conventions for filldir_t
locks: fix TOCTOU race when granting write lease
Diffstat (limited to 'fs/open.c')
-rw-r--r-- | fs/open.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/fs/open.c b/fs/open.c index cf7e5c350a54..a81319b6177f 100644 --- a/fs/open.c +++ b/fs/open.c @@ -842,7 +842,9 @@ static int do_dentry_open(struct file *f, return 0; } - if (f->f_mode & FMODE_WRITE && !special_file(inode->i_mode)) { + if ((f->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) { + i_readcount_inc(inode); + } else if (f->f_mode & FMODE_WRITE && !special_file(inode->i_mode)) { error = get_write_access(inode); if (unlikely(error)) goto cleanup_file; @@ -882,8 +884,6 @@ static int do_dentry_open(struct file *f, goto cleanup_all; } f->f_mode |= FMODE_OPENED; - if ((f->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) - i_readcount_inc(inode); if ((f->f_mode & FMODE_READ) && likely(f->f_op->read || f->f_op->read_iter)) f->f_mode |= FMODE_CAN_READ; @@ -937,10 +937,7 @@ cleanup_all: if (WARN_ON_ONCE(error > 0)) error = -EINVAL; fops_put(f->f_op); - if (f->f_mode & FMODE_WRITER) { - put_write_access(inode); - __mnt_drop_write(f->f_path.mnt); - } + put_file_access(f); cleanup_file: path_put(&f->f_path); f->f_path.mnt = NULL; |