ntfs: Use kmemdup rather than duplicating its implementation
PATCH v2 30/35 ntfs: Use kmemdup rather than duplicating its implementation
kmemdup is introduced to duplicate a region of memory in a neat way. Rather than kmalloc/kzalloc + memcpy, which the programmer needs to write the size twice (sometimes lead to mistakes), kmemdup improves readability, leads to smaller code and also reduce the chances of mistakes. Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.
Signed-off-by Fuqian Huang <[email protected]>
---
Changes in v2:
- Fix a typo in commit message (memset -> memcpy)
fs/ntfs/dir.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/ntfs/dir.c +4 -4
@@ -1158,14 +1158,14 @@ static int ntfs_readdir(struct file *file, struct dir_context *actor)* map the mft record without deadlocking. */ rc =le32_to_cpu (ctx->attr->data.resident.value_length); - ir =kmalloc (rc,GFP_NOFS ); +/* Copy the index root value (it has been verified in read_inode). */ + ir =kmemdup ((u8 *)ctx->attr + +le16_to_cpu (ctx->attr->data.resident.value_offset), rc,GFP_NOFS );if (unlikely (!ir)) { err = -ENOMEM ; goto err_out; } -/* Copy the index root value (it has been verified in read_inode). */ -memcpy (ir, (u8 *)ctx->attr + -le16_to_cpu (ctx->attr->data.resident.value_offset), rc); +ntfs_attr_put_search_ctx (ctx);unmap_mft_record (ndir); ctx =NULL ;
Signature · 1 line
2.11.0