Re: [PATCH] ntfs: dir: use kmemdup() instead of kmalloc() and memcpy()

From: Hyunchul Lee

Date: Sun Jul 05 2026 - 20:37:42 EST


2026년 7월 4일 (토) 오후 11:47, <mdshahid03@xxxxxxxxx>님이 작성:
>
> From: Mohammad Shahid <mdshahid03@xxxxxxxxx>
>
> Use kmemdup() instead of a separate kmalloc() and memcpy()
> pair, simplifying the code while preserving the existing
> behavior.
>
> This issue was reported by memdup.cocci.
>
> Signed-off-by: Mohammad Shahid <mdshahid03@xxxxxxxxx>

Looks good to me.

Reviewed-by: Hyunchul Lee <hyc.lee@xxxxxxxxx>

> ---
> fs/ntfs/dir.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
> index 4b6bd5f30c65..df94603ec102 100644
> --- a/fs/ntfs/dir.c
> +++ b/fs/ntfs/dir.c
> @@ -959,13 +959,14 @@ static int ntfs_readdir(struct file *file, struct dir_context *actor)
> */
> private = file->private_data;
> kfree(private->key);
> - private->key = kmalloc(le16_to_cpu(next->key_length), GFP_KERNEL);
> + private->key = kmemdup(&next->key.file_name,
> + le16_to_cpu(next->key_length),
> + GFP_KERNEL);
> if (!private->key) {
> err = -ENOMEM;
> goto out;
> }
>
> - memcpy(private->key, &next->key.file_name, le16_to_cpu(next->key_length));
> private->key_length = next->key_length;
> break;
> }
> --
> 2.43.0
>


--
Thanks,
Hyunchul