ntfs: dir: use kmemdup() instead of kmalloc() and memcpy()

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@gmail.com>
Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
This commit is contained in:
Mohammad Shahid 2026-07-04 20:16:54 +05:30 committed by Namjae Jeon
parent eec908b5c0
commit 34d22551ad

View File

@ -966,13 +966,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;
}