[PATCH v5 2/3] ubifs: use strscpy() and kmemdup_nul() where appropriate
Zhihao Cheng
chengzhihao1 at huawei.com
Wed Apr 15 23:41:59 PDT 2026
在 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
> .
>
More information about the linux-mtd
mailing list