public inbox for ecryptfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Tyler Hicks <code@tyhicks.com>
To: Thorsten Blum <thorsten.blum@linux.dev>
Cc: Ard Biesheuvel <ardb@kernel.org>,
	Christian Brauner <brauner@kernel.org>,
	Eric Biggers <ebiggers@kernel.org>,
	Zipeng Zhang <zhangzipeng0@foxmail.com>,
	ecryptfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ecryptfs: Replace memcpy + NUL termination in ecryptfs_copy_filename
Date: Mon, 12 Jan 2026 19:46:31 -0600	[thread overview]
Message-ID: <aWWj9yHse6qVqxHN@yaupon> (raw)
In-Reply-To: <20260111131301.548411-1-thorsten.blum@linux.dev>

On 2026-01-11 14:12:58, Thorsten Blum wrote:
> Use kmemdup_nul() to copy 'name' instead of using memcpy() followed by a
> manual NUL termination.  Remove the local return variable and the goto
> label to simplify the code.  No functional changes.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>

Thank you for the simplification.

Acked-by: Tyler Hicks <code@tyhicks.com>

Tyler

> ---
>  fs/ecryptfs/crypto.c | 18 ++++--------------
>  1 file changed, 4 insertions(+), 14 deletions(-)
> 
> diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
> index d49cdf7292ab..82fc5e1b6324 100644
> --- a/fs/ecryptfs/crypto.c
> +++ b/fs/ecryptfs/crypto.c
> @@ -1422,21 +1422,11 @@ ecryptfs_encrypt_filename(struct ecryptfs_filename *filename,
>  static int ecryptfs_copy_filename(char **copied_name, size_t *copied_name_size,
>  				  const char *name, size_t name_size)
>  {
> -	int rc = 0;
> -
> -	(*copied_name) = kmalloc((name_size + 1), GFP_KERNEL);
> -	if (!(*copied_name)) {
> -		rc = -ENOMEM;
> -		goto out;
> -	}
> -	memcpy((void *)(*copied_name), (void *)name, name_size);
> -	(*copied_name)[(name_size)] = '\0';	/* Only for convenience
> -						 * in printing out the
> -						 * string in debug
> -						 * messages */
> +	(*copied_name) = kmemdup_nul(name, name_size, GFP_KERNEL);
> +	if (!(*copied_name))
> +		return -ENOMEM;
>  	(*copied_name_size) = name_size;
> -out:
> -	return rc;
> +	return 0;
>  }
>  
>  /**
> -- 
> Thorsten Blum <thorsten.blum@linux.dev>
> GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
> 

      reply	other threads:[~2026-01-13  1:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-11 13:12 [PATCH] ecryptfs: Replace memcpy + NUL termination in ecryptfs_copy_filename Thorsten Blum
2026-01-13  1:46 ` Tyler Hicks [this message]

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=aWWj9yHse6qVqxHN@yaupon \
    --to=code@tyhicks.com \
    --cc=ardb@kernel.org \
    --cc=brauner@kernel.org \
    --cc=ebiggers@kernel.org \
    --cc=ecryptfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thorsten.blum@linux.dev \
    --cc=zhangzipeng0@foxmail.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