From nobody Fri Dec 19 14:25:58 2025 Received: from forward103a.mail.yandex.net (forward103a.mail.yandex.net [178.154.239.86]) (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 23A164AECA; Sat, 27 Apr 2024 11:25:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.86 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714217106; cv=none; b=ht6wSNmlFCeNnqSO3eju99ULcdTyEGUtTcMf9lDnIeaRGAUER9z2UePAugL305HniigkoX6oE8SsUWS0iMQ25QqmdGp6ncKqkmBHlIjmeN7rdCrPxykeRjGl9qqQ6dRdjT8uMk51r0D6cbvPwxYF+dvltOcrs4l8RjRxoMMo1dU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714217106; c=relaxed/simple; bh=eW+R7T+4wDE0CCmXnPO5w8nUsJ7ogtYZtHHlx4MY378=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lPNcCG/PIjRnSFJ4GwUb4EblSfr1lAx1y2ZrYZCjdWg8dSOzC490BxcqCQX3HQEelKNbGFfFitOJKUYKbXhKrQjhwwJHcq3mH8mMm7rD688tZDrZjTowE5nBU9EfnUJtRgKvSAO/GiMoAQ4kj9BWHwSpwv4roYTJic38kziyizI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=qzFP3BHf; arc=none smtp.client-ip=178.154.239.86 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="qzFP3BHf" Received: from mail-nwsmtp-smtp-production-main-51.vla.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-51.vla.yp-c.yandex.net [IPv6:2a02:6b8:c0d:2a02:0:640:77d9:0]) by forward103a.mail.yandex.net (Yandex) with ESMTPS id C6FAE60030; Sat, 27 Apr 2024 14:24:59 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-51.vla.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id uOMFvPQXlqM0-vUxBD1Hs; Sat, 27 Apr 2024 14:24:58 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1714217098; bh=N6Wa5ZdYH+jnqmFV3t56OpNcrMxvOQwAgYBdbDZuPl8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=qzFP3BHfeY7rNGhZqBxXwE4wxJOr2GnR07ho6nERxZiLgP3hs34KsBaZUdFQUWueA ybOo2p7OvRCqzugDoddGG6scVZTISVNsvZRwRuPHoKZDu9BsTWeK75cjmp3Ngl2Nj0 Z1DNCq4MaKmj2OiVF3aYmInGHMWD8uK+kuKN9Lus= Authentication-Results: mail-nwsmtp-smtp-production-main-51.vla.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Stas Sergeev To: linux-kernel@vger.kernel.org Cc: Stas Sergeev , Stefan Metzmacher , Eric Biederman , Alexander Viro , Andy Lutomirski , Christian Brauner , Jan Kara , Jeff Layton , Chuck Lever , Alexander Aring , David Laight , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, Paolo Bonzini , =?UTF-8?q?Christian=20G=C3=B6ttsche?= Subject: [PATCH v6 1/3] fs: reorganize path_openat() Date: Sat, 27 Apr 2024 14:24:49 +0300 Message-ID: <20240427112451.1609471-2-stsp2@yandex.ru> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240427112451.1609471-1-stsp2@yandex.ru> References: <20240427112451.1609471-1-stsp2@yandex.ru> 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" This patch moves the call to alloc_empty_file() down the if branches. That changes is needed for the next patch, which adds a cred override for alloc_empty_file(). The cred override is only needed in one branch, i.e. it is not needed for O_PATH and O_TMPFILE.. No functional changes are intended by that patch. Signed-off-by: Stas Sergeev CC: Eric Biederman CC: Alexander Viro CC: Christian Brauner CC: Jan Kara CC: Andy Lutomirski CC: David Laight CC: linux-fsdevel@vger.kernel.org CC: linux-kernel@vger.kernel.org --- fs/namei.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index c5b2a25be7d0..dd50345f7260 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3781,17 +3781,24 @@ static struct file *path_openat(struct nameidata *n= d, { struct file *file; int error; + int open_flags =3D op->open_flag; =20 - file =3D alloc_empty_file(op->open_flag, current_cred()); - if (IS_ERR(file)) - return file; - - if (unlikely(file->f_flags & __O_TMPFILE)) { - error =3D do_tmpfile(nd, flags, op, file); - } else if (unlikely(file->f_flags & O_PATH)) { - error =3D do_o_path(nd, flags, file); + if (unlikely(open_flags & (__O_TMPFILE | O_PATH))) { + file =3D alloc_empty_file(open_flags, current_cred()); + if (IS_ERR(file)) + return file; + if (open_flags & __O_TMPFILE) + error =3D do_tmpfile(nd, flags, op, file); + else + error =3D do_o_path(nd, flags, file); } else { - const char *s =3D path_init(nd, flags); + const char *s; + + file =3D alloc_empty_file(open_flags, current_cred()); + if (IS_ERR(file)) + return file; + + s =3D path_init(nd, flags); while (!(error =3D link_path_walk(s, nd)) && (s =3D open_last_lookups(nd, file, op)) !=3D NULL) ; --=20 2.44.0