Received: from fhigh-a2-smtp.messagingengine.com (fhigh-a2-smtp.messagingengine.com [103.168.172.153]) (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 A5CD02FABF9 for ; Wed, 15 Oct 2025 01:48:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760492908; cv=none; b=BKGeoQcYa6Blmj33kyr6+2KEyXt4/MID1TMCPglj6Xq0NjT6icKoRsniTQPLitpQ+Si6JQygGtmruuFygnKA2gG0JaX9YwJZG79/WtBpDhYE7iGS5lxcl0hcjujHAkpocZMjGGVG1Ioki7wNMKyUcFb819vYL85+Ougyo0K3VOw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760492908; c=relaxed/simple; bh=tb04WQEi6I93x3at26UIVoWMtyUVrz4OhK1KhxOSJhk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BUG+aoFmy0EWK+wLp12IihjeZ9YjGlByJsk5zBF7gZB6Vmld6mEjw2l58wbnmB2hzSIrypIncprU2lb/Bh1PquTXv4QAIr8Pbhbj5cqGQO8IGZXj07rTlqHLlesm4GvQJalmG3wy+wULKev62zA9or2J7dctZMZCgFvW7M0ylU4= 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=xu5CG8GD; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=OSGPsy3D; arc=none smtp.client-ip=103.168.172.153 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="xu5CG8GD"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="OSGPsy3D" Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id BCF8E14000A2; Tue, 14 Oct 2025 21:48:25 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Tue, 14 Oct 2025 21:48:25 -0400 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=fm2; t=1760492905; x=1760579305; bh=SAsKm7IWlbtNaX8+pnOuAQHs2pi0ciU6MTi65sj4lRU=; b= xu5CG8GDB10/7jP9HfMj4tdoKTGP7Mv4C4oM0trvRYolYpOhUubqCkmWqscBU1Hk bVZ3T9oYEAjAbddCoHHFb4q4LzbY14HuAcQMOx0frLGXLnm+/1e5q+JBiGV+O78O i3JqftTpnO8xLTVyp3bWuDwTrNjmT3hKJuUN1BghmVw6dbvHWTjH+AQja5RV8jsT lyYVlY2qOjLSzutiS7Ib8zZJ6PIs9slue3TrBbVNeFJlc5t0M7vw5Wl7fAPXh3hl 7zXOKidpCB2APoNgvpnFqrlJ322Uv5u2Ha7/SeA6J6fa9smep2XwpPD8AebcgCHS cdssNuMStb8LHvbcq78QDg== 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=fm2; t=1760492905; x=1760579305; bh=S AsKm7IWlbtNaX8+pnOuAQHs2pi0ciU6MTi65sj4lRU=; b=OSGPsy3DLdh4suVtL lyxUmKNLuhxjlm8H5ORlFL3CiMVgdqiqZoDqZ+p/u0RIa6P4aGOOcNJJxD1qKE5B D11IHsZ+NMnVb+kW6oPE9Gstsru8NBO4doCt779RTJvX80g0dD2XQRIDro+aPp3e FDi2rmAs4Co9nTlonDk39BYe5jhjVrNoY4ke62gO2jKOllx3AkD8CcSbGawHqQZg 7eRY9Wf6Jpf5EupAlSjIV2DeSk0eHOTaSddhK1nYk6ezsl4yv61dTxMUMZngeTMZ SFtD90L1NOdjf0Et9QlnUl1Zg/5tRbNYLYfcad2twVjQcQRAOT+ypHrX/6OOH+Db 1zn7Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdduvddvudefucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhephffvvefufffkofgjfhhrggfgsedtkeertdertddtnecuhfhrohhmpefpvghilheu rhhofihnuceonhgvihhlsgesohifnhhmrghilhdrnhgvtheqnecuggftrfgrthhtvghrnh epveevkeffudeuvefhieeghffgudektdelkeejiedtjedugfeukedvkeffvdefvddunecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepnhgvihhlsg esohifnhhmrghilhdrnhgvthdpnhgspghrtghpthhtohepiedpmhhouggvpehsmhhtphho uhhtpdhrtghpthhtohepvhhirhhoseiivghnihhvrdhlihhnuhigrdhorhhgrdhukhdprh gtphhtthhopehlihhnuhigqdhfshguvghvvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhg pdhrtghpthhtohepjhgrtghksehsuhhsvgdrtgiipdhrtghpthhtohepjhhlrgihthhonh eskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepsghrrghunhgvrheskhgvrhhnvghlrdho rhhgpdhrtghpthhtoheprghmihhrjeefihhlsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: iab3e480c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 14 Oct 2025 21:48:23 -0400 (EDT) From: NeilBrown To: "Alexander Viro" , "Christian Brauner" , "Amir Goldstein" , Jeff Layton Cc: "Jan Kara" , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 03/14] VFS: tidy up do_unlinkat() Date: Wed, 15 Oct 2025 12:46:55 +1100 Message-ID: <20251015014756.2073439-4-neilb@ownmail.net> X-Mailer: git-send-email 2.50.0.107.gf914562f5916.dirty In-Reply-To: <20251015014756.2073439-1-neilb@ownmail.net> References: <20251015014756.2073439-1-neilb@ownmail.net> Reply-To: NeilBrown Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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())" branch. - Move the "slashes" handing inline, but mark it as unlikely() - simplify use of the "inode" variable - we no longer need to test for NULL. Signed-off-by: NeilBrown --- fs/namei.c | 55 ++++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 3618efd4bcaa..9effaad115d9 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 = NULL; + struct inode *inode; struct inode *delegated_inode = NULL; unsigned int lookup_flags = 0; retry: error = filename_parentat(dfd, name, lookup_flags, &path, &last, &type); if (error) - goto exit1; + goto exit_putname; error = -EISDIR; if (type != LAST_NORM) - goto exit2; + goto exit_path_put; error = mnt_want_write(path.mnt); if (error) - goto exit2; + goto exit_path_put; retry_deleg: dentry = start_dirop(path.dentry, &last, lookup_flags); error = PTR_ERR(dentry); - if (!IS_ERR(dentry)) { + if (IS_ERR(dentry)) + goto exit_drop_write; - /* Why not before? Because we want correct error value */ - if (last.name[last.len]) - goto slashes; - inode = dentry->d_inode; - ihold(inode); - error = security_path_unlink(&path, dentry); - if (error) - goto exit3; - error = 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 = -EISDIR; + else + error = -ENOTDIR; end_dirop(dentry); + goto exit_drop_write; } - if (inode) - iput(inode); /* truncate the inode here */ - inode = NULL; + inode = dentry->d_inode; + ihold(inode); + error = security_path_unlink(&path, dentry); + if (error) + goto exit_end_dirop; + error = 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 = 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 |= LOOKUP_REVAL; - inode = NULL; goto retry; } -exit1: +exit_putname: putname(name); return error; - -slashes: - if (d_is_dir(dentry)) - error = -EISDIR; - else - error = -ENOTDIR; - goto exit3; } SYSCALL_DEFINE3(unlinkat, int, dfd, const char __user *, pathname, int, flag) -- 2.50.0.107.gf914562f5916.dirty