public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Zhihao Cheng <chengzhihao1@huawei.com>
To: Dmitry Antipov <dmantipov@yandex.ru>,
	Richard Weinberger <richard@nod.at>
Cc: <linux-mtd@lists.infradead.org>
Subject: Re: [PATCH v5 2/3] ubifs: use strscpy() and kmemdup_nul() where appropriate
Date: Thu, 16 Apr 2026 14:41:59 +0800	[thread overview]
Message-ID: <e4c0d68f-5378-7184-a577-0ad7f20676fb@huawei.com> (raw)
In-Reply-To: <2f909ac5b916008033db7fd12804cf3e2a499e27.camel@yandex.ru>

在 2026/4/16 13:09, Dmitry Antipov 写道:
> On Thu, 2026-04-16 at 11:37 +0800, Zhihao Cheng wrote:
> 
>>> -	memcpy(dent->name, fname_name(nm), fname_len(nm));
>>> -	dent->name[fname_len(nm)] = '\0';
>>> +	strscpy(dent->name, fname_name(nm), fname_len(nm) + 1);
>>
>> Hi Dmitry,
>> I notice that some architectures can accelerate the implementation of
>> memcpy(), and the length of dentry name could be 255, I suggest to keep
>> the orignal implementation.
> 
> What about
> 
> memcpy_and_pad(dent->name, fname_len(nm) + 1, fname_name(nm), fname_len(nm), 0)?

I weakly accept memcpy_and_pad().
> 
> I have a strong suspicion that all of the '\0' things should be left to
> library functions. So this is not a style but rather an overall design point -
> if you're inserting '\0' at your own, most likely you're doing something
> wrong, at least because you're duplicating something which is already
> implemented in a library function.

Well, kernel developers, of course, need to understand when and how to 
set the trailing '\0'. There are many other places setting trailing 
'\0'(eg. xfs_init_local_fork, xfs_symlink_remote_read, 
ext4_xattr_move_to_block, etc.). I don't think there's a problem with 
this; the developers know what they're doing.
> 
> Dmitry
> .
> 


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  reply	other threads:[~2026-04-16  6:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-15  7:18 [PATCH v5 1/3] ubifs: prefer kstrtobool_from_user() over custom helper Dmitry Antipov
2026-04-15  7:18 ` [PATCH v5 2/3] ubifs: use strscpy() and kmemdup_nul() where appropriate Dmitry Antipov
2026-04-16  3:37   ` Zhihao Cheng
2026-04-16  5:09     ` Dmitry Antipov
2026-04-16  6:41       ` Zhihao Cheng [this message]
2026-04-15  7:18 ` [PATCH v5 3/3] ubifs: avoid redundant calls to memset() Dmitry Antipov
2026-04-16  3:52   ` Zhihao Cheng

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=e4c0d68f-5378-7184-a577-0ad7f20676fb@huawei.com \
    --to=chengzhihao1@huawei.com \
    --cc=dmantipov@yandex.ru \
    --cc=linux-mtd@lists.infradead.org \
    --cc=richard@nod.at \
    /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