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: 146233 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3480815vqu; Thu, 28 Sep 2023 10:31:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEwN75wtE0CLd7+ovdWQISBNpjMbzp60dS+oWyaa4jZ57RMWe/f6I7U22eD0Eo+k+/UDPe8 X-Received: by 2002:a05:6a21:606:b0:15d:149f:95ef with SMTP id ll6-20020a056a21060600b0015d149f95efmr1820262pzb.51.1695922276038; Thu, 28 Sep 2023 10:31:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695922276; cv=none; d=google.com; s=arc-20160816; b=c7wr9zaz9Zn9Ho+kfPKNvf10LsGCtSGuoCMdWu4WGG3tJOqhknV0VnXd82wDXcSWSr qsPSaUyds8YYFoQMLeYqRAqr2nKlzd8X4zH72qTsFDbQ3vAuVRWdokjIvclLUB5f5toz sPUvxEAIsk221KOA1KB7GXlrZX27uvUgWEAgUCzU83ataU0xosM+i1IixIuYLI8L3PTh 9bcOQTpdXJXRCP96wxysZe4hh7IPQ5I8VBI8Lv5Frlcrgzx0hd4bGGSRJbTN6h2DRWXm 8zvhf+NZlsTr0TASE8Nr7YEKAfVUs3vPc4vHOkMFpm2+gynQQG2N2IPIBUu0EjpmDM3D yhtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=TMVO4JWLEU7kHL3FVMMwI/4b1Qo5sbRkTUZ8Yb+qirM=; fh=fciSVGILx1+3W+cWTz5M4UK4jYfML/V4M7yN3A+ltE4=; b=XIqYA+SIWViwd1JvY7XH0Q5VoZ4AheRM4WTA6A72y5+0HfeSGDp8fUpAZWuumYjt4l 4nGzqOz9OOxz89jHbW89U5Zb4g3oe3dJj97hp3Zhoo3UWh92xWIFObo0Efb7/ewvyzv5 fyAlBB/sntCztwPhA6q7g/VJXuhZd5k5KrQFYoHFgDp7mXAx26U39rwHxIcV78lM1sXM bs5SYw/mLzcaj/JnttbrDxOHkFceoGgwVFep4wFz0IuqqpzYsjFrybLhEHd0CnL64LeI 1f9XYlQtSwYltLowcA7KjJIx2NroSey2FdIMPBAOgizUhTJSrCAdy/zwFFFkvksq1hmH ghSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=ySQHLJcE; dkim=neutral (no key) header.i=@suse.de header.b=L318WkBy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id i11-20020a17090332cb00b001bf1973eafcsi10924682plr.571.2023.09.28.10.31.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 10:31:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=ySQHLJcE; dkim=neutral (no key) header.i=@suse.de header.b=L318WkBy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 527DC83470ED; Thu, 28 Sep 2023 08:23:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231789AbjI1PXr (ORCPT + 21 others); 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 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 28 Sep 2023 08:23:57 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778300017936309553 X-GMAIL-MSGID: 1778303396435133281 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)