Skip to contentSkip to conversation

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

PATCH Applied [email protected] 3 participants 3 messages Jul 4 – Jul 6

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index 4b6bd5f30c65..df94603ec102 100644
@@ -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
maintainer Reviewed-by on v1 1/1
#1 lore raw

2026년 7월 4일 (토) 오후 11:47, <[email protected]>님이 작성:

Quoted 10 lines

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.

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
index 4b6bd5f30c65..df94603ec102 100644
@@ -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