Linux-CIFS Archive mirror
 help / color / mirror / Atom feed
From: NeilBrown <neilb@ownmail.net>
To: "Markus Elfring" <Markus.Elfring@web.de>
Cc: linux-cifs@vger.kernel.org, "Namjae Jeon" <linkinjeon@kernel.org>,
	"Sergey Senozhatsky" <senozhatsky@chromium.org>,
	"Steve French" <smfrench@gmail.com>,
	"Tom Talpey" <tom@talpey.com>,
	"LKML" <linux-kernel@vger.kernel.org>,
	kernel-janitors@vger.kernel.org,
	"Stefan Metzmacher" <metze@samba.org>
Subject: Re: [PATCH] ksmbd: Use common error handling code in ksmbd_vfs_path_lookup()
Date: Sat, 04 Oct 2025 08:30:46 +1000	[thread overview]
Message-ID: <175953064635.1793333.2429881029964457140@noble.neil.brown.name> (raw)
In-Reply-To: <6d759211-79e7-4d86-b22e-2ae46d209622@web.de>

On Sat, 04 Oct 2025, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 3 Oct 2025 20:26:56 +0200
> 
> Add a jump target so that a bit of exception handling can be better reused
> at the end of this function implementation.

I think this is a good cleanup - thanks.  But I think it could be even
better.

- rename the "path" parameter to "return_path" or similar.
- declare  struct path path __free(path_-put) = {};
- change all "path->" instances to "path."
- remove all those path_put() calls, but leave the "return xxx"
- at the point of successful return, use

   return_path->dentry = no_free_ptr(path.dentry);
   return_path->mnt = no_free_ptr(path.mnt);
   return 0;

This is based on the pattern in kern_path_parent() and
__start_removing_path().

Thanks,
NeilBrown


> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  fs/smb/server/vfs.c | 32 ++++++++++++++------------------
>  1 file changed, 14 insertions(+), 18 deletions(-)
> 
> diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c
> index 891ed2dc2b73..3535655b4d86 100644
> --- a/fs/smb/server/vfs.c
> +++ b/fs/smb/server/vfs.c
> @@ -94,17 +94,13 @@ static int ksmbd_vfs_path_lookup(struct ksmbd_share_config *share_conf,
>  	if (err)
>  		return err;
>  
> -	if (unlikely(type != LAST_NORM)) {
> -		path_put(path);
> -		return -ENOENT;
> -	}
> +	if (unlikely(type != LAST_NORM))
> +		goto put_path;
>  
>  	if (do_lock) {
>  		err = mnt_want_write(path->mnt);
> -		if (err) {
> -			path_put(path);
> -			return -ENOENT;
> -		}
> +		if (err)
> +			goto put_path;
>  
>  		inode_lock_nested(path->dentry->d_inode, I_MUTEX_PARENT);
>  		d = lookup_one_qstr_excl(&last, path->dentry, 0);
> @@ -116,8 +112,7 @@ static int ksmbd_vfs_path_lookup(struct ksmbd_share_config *share_conf,
>  		}
>  		inode_unlock(path->dentry->d_inode);
>  		mnt_drop_write(path->mnt);
> -		path_put(path);
> -		return -ENOENT;
> +		goto put_path;
>  	}
>  
>  	d = lookup_noperm_unlocked(&last, path->dentry);
> @@ -125,21 +120,22 @@ static int ksmbd_vfs_path_lookup(struct ksmbd_share_config *share_conf,
>  		dput(d);
>  		d = ERR_PTR(-ENOENT);
>  	}
> -	if (IS_ERR(d)) {
> -		path_put(path);
> -		return -ENOENT;
> -	}
> +	if (IS_ERR(d))
> +		goto put_path;
> +
>  	dput(path->dentry);
>  	path->dentry = d;
>  
>  	if (test_share_config_flag(share_conf, KSMBD_SHARE_FLAG_CROSSMNT)) {
>  		err = follow_down(path, 0);
> -		if (err < 0) {
> -			path_put(path);
> -			return -ENOENT;
> -		}
> +		if (err < 0)
> +			goto put_path;
>  	}
>  	return 0;
> +
> +put_path:
> +	path_put(path);
> +	return -ENOENT;
>  }
>  
>  void ksmbd_vfs_query_maximal_access(struct mnt_idmap *idmap,
> -- 
> 2.51.0
> 
> 
> 


  reply	other threads:[~2025-10-03 22:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-03 18:45 [PATCH] ksmbd: Use common error handling code in ksmbd_vfs_path_lookup() Markus Elfring
2025-10-03 22:30 ` NeilBrown [this message]
2025-10-04  8:45   ` Markus Elfring
2025-10-04 11:16     ` NeilBrown
2025-10-04 12:36       ` Markus Elfring

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=175953064635.1793333.2429881029964457140@noble.neil.brown.name \
    --to=neilb@ownmail.net \
    --cc=Markus.Elfring@web.de \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=metze@samba.org \
    --cc=neil@brown.name \
    --cc=senozhatsky@chromium.org \
    --cc=smfrench@gmail.com \
    --cc=tom@talpey.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).