From nobody Fri Dec 19 16:08:04 2025 Received: from flow-b4-smtp.messagingengine.com (flow-b4-smtp.messagingengine.com [202.12.124.139]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52F5F1DBB3A; Thu, 6 Nov 2025 00:54:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.139 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762390479; cv=none; b=eOzbJJn4OLM6+m/8o+hyI52VLN50cSD4nA5pPB6aNB64yZkSX1mHIarQyDPBUesrTBE2f5REteQXR6Tem0i2G2IlUq2yXVuZX2kuCuW5KZak7yw2vjn3pA6CQMW1xT8Y6rrrGWs9Zw41YsSFOLy+TkpirmLGiXCmh2qzT/QTUSo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762390479; c=relaxed/simple; bh=pwwf2eZdH4paX+NVy07huwl2ixfz7Y09Pw2z2VdPEEo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MMNnZ7EGktcVwJ169zCEJMT2rB/TnC9qo22VV0xoUGErvmtAutZZpSDAl9ff2EazDZrgpWaCWISdLFnLU18Y2HfiFhX//7yf9x5jv6/PGfvn75KgBlodmDBNZmECi1rGtdF9TBi3uy5gQ5eR49q2Y74g1ZDcXdJG1kxiBxtJC5o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ownmail.net; spf=pass smtp.mailfrom=ownmail.net; dkim=pass (2048-bit key) header.d=ownmail.net header.i=@ownmail.net header.b=ayE02s+m; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=OydEuUfA; arc=none smtp.client-ip=202.12.124.139 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ownmail.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ownmail.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ownmail.net header.i=@ownmail.net header.b="ayE02s+m"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="OydEuUfA" Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailflow.stl.internal (Postfix) with ESMTP id 8D33C13005D8; Wed, 5 Nov 2025 19:54:36 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Wed, 05 Nov 2025 19:54:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ownmail.net; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:reply-to:subject:subject:to:to; s=fm3; t=1762390476; x=1762397676; bh=eEhtPf3j1g85S+RHaSaC+a31yH7FYFSWk8gUwaN1ev4=; b= ayE02s+msFGbE6i4ybqvPgcbvFKuP5wIxzua7i3y2LKfRqSjHKCjwh+ZH9h21ek8 TGG16dsuQZaKa7bhJK09AR8/VnbQqcfPomyf1OaP1jo/CjHCexaNq1StmTk9FtIg FNJ5tTIB3d2SD4hzuS3lH4d/4KwU6xq1tLmNyx/iwW4+KL18yIru46G/lp6oTW2X gbmXw6bcjUApTnOu/KxYm7o0LnSAM50nD+a63N5koC7GeqcUDgpCD503WXbDXVSO 00qL+jEaTdlcT0cLoMv3iEOKWhO/KkRddlEUnCZqiSTr8P9ulYFzpGfcdlxrF4l/ 8BcMuIwJ1WeffIRRSwnr2Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1762390476; x=1762397676; bh=e EhtPf3j1g85S+RHaSaC+a31yH7FYFSWk8gUwaN1ev4=; b=OydEuUfA7IoXargGe Um4XRwzaRw/sm0PhnazdaXDhIKIL8ZtljGOX71d6cIR26jrOnvdn93Hq2DTBFXjt pSkRwCvV268HapLonlV6QdKEjvkAaj9/twWjiPZWBNivbGvVHkuPVnwI4ldbLjvb oUj1cMKNvG7Xeji8+kYto66WSPrr97l9JVdksdSOu6Mc6bCZvMJANO3k/qPUTsyo 8Jx+6gp9Ax60iLcM2FHtKYowSteaHjHfaSu1xfCMbGINd9LORV8+MBwMwOHd+wZk mIx7KEwS4QOd/AYji8oLPGd+eBAsu3tEm1nmD4EkD99Jh7nckam5geJjxJnTLg+V fSkTg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddukeehfeelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhephffvvefufffkofgjfhhrggfgsedtkeertdertddtnecuhfhrohhmpefpvghilheu rhhofihnuceonhgvihhlsgesohifnhhmrghilhdrnhgvtheqnecuggftrfgrthhtvghrnh epveevkeffudeuvefhieeghffgudektdelkeejiedtjedugfeukedvkeffvdefvddunecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepnhgvihhlsg esohifnhhmrghilhdrnhgvthdpnhgspghrtghpthhtohepgedtpdhmohguvgepshhmthhp ohhuthdprhgtphhtthhopehvihhrohesiigvnhhivhdrlhhinhhugidrohhrghdruhhkpd hrtghpthhtohepshgvlhhinhhugiesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphht thhopehlihhnuhigqdigfhhssehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoh eplhhinhhugidquhhnihhonhhfshesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphht thhopehlihhnuhigqdhsvggtuhhrihhthidqmhhoughulhgvsehvghgvrhdrkhgvrhhnvg hlrdhorhhgpdhrtghpthhtoheplhhinhhugidqnhhfshesvhhgvghrrdhkvghrnhgvlhdr ohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlh drohhrghdprhgtphhtthhopehlihhnuhigqdhfshguvghvvghlsehvghgvrhdrkhgvrhhn vghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqtghifhhssehvghgvrhdrkhgvrhhnvg hlrdhorhhg X-ME-Proxy: Feedback-ID: iab3e480c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 5 Nov 2025 19:54:25 -0500 (EST) From: NeilBrown To: "Alexander Viro" , "Christian Brauner" , "Amir Goldstein" Cc: "Jan Kara" , linux-fsdevel@vger.kernel.org, Jeff Layton , Chris Mason , David Sterba , David Howells , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Tyler Hicks , Miklos Szeredi , Chuck Lever , Olga Kornievskaia , Dai Ngo , Namjae Jeon , Steve French , Sergey Senozhatsky , Carlos Maiolino , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Ondrej Mosnacek , Mateusz Guzik , Lorenzo Stoakes , Stefan Berger , "Darrick J. Wong" , linux-kernel@vger.kernel.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org, linux-cifs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Subject: [PATCH v5 03/14] VFS: tidy up do_unlinkat() Date: Thu, 6 Nov 2025 11:50:47 +1100 Message-ID: <20251106005333.956321-4-neilb@ownmail.net> X-Mailer: git-send-email 2.50.0.107.gf914562f5916.dirty In-Reply-To: <20251106005333.956321-1-neilb@ownmail.net> References: <20251106005333.956321-1-neilb@ownmail.net> Reply-To: NeilBrown Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: NeilBrown The simplification of locking in the previous patch opens up some room for tidying up do_unlinkat() - change all "exit" labels to describe what will happen at the label. - always goto an exit label on an error - unwrap the "if (!IS_ERR())" branc= h. - Move the "slashes" handing inline, but mark it as unlikely() - simplify use of the "inode" variable - we no longer need to test for NULL. Reviewed-by: Amir Goldstein Signed-off-by: NeilBrown Reviewed-by: Jeff Layton --- fs/namei.c | 55 ++++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 231e1ffd4b8d..93c5fce2d814 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4755,65 +4755,62 @@ int do_unlinkat(int dfd, struct filename *name) struct path path; struct qstr last; int type; - struct inode *inode =3D NULL; + struct inode *inode; struct inode *delegated_inode =3D NULL; unsigned int lookup_flags =3D 0; retry: error =3D filename_parentat(dfd, name, lookup_flags, &path, &last, &type); if (error) - goto exit1; + goto exit_putname; =20 error =3D -EISDIR; if (type !=3D LAST_NORM) - goto exit2; + goto exit_path_put; =20 error =3D mnt_want_write(path.mnt); if (error) - goto exit2; + goto exit_path_put; retry_deleg: dentry =3D start_dirop(path.dentry, &last, lookup_flags); error =3D PTR_ERR(dentry); - if (!IS_ERR(dentry)) { + if (IS_ERR(dentry)) + goto exit_drop_write; =20 - /* Why not before? Because we want correct error value */ - if (last.name[last.len]) - goto slashes; - inode =3D dentry->d_inode; - ihold(inode); - error =3D security_path_unlink(&path, dentry); - if (error) - goto exit3; - error =3D vfs_unlink(mnt_idmap(path.mnt), path.dentry->d_inode, - dentry, &delegated_inode); -exit3: + /* Why not before? Because we want correct error value */ + if (unlikely(last.name[last.len])) { + if (d_is_dir(dentry)) + error =3D -EISDIR; + else + error =3D -ENOTDIR; end_dirop(dentry); + goto exit_drop_write; } - if (inode) - iput(inode); /* truncate the inode here */ - inode =3D NULL; + inode =3D dentry->d_inode; + ihold(inode); + error =3D security_path_unlink(&path, dentry); + if (error) + goto exit_end_dirop; + error =3D vfs_unlink(mnt_idmap(path.mnt), path.dentry->d_inode, + dentry, &delegated_inode); +exit_end_dirop: + end_dirop(dentry); + iput(inode); /* truncate the inode here */ if (delegated_inode) { error =3D break_deleg_wait(&delegated_inode); if (!error) goto retry_deleg; } +exit_drop_write: mnt_drop_write(path.mnt); -exit2: +exit_path_put: path_put(&path); if (retry_estale(error, lookup_flags)) { lookup_flags |=3D LOOKUP_REVAL; - inode =3D NULL; goto retry; } -exit1: +exit_putname: putname(name); return error; - -slashes: - if (d_is_dir(dentry)) - error =3D -EISDIR; - else - error =3D -ENOTDIR; - goto exit3; } =20 SYSCALL_DEFINE3(unlinkat, int, dfd, const char __user *, pathname, int, fl= ag) --=20 2.50.0.107.gf914562f5916.dirty