From patchwork Thu Sep 28 15:23:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luis Henriques X-Patchwork-Id: 13403265 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7225EE732E4 for ; Thu, 28 Sep 2023 15:23:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231761AbjI1PXr (ORCPT ); Thu, 28 Sep 2023 11:23:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231620AbjI1PXq (ORCPT ); Thu, 28 Sep 2023 11:23:46 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B01D5AC; Thu, 28 Sep 2023 08:23:44 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3E373218EE; Thu, 28 Sep 2023 15:23:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695914623; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TMVO4JWLEU7kHL3FVMMwI/4b1Qo5sbRkTUZ8Yb+qirM=; b=ySQHLJcEODl7uYvtim5VAX7ladjWz1XOh0RKHASv29BGkqkQ2mQgWfQXCkU5dL6+D4osZX hUqBBw+uv4odRaITlGeUW4jfKLUwHAe99FGERX+G6lTjVZweXWqiv1e9uzRkZM/axjHlto c6jXihZxTuS32dlyjvdUsjzNcNYSh4I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695914623; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TMVO4JWLEU7kHL3FVMMwI/4b1Qo5sbRkTUZ8Yb+qirM=; b=L318WkBygjvdQ5WS2NKz2hxFQwxy+SeJlP/E5DmGlJD1IFzzj+3pnr/0D11mPt6Kb2Tn8k AH/hpYPp4VB2aACQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B559C138E9; Thu, 28 Sep 2023 15:23:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id R5KaKH6aFWXoKwAAMHmgww (envelope-from ); Thu, 28 Sep 2023 15:23:42 +0000 Received: from localhost (brahms.olymp [local]) by brahms.olymp (OpenSMTPD) with ESMTPA id a6641159; Thu, 28 Sep 2023 15:23:41 +0000 (UTC) From: =?utf-8?q?Lu=C3=ADs_Henriques?= To: Alexander Viro , Christian Brauner , David Howells Cc: Mateusz Guzik , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Lu=C3=ADs_Henriques?= Subject: [PATCH v2] fs: simplify misleading code to remove ambiguity regarding ihold()/iput() Date: Thu, 28 Sep 2023 16:23:41 +0100 Message-Id: <20230928152341.303-1-lhenriques@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Because 'inode' is being initialised before checking if 'dentry' is negative it looks like an extra iput() on 'inode' may happen since the ihold() is done only if the dentry is *not* negative. In reality this doesn't happen because d_is_negative() is never true if ->d_inode is NULL. This patch only makes the code easier to understand, as I was initially mislead by it. Fixes: b18825a7c8e3 ("VFS: Put a small type field into struct dentry::d_flags") Signed-off-by: Luís Henriques --- Changes since v1: Rephrased commit message to make it clear there isn't a real bug fs/namei.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 567ee547492b..156a570d7831 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4386,11 +4386,9 @@ int do_unlinkat(int dfd, struct filename *name) if (!IS_ERR(dentry)) { /* Why not before? Because we want correct error value */ - if (last.name[last.len]) + if (last.name[last.len] || d_is_negative(dentry)) goto slashes; inode = dentry->d_inode; - if (d_is_negative(dentry)) - goto slashes; ihold(inode); error = security_path_unlink(&path, dentry); if (error)