Received: by 2002:ac0:adb4:0:0:0:0:0 with SMTP id o49-v6csp5949imb; Tue, 10 Jul 2018 19:27:31 -0700 (PDT) X-Google-Smtp-Source: AAOMgpckPxAO12RjLwcx7/SoNbBxS/M1PsI2qYGd1OTVRivbiQCzJZKOSH/bD7Akz5UPF2u1YrxE X-Received: by 2002:a17:902:bc49:: with SMTP id t9-v6mr26827065plz.116.1531276051669; Tue, 10 Jul 2018 19:27:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531276051; cv=none; d=google.com; s=arc-20160816; b=hEOlIBrWiNa6HhTRq9EmBUfyWs0OEZoGm0iRVlu2eAruRIczXmuoagqimfqEQ6+lZG OCgBIkgH9gDiUPBrYHiO7x/qdbWQ+XiNfHiwSSAnzAAgCZeC4Jtqpo2MZDpHw19hADs6 95VO+jHyD1Mcf8X5VOF4OUkbj5nhuJCx5wBU8UBXbDZnU9aXKMFINgXUEtExHrykobwP wGvhqyJj1qbpOqnn7Px1VLcXzB46sxn2YRNHMQOb8zw6jhSghi1dSiCu5226sXXaDZyA SXL1x0uAYdLJgiBdyO5gLd3mFXuk/N8O04aT7RweRPv7D2GCZPw9ZnB+oKtZjhjTY4za 1D6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=X3zV5hEl9HfHyaa+qSB0TEcaRy0dJfHCrOvKsZ7/mdc=; b=rxmhneLfVJD/eaVVYUQcljvpsod8a0n00w4WvT9CQR7K/Ym9luat3govWPvapJLk1Q Z5lq/LMS+Rzcit9qAJ/HfXxhT4zvdlGG1jNS5lp5v8VrqdQLrbrNfvJZMfFKZ7ejFzWf 8Mcq2qa8Z8nbNgYU/UdNquj1QYgr86uanpUko2j3UX0Uqqq8/s0KpTpvEDkaaYy4LHjY zBT26mGQGB4NAd0nRKwUWmu8F1vvMHZZz5gF/6EvqthtEG3DROn6eGXq/2jgZjFUShay leY2VFLKbZimV7ZmnDA3i5l32YDl4tPOSEs5hg4mM79LLKJGrGGzQWlUxysNvRGI/tjK QrNQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 200-v6si17635403pgf.378.2018.07.10.19.27.16; Tue, 10 Jul 2018 19:27:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732756AbeGKC1F (ORCPT + 99 others); Tue, 10 Jul 2018 22:27:05 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:45566 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732381AbeGKCYF (ORCPT ); Tue, 10 Jul 2018 22:24:05 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.87 #1 (Red Hat Linux)) id 1fd4lb-0003Im-Gl; Wed, 11 Jul 2018 02:22:07 +0000 From: Al Viro To: Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Miklos Szeredi Subject: [RFC][PATCH 14/42] fold put_filp() into fput() Date: Wed, 11 Jul 2018 03:21:38 +0100 Message-Id: <20180711022206.12571-14-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20180711022206.12571-1-viro@ZenIV.linux.org.uk> References: <20180711021136.GN30522@ZenIV.linux.org.uk> <20180711022206.12571-1-viro@ZenIV.linux.org.uk> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro Just check FMODE_OPENED in __fput() and be done with that... Signed-off-by: Al Viro --- fs/file_table.c | 15 +++++---------- fs/namei.c | 4 ++-- fs/open.c | 11 +++-------- include/linux/file.h | 1 - 4 files changed, 10 insertions(+), 21 deletions(-) diff --git a/fs/file_table.c b/fs/file_table.c index eaee481295de..d55dc579ae4e 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -190,6 +190,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); @@ -219,12 +222,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); @@ -299,12 +300,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 7b1fe5e30a0d..3d4e20a1c756 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3533,7 +3533,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)) && @@ -3549,7 +3549,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 ce092dda5472..affdeebe5fd5 100644 --- a/fs/open.c +++ b/fs/open.c @@ -925,15 +925,10 @@ struct file *dentry_open(const struct path *path, int flags, if (!IS_ERR(f)) { f->f_flags = flags; 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); } } diff --git a/include/linux/file.h b/include/linux/file.h index 279720db984a..d771bc05da77 100644 --- a/include/linux/file.h +++ b/include/linux/file.h @@ -78,7 +78,6 @@ extern int f_dupfd(unsigned int from, struct file *file, unsigned flags); extern int replace_fd(unsigned fd, struct file *file, unsigned flags); extern void set_close_on_exec(unsigned int fd, int flag); extern bool get_close_on_exec(unsigned int fd); -extern void put_filp(struct file *); extern int get_unused_fd_flags(unsigned flags); extern void put_unused_fd(unsigned int fd); -- 2.11.0