From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw0-f196.google.com ([209.85.161.196]:42641 "EHLO mail-yw0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726199AbeGKFqF (ORCPT ); Wed, 11 Jul 2018 01:46:05 -0400 MIME-Version: 1.0 In-Reply-To: <20180711022206.12571-15-viro@ZenIV.linux.org.uk> References: <20180711021136.GN30522@ZenIV.linux.org.uk> <20180711022206.12571-1-viro@ZenIV.linux.org.uk> <20180711022206.12571-15-viro@ZenIV.linux.org.uk> From: Amir Goldstein Date: Wed, 11 Jul 2018 08:43:31 +0300 Message-ID: Subject: Re: [RFC][PATCH 15/42] lift fput() on late failures into path_openat() To: Al Viro Cc: Linus Torvalds , linux-fsdevel , linux-kernel , Miklos Szeredi Content-Type: text/plain; charset="UTF-8" Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Wed, Jul 11, 2018 at 5:21 AM, Al Viro wrote: [...] > @@ -3407,8 +3407,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); Another opportunity to squash WARN_ON(1) with condition. > 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: > @@ -3547,20 +3543,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); This style may be open for debate but: if (!WARN_ON(!(opened & FILE_OPENED))) return file; Maybe we need WARN_UNLESS() or WARN_ASSERT() Thanks, Amir.