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

mdshahid03@gmail.com posted 1 patch 4 hours ago
fs/ntfs/dir.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
[PATCH] ntfs: dir: use kmemdup() instead of kmalloc() and memcpy()
Posted by mdshahid03@gmail.com 4 hours ago
From: Mohammad Shahid <mdshahid03@gmail.com>

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>
---
 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