Skip to contentSkip to conversation

ntfs: mft: 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: mft: 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/mft.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ntfs/mft.c +1 -2
index a5019e80951b..fd07d41c2741 100644
@@ -2420,7 +2420,7 @@ int ntfs_mft_record_alloc(struct ntfs_volume *vol, const int mode,
 		 * record.
 		 */
 
-		(*ni)->mrec = kmalloc(vol->mft_record_size, GFP_NOFS);
+		(*ni)->mrec = kmemdup(m, vol->mft_record_size, GFP_NOFS);
 		if (!(*ni)->mrec) {
 			folio_unlock(folio);
 			kunmap_local(m);
@@ -2429,7 +2429,6 @@ int ntfs_mft_record_alloc(struct ntfs_volume *vol, const int mode,
 			goto undo_mftbmp_alloc;
 		}
 
-		memcpy((*ni)->mrec, m, vol->mft_record_size);
 		post_read_mst_fixup((struct ntfs_record *)(*ni)->mrec, vol->mft_record_size);
 		ntfs_mft_mark_dirty(folio);
 		folio_unlock(folio);
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

2026년 7월 4일 (토) 오후 8:11, <[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/mft.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ntfs/mft.c +1 -3
index a5019e80951b..fd07d41c2741 100644
@@ -2420,7 +2420,7 @@ int ntfs_mft_record_alloc(struct ntfs_volume *vol, const int mode,
                 * record.
                 */
 
-               (*ni)->mrec = kmalloc(vol->mft_record_size, GFP_NOFS);
+               (*ni)->mrec = kmemdup(m, vol->mft_record_size, GFP_NOFS);
                if (!(*ni)->mrec) {
                        folio_unlock(folio);
                        kunmap_local(m);
@@ -2429,7 +2429,6 @@ int ntfs_mft_record_alloc(struct ntfs_volume *vol, const int mode,
                        goto undo_mftbmp_alloc;
                }
 
-               memcpy((*ni)->mrec, m, vol->mft_record_size);
                post_read_mst_fixup((struct ntfs_record *)(*ni)->mrec, vol->mft_record_size);
                ntfs_mft_mark_dirty(folio);
                folio_unlock(folio);
--

2.43.0

Signature · 2 lines
Thanks,
Hyunchul