[PATCH v3 2/2] ubifs: use strscpy() and kmemdup_nul() where appropriate

Zhihao Cheng chengzhihao1 at huawei.com
Tue Apr 7 23:09:13 PDT 2026


在 2026/4/8 0:05, Dmitry Antipov 写道:
> Go closer to the modern kernel API and use 'strscpy()' and 'kmemdup_nul()'
> over an ad-hoc ensure-to-have-'\0' quirks where appropriate.
> 
> Signed-off-by: Dmitry Antipov <dmantipov at yandex.ru>
> ---
> v3: fix strscpy() usage as noticed by Zhihao
> v2: initial version to join the series
> ---
>   fs/ubifs/journal.c | 18 ++++++------------
>   fs/ubifs/replay.c  |  3 +--
>   fs/ubifs/super.c   |  8 ++------
>   3 files changed, 9 insertions(+), 20 deletions(-)
> 
> diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c
> index e28ab4395e5c..b8c4ab8990c2 100644
> --- a/fs/ubifs/journal.c
> +++ b/fs/ubifs/journal.c
> @@ -729,8 +729,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
>   	dent->inum = deletion ? 0 : cpu_to_le64(inode->i_ino);
>   	dent->type = get_dent_type(inode->i_mode);
>   	dent->nlen = cpu_to_le16(fname_len(nm));
> -	memcpy(dent->name, fname_name(nm), fname_len(nm));
> -	dent->name[fname_len(nm)] = '\0';
> +	strscpy(dent->name, fname_name(nm), dent->nlen + 1);

The 'dent->nlen' is a little endian type, cannot be used directly.
>   	set_dent_cookie(c, dent);
>   
>   	zero_dent_node_unused(dent);





More information about the linux-mtd mailing list