Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1210243imm; Fri, 8 Jun 2018 11:54:30 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLyKkNrQKUgc/U2WNMl8Gb2BAIHmCDqngjqk5JSX327prwDWiTmREuO2lT2RQNAVSogmBW/ X-Received: by 2002:a62:32c6:: with SMTP id y189-v6mr7196377pfy.241.1528484070922; Fri, 08 Jun 2018 11:54:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528484070; cv=none; d=google.com; s=arc-20160816; b=QlhaPKxUFCIlY+ucFt3dlWh6o2RlcCI8t2LYoxg339BPMgwqjvbRczPUVNpE7Rpeou LxtG/kpJlclwBek9DraIqwZ6EYvhd33Fh6SYOJJex2e105b6DkyGGgvaOLEnbgkx+xy8 izW1NqPR3wWpM4oFQWG1p0nq3G4Cs1Ism2DVz4I5mUuK+kNGWmCAYEaVmlLMoFqSWR97 rrC+0iHzzmjKfi69ljSWGcekKRlqG85Fz77nH229qNSQH3f83b+VCH0iwOmdo1zjwxq8 RWSPxfRv7OZ+Uzv08YulixwZWQulalMWd9TQLKAbbg9c8eTJ1l4VsIlOV04wkhQWmybn T5tw== 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=p1vssowec8t8DKxqGNFeuIvRCSpCM5YRBp6I20uJG+E=; b=LSD0VbUY/TUMhrqK9cElhB2djoBDGCHK0uc4ta1ZAz0Ng9fli8UEb0F/Gux2wNhUz5 JGA5Lu8Uss4harxQ/1l9RnWvON99hBdeGphsB7RlsmFlljA98a1B0+btogHU+qKI8gC8 OSWqG0I+uRuobBaG9BdkovOyT1Pbq74AGbU9nInq4P3Hdr75Y4JcTr4EbK7Nwu0cc50z 2MFhdaSs/wpIPimTBMCDqPHdbBUVwR5i6Y5ktoP+tDYqZefCvlSfhCOLHGbHF0IewDa0 ChIjorajpg4kIvB095UIxK7v41Ixbi41abmWToArJlv+k5GAVaD8vK1uDZ55VaG0KiDo SxhA== 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 67-v6si30338205pge.373.2018.06.08.11.54.16; Fri, 08 Jun 2018 11:54:30 -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 S1753260AbeFHSxP (ORCPT + 99 others); Fri, 8 Jun 2018 14:53:15 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:53798 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752691AbeFHSuV (ORCPT ); Fri, 8 Jun 2018 14:50:21 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.87 #1 (Red Hat Linux)) id 1fRMSp-0006Nh-Td; Fri, 08 Jun 2018 18:50:19 +0000 From: Al Viro To: Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/13] pull fput() on late failures into path_openat() Date: Fri, 8 Jun 2018 19:50:11 +0100 Message-Id: <20180608185019.24472-5-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20180608185019.24472-1-viro@ZenIV.linux.org.uk> References: <20180608184842.GD30522@ZenIV.linux.org.uk> <20180608185019.24472-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 Signed-off-by: Al Viro --- fs/namei.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index b34ead1b8790..2abd00079b26 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3375,8 +3375,6 @@ static int do_last(struct nameidata *nd, 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; @@ -3454,8 +3452,6 @@ static int do_tmpfile(struct nameidata *nd, unsigned flags, if (file->f_mode & FMODE_OPENED) *opened |= FILE_OPENED; error = open_check_o_direct(file); - if (error) - fput(file); out2: mnt_drop_write(path.mnt); out: @@ -3517,20 +3513,23 @@ static struct file *path_openat(struct nameidata *nd, } terminate_walk(nd); out2: - if (!(opened & FILE_OPENED)) { - BUG_ON(!error); - put_filp(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); + if (opened & FILE_OPENED) + fput(file); + else + put_filp(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, -- 2.11.0