mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Xianting Tian <xianting_tian@126.com>
Cc: tytso@mit.edu, adilger.kernel@dilger.ca,
	linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
	clang-built-linux@googlegroups.com
Subject: Re: [PATCH] ext4: use kmemdup_nul() instead of kstrndup()
Date: Mon, 17 Aug 2020 19:08:53 +0200	[thread overview]
Message-ID: <20200817170853.GC22500@quack2.suse.cz> (raw)
In-Reply-To: <1596894336-49052-1-git-send-email-xianting_tian@126.com>

On Sat 08-08-20 09:45:36, Xianting Tian wrote:
> kmemdup_nul() is more efficient than kmemdup_nul() if
> the size is known exactly.
> 
> The description of kstrndup() already suggested:
> Note: Use kmemdup_nul() instead if the size is known exactly.
> 
> Signed-off-by: Xianting Tian <xianting_tian@126.com>

Thanks for the patch but I think it is not ideal. The thing is that
s_mount_opt is actually a NUL terminated string (we are just careful and
don't rely on that to avoid problems when the fs is corrupted). So it is
possibly shorter than those 64 bytes reserved for it in the superblock and
using kmemdup_nul() will allocate and copy more memory than strictly
necessary.

								Honza

> ---
>  fs/ext4/super.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 330957e..be37556 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -4016,7 +4016,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
>  	}
>  
>  	if (sbi->s_es->s_mount_opts[0]) {
> -		char *s_mount_opts = kstrndup(sbi->s_es->s_mount_opts,
> +		char *s_mount_opts = kmemdup_nul(sbi->s_es->s_mount_opts,
>  					      sizeof(sbi->s_es->s_mount_opts),
>  					      GFP_KERNEL);
>  		if (!s_mount_opts)
> -- 
> 1.8.3.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

      reply	other threads:[~2020-08-17 17:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-08 13:45 Xianting Tian
2020-08-17 17:08 ` Jan Kara [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=20200817170853.GC22500@quack2.suse.cz \
    --to=jack@suse.cz \
    --cc=adilger.kernel@dilger.ca \
    --cc=clang-built-linux@googlegroups.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=xianting_tian@126.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

all inboxes | Powered by JetHome®