Re: [PATCH 03/10] fs: use path_clone() in path_init()
From: NeilBrown
Date: Mon Sep 14 2026 - 19:54:03 EST
On Mon, 14 Sep 2026, Mateusz Guzik wrote:
> No functional changes.
>
> Signed-off-by: Mateusz Guzik <mjguzik@xxxxxxxxx>
> ---
> fs/namei.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/fs/namei.c b/fs/namei.c
> index c8754c7ba8be..11937cfa8c7f 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -2745,13 +2745,13 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
> struct inode *inode = root->d_inode;
> if (*s && unlikely(!d_can_lookup(root)))
> return ERR_PTR(-ENOTDIR);
> - nd->path = nd->root;
> nd->inode = inode;
> if (flags & LOOKUP_RCU) {
> + nd->path = nd->root;
> nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);
> nd->root_seq = nd->seq;
> } else {
> - path_get(&nd->path);
> + path_clone(&nd->root, &nd->path);
If path_clone() we inline, the compiler possibly detect that both
branches of this if had the same assignment, and could move it before
the "if", restoring code size.
But I think the code does look a bit nicer this way.
NeilBrown
> }
> return s;
> }
> @@ -2801,23 +2801,23 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
> if (*s && unlikely(!d_can_lookup(dentry)))
> return ERR_PTR(-ENOTDIR);
>
> - nd->path = fd_file(f)->f_path;
> if (flags & LOOKUP_RCU) {
> + nd->path = fd_file(f)->f_path;
> nd->inode = nd->path.dentry->d_inode;
> nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);
> } else {
> - path_get(&nd->path);
> + path_clone(&fd_file(f)->f_path, &nd->path);
> nd->inode = nd->path.dentry->d_inode;
> }
> }
>
> /* For scoped-lookups we need to set the root to the dirfd as well. */
> if (unlikely(flags & LOOKUP_IS_SCOPED)) {
> - nd->root = nd->path;
> if (flags & LOOKUP_RCU) {
> + nd->root = nd->path;
> nd->root_seq = nd->seq;
> } else {
> - path_get(&nd->root);
> + path_clone(&nd->path, &nd->root);
> nd->state |= ND_ROOT_GRABBED;
> }
> }
> --
> 2.53.0
>
>
>