Re: [RFC][PATCH 08/13] do_sys_truncate(): import pathname only once

Jan Kara <[email protected]>
Newsgroups org.kernel.vger.audit,org.kernel.vger.io-uring,org.kernel.vger.linux-fsdevel
Message-ID <arcknrpnyknuqttlqehrjwveufd2xpzdlq3ao4bizwdmkz2kog@aj77rfxxcdah>
On Sun 09-11-25 06:37:40, Al Viro wrote:
> Convert the user_path_at() call inside a retry loop into getname_flags() +
> filename_lookup() + putname() and leave only filename_lookup() inside
> the loop.
> 
> In this case we never pass LOOKUP_EMPTY, so getname_flags() is equivalent
> to plain getname().
> 
> The things could be further simplified by use of cleanup.h stuff, but
> let's not clutter the patch with that.
> 
> Signed-off-by: Al Viro <[email protected]>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <[email protected]>

								Honza

> ---
>  fs/open.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/open.c b/fs/open.c
> index e67baae339fc..eb2ff940393d 100644
> --- a/fs/open.c
> +++ b/fs/open.c
> @@ -129,14 +129,16 @@ EXPORT_SYMBOL_GPL(vfs_truncate);
>  int do_sys_truncate(const char __user *pathname, loff_t length)
>  {
>  	unsigned int lookup_flags = LOOKUP_FOLLOW;
> +	struct filename *name;
>  	struct path path;
>  	int error;
>  
>  	if (length < 0)	/* sorry, but loff_t says... */
>  		return -EINVAL;
>  
> +	name = getname(pathname);
>  retry:
> -	error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path);
> +	error = filename_lookup(AT_FDCWD, name, lookup_flags, &path, NULL);
>  	if (!error) {
>  		error = vfs_truncate(&path, length);
>  		path_put(&path);
> @@ -145,6 +147,7 @@ int do_sys_truncate(const char __user *pathname, loff_t length)
>  		lookup_flags |= LOOKUP_REVAL;
>  		goto retry;
>  	}
> +	putname(name);
>  	return error;
>  }
>  
> -- 
> 2.47.3
> 
-- 
Jan Kara <[email protected]>
SUSE Labs, CR
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.