diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2018-07-09 11:14:39 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2018-07-12 10:04:16 -0400 |
commit | 4d27f3266f14e4d1d13125ce32cb49a40f3122c3 (patch) | |
tree | f8563984e4278fc0ddd68c4bdd277f8179014ef5 /fs | |
parent | f5d11409e61dadf1f9af91b22bbedc28a60a2e2c (diff) | |
download | linux-stable-4d27f3266f14e4d1d13125ce32cb49a40f3122c3.tar.gz linux-stable-4d27f3266f14e4d1d13125ce32cb49a40f3122c3.tar.bz2 linux-stable-4d27f3266f14e4d1d13125ce32cb49a40f3122c3.zip |
fold put_filp() into fput()
Just check FMODE_OPENED in __fput() and be done with that...
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/file_table.c | 15 | ||||
-rw-r--r-- | fs/namei.c | 4 | ||||
-rw-r--r-- | fs/open.c | 11 |
3 files changed, 10 insertions, 20 deletions
diff --git a/fs/file_table.c b/fs/file_table.c index d664d10acfeb..9b70ed2bbc4e 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -192,6 +192,9 @@ static void __fput(struct file *file) struct vfsmount *mnt = file->f_path.mnt; struct inode *inode = file->f_inode; + if (unlikely(!(file->f_mode & FMODE_OPENED))) + goto out; + might_sleep(); fsnotify_close(file); @@ -221,12 +224,10 @@ static void __fput(struct file *file) put_write_access(inode); __mnt_drop_write(mnt); } - file->f_path.dentry = NULL; - file->f_path.mnt = NULL; - file->f_inode = NULL; - file_free(file); dput(dentry); mntput(mnt); +out: + file_free(file); } static LLIST_HEAD(delayed_fput_list); @@ -301,12 +302,6 @@ void __fput_sync(struct file *file) EXPORT_SYMBOL(fput); -void put_filp(struct file *file) -{ - if (atomic_long_dec_and_test(&file->f_count)) - file_free(file); -} - void __init files_init(void) { filp_cachep = kmem_cache_create("filp", sizeof(struct file), 0, diff --git a/fs/namei.c b/fs/namei.c index 3cf02804d5ff..503c4b968415 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3531,7 +3531,7 @@ static struct file *path_openat(struct nameidata *nd, s = path_init(nd, flags); if (IS_ERR(s)) { - put_filp(file); + fput(file); return ERR_CAST(s); } while (!(error = link_path_walk(s, nd)) && @@ -3547,7 +3547,7 @@ static struct file *path_openat(struct nameidata *nd, out2: if (!(opened & FILE_OPENED)) { BUG_ON(!error); - put_filp(file); + fput(file); } if (unlikely(error)) { if (error == -EOPENSTALE) { diff --git a/fs/open.c b/fs/open.c index f3c6cb6a57b9..3d09b823f12b 100644 --- a/fs/open.c +++ b/fs/open.c @@ -921,15 +921,10 @@ struct file *dentry_open(const struct path *path, int flags, f = alloc_empty_file(flags, cred); if (!IS_ERR(f)) { error = vfs_open(path, f); - if (!error) { - /* from now on we need fput() to dispose of f */ + if (!error) error = open_check_o_direct(f); - if (error) { - fput(f); - f = ERR_PTR(error); - } - } else { - put_filp(f); + if (error) { + fput(f); f = ERR_PTR(error); } } |