The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Jori Koolstra <jkoolstra@xs4all.nl>
Cc: Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
	Al Viro <viro@zeniv.linux.org.uk>, NeilBrown <neil@brown.name>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 01/12] fs/namei.c: use trailing_slashes()
Date: Mon, 15 Jun 2026 10:26:06 +0100	[thread overview]
Message-ID: <20260615102606.0d7befa2@pumpkin> (raw)
In-Reply-To: <20260614164438.2980769-2-jkoolstra@xs4all.nl>

On Sun, 14 Jun 2026 18:44:27 +0200
Jori Koolstra <jkoolstra@xs4all.nl> wrote:

> There are several places in fs/namei.c that can use the
> trailing_slashes() function to improve intent.

I'm not sure it does anything for the readability.

> 
> Signed-off-by: Jori Koolstra <jkoolstra@xs4all.nl>
> ---
>  fs/namei.c | 26 +++++++++++++-------------
>  1 file changed, 13 insertions(+), 13 deletions(-)
> 
> diff --git a/fs/namei.c b/fs/namei.c
> index 4787244ca4a7..64b91ed9efb7 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -2777,9 +2777,14 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
>  	return s;
>  }
>  
> +static inline bool trailing_slashes(const struct qstr last)

You are passing a struct by value.
If the function isn't inlined then you've blown the stack.

	David

> +{
> +	return (bool)last.name[last.len];
> +}
> +
>  static inline const char *lookup_last(struct nameidata *nd)
>  {
> -	if (nd->last_type == LAST_NORM && nd->last.name[nd->last.len])
> +	if (nd->last_type == LAST_NORM && trailing_slashes(nd->last))
>  		nd->flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
>  
>  	return walk_component(nd, WALK_TRAILING);
> @@ -4524,17 +4529,12 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,
>  	return ERR_PTR(error);
>  }
>  
> -static inline bool trailing_slashes(struct nameidata *nd)
> -{
> -	return (bool)nd->last.name[nd->last.len];
> -}
> -
>  static struct dentry *lookup_fast_for_open(struct nameidata *nd, int open_flag)
>  {
>  	struct dentry *dentry;
>  
>  	if (open_flag & O_CREAT) {
> -		if (trailing_slashes(nd))
> +		if (trailing_slashes(nd->last))
>  			return ERR_PTR(-EISDIR);
>  
>  		/* Don't bother on an O_EXCL create */
> @@ -4542,7 +4542,7 @@ static struct dentry *lookup_fast_for_open(struct nameidata *nd, int open_flag)
>  			return NULL;
>  	}
>  
> -	if (trailing_slashes(nd))
> +	if (trailing_slashes(nd->last))
>  		nd->flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
>  
>  	dentry = lookup_fast(nd);
> @@ -4945,7 +4945,7 @@ static struct dentry *filename_create(int dfd, struct filename *name,
>  	 * Do the final lookup.  Suppress 'create' if there is a trailing
>  	 * '/', and a directory wasn't requested.
>  	 */
> -	if (last.name[last.len] && !want_dir)
> +	if (trailing_slashes(last) && !want_dir)
>  		create_flags &= ~LOOKUP_CREATE;
>  	dentry = start_dirop(path->dentry, &last, reval_flag | create_flags);
>  	if (IS_ERR(dentry))
> @@ -5562,7 +5562,7 @@ int filename_unlinkat(int dfd, struct filename *name)
>  		goto exit_drop_write;
>  
>  	/* Why not before? Because we want correct error value */
> -	if (unlikely(last.name[last.len])) {
> +	if (unlikely(trailing_slashes(last))) {
>  		if (d_is_dir(dentry))
>  			error = -EISDIR;
>  		else
> @@ -6161,16 +6161,16 @@ int filename_renameat2(int olddfd, struct filename *from,
>  	if (flags & RENAME_EXCHANGE) {
>  		if (!d_is_dir(rd.new_dentry)) {
>  			error = -ENOTDIR;
> -			if (new_last.name[new_last.len])
> +			if (trailing_slashes(new_last))
>  				goto exit_unlock;
>  		}
>  	}
>  	/* unless the source is a directory trailing slashes give -ENOTDIR */
>  	if (!d_is_dir(rd.old_dentry)) {
>  		error = -ENOTDIR;
> -		if (old_last.name[old_last.len])
> +		if (trailing_slashes(old_last))
>  			goto exit_unlock;
> -		if (!(flags & RENAME_EXCHANGE) && new_last.name[new_last.len])
> +		if (!(flags & RENAME_EXCHANGE) && trailing_slashes(new_last))
>  			goto exit_unlock;
>  	}
>  


  reply	other threads:[~2026-06-15  9:26 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-14 16:44 [PATCH 00/12] vfs: add O_CREAT|O_DIRECTORY to open*(2) Jori Koolstra
2026-06-14 16:44 ` [PATCH 01/12] fs/namei.c: use trailing_slashes() Jori Koolstra
2026-06-15  9:26   ` David Laight [this message]
2026-06-14 16:44 ` [PATCH 02/12] fs/namei.c: move create error && negative dentry case in lookup_open up Jori Koolstra
2026-06-15  9:37   ` David Laight
2026-06-14 16:44 ` [PATCH 03/12] vfs: prepare vfs_creat|mkdir_no_perm for reuse in lookup_open() Jori Koolstra
2026-06-14 16:44 ` [PATCH 04/12] fs/namei.c: lookup_open(): move audit_inode_child() up Jori Koolstra
2026-06-15 21:43   ` Jori Koolstra
2026-06-14 16:44 ` [PATCH 05/12] vfs: lookup_open(): move setting FMODE_CREATED up when calling create() Jori Koolstra
2026-06-14 16:44 ` [PATCH 06/12] vfs: lookup_open(): move i_op->create check to before try_break_deleg() Jori Koolstra
2026-06-14 16:44 ` [PATCH 07/12] vfs: lookup_open(): use vfs_create_no_perm() Jori Koolstra
2026-06-14 16:44 ` [PATCH 08/12] vfs: add O_CREAT|O_DIRECTORY to open*(2) Jori Koolstra
2026-06-14 16:44 ` [PATCH 09/12] vfs: move O_IS_MKDIR check out atomic_open() to individual filesystems Jori Koolstra
2026-06-14 16:44 ` [PATCH 10/12] vfs: refuse O_CREAT for directories through a dangling symlink Jori Koolstra
2026-06-14 16:44 ` [PATCH 11/12] vfs: short-circuit MAY_WRITE access for O_DIRECTORY opens Jori Koolstra
2026-06-14 17:01   ` Jori Koolstra
2026-06-15 12:56   ` Jori Koolstra
2026-06-14 16:44 ` [PATCH 12/12] selftest: add tests for open*(O_CREAT|O_DIRECTORY) Jori Koolstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260615102606.0d7befa2@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=jkoolstra@xs4all.nl \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neil@brown.name \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox