diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2018-06-08 12:56:55 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2018-07-12 10:04:17 -0400 |
commit | 7c1c01ec20d61ef52dba9b6f85435e53449bea71 (patch) | |
tree | dc65b64317db04a043a58af626e305a4a993a9d0 | |
parent | 4d27f3266f14e4d1d13125ce32cb49a40f3122c3 (diff) | |
download | linux-7c1c01ec20d61ef52dba9b6f85435e53449bea71.tar.bz2 |
lift fput() on late failures into path_openat()
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | fs/namei.c | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/fs/namei.c b/fs/namei.c index 503c4b968415..bb77f6cc3ea8 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3407,8 +3407,6 @@ opened: if (!error && will_truncate) error = handle_truncate(file); out: - if (unlikely(error) && (*opened & FILE_OPENED)) - fput(file); if (unlikely(error > 0)) { WARN_ON(1); error = -EINVAL; @@ -3484,8 +3482,6 @@ static int do_tmpfile(struct nameidata *nd, unsigned flags, if (error) goto out2; error = open_check_o_direct(file); - if (error) - fput(file); out2: mnt_drop_write(path.mnt); out: @@ -3545,20 +3541,20 @@ static struct file *path_openat(struct nameidata *nd, } terminate_walk(nd); out2: - if (!(opened & FILE_OPENED)) { - BUG_ON(!error); - fput(file); + if (likely(!error)) { + if (likely(opened & FILE_OPENED)) + return file; + WARN_ON(1); + error = -EINVAL; } - if (unlikely(error)) { - if (error == -EOPENSTALE) { - if (flags & LOOKUP_RCU) - error = -ECHILD; - else - error = -ESTALE; - } - file = ERR_PTR(error); + fput(file); + if (error == -EOPENSTALE) { + if (flags & LOOKUP_RCU) + error = -ECHILD; + else + error = -ESTALE; } - return file; + return ERR_PTR(error); } struct file *do_filp_open(int dfd, struct filename *pathname, |