summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFuqian Huang <huangfq.daxian@gmail.com>2019-07-03 09:17:27 -0400
committerJan Kara <jack@suse.cz>2019-07-03 10:24:25 -0400
commit90f15ac9fa7e7ff66e0980309d8184bff0611624 (patch)
tree7a486f87d06779c52b6ebb2ea95383d84fbcda68
parent555b2c3da1fc3d1c5cc133e9353354c40fbfe336 (diff)
ext2: Use kmemdup rather than duplicating its implementation
kmemdup is introduced to duplicate a region of memory in a neat way. Rather than kmalloc/kzalloc + memset, 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 + memset. Signed-off-by: Fuqian Huang <huangfq.daxian@gmail.com> Link: https://lore.kernel.org/r/20190703131727.25735-1-huangfq.daxian@gmail.com Signed-off-by: Jan Kara <jack@suse.cz>
-rw-r--r--fs/ext2/xattr.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
index 839e71e78673..79369c13cc55 100644
--- a/fs/ext2/xattr.c
+++ b/fs/ext2/xattr.c
@@ -532,11 +532,10 @@ bad_block:
532 532
533 unlock_buffer(bh); 533 unlock_buffer(bh);
534 ea_bdebug(bh, "cloning"); 534 ea_bdebug(bh, "cloning");
535 header = kmalloc(bh->b_size, GFP_KERNEL); 535 header = kmemdup(HDR(bh), bh->b_size, GFP_KERNEL);
536 error = -ENOMEM; 536 error = -ENOMEM;
537 if (header == NULL) 537 if (header == NULL)
538 goto cleanup; 538 goto cleanup;
539 memcpy(header, HDR(bh), bh->b_size);
540 header->h_refcount = cpu_to_le32(1); 539 header->h_refcount = cpu_to_le32(1);
541 540
542 offset = (char *)here - bh->b_data; 541 offset = (char *)here - bh->b_data;