ntfs: dir: use kmemdup() instead of kmalloc() and memcpy()
Subsystems (2)
PATCH 1/1 ntfs: dir: use kmemdup() instead of kmalloc() and memcpy()
From: Mohammad Shahid <[email protected]>
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.
--- fs/ntfs/dir.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/ntfs/dir.c +3 -2
@@ -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 ; }
Signature · 1 line
2.43.0
2026년 7월 4일 (토) 오후 11:47, <[email protected]>님이 작성:
Quoted 10 lines
From: Mohammad Shahid <[email protected]>
Use
kmemdup()instead of a separatekmalloc()andmemcpy()pair, simplifying the code while preserving the existing behavior.This issue was reported by
memdup.cocci.Signed-off-by Mohammad Shahid <[email protected]>
Looks good to me.
Quoted 28 lines
--- fs/ntfs/dir.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)fs/ntfs/dir.c +3
-3@@ -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
Signature · 2 lines
Thanks, Hyunchul
Quoted 10 lines · On Sat, Jul 4, 2026 at 11:47 PM <[email protected]> wrote:
From: Mohammad Shahid <[email protected]>
Use
kmemdup()instead of a separatekmalloc()andmemcpy()pair, simplifying the code while preserving the existing behavior.This issue was reported by
memdup.cocci.Signed-off-by Mohammad Shahid <[email protected]>
Applied it to #ntfs-next.
Thanks!