From: Fuqian Huang Date: Wed, 3 Jul 2019 13:17:27 +0000 (+0800) Subject: ext2: Use kmemdup rather than duplicating its implementation X-Git-Tag: v5.4-rc1~628^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=90f15ac9fa7e7ff66e0980309d8184bff0611624;p=platform%2Fkernel%2Flinux-rpi.git 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 Link: https://lore.kernel.org/r/20190703131727.25735-1-huangfq.daxian@gmail.com Signed-off-by: Jan Kara --- diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c index 839e71e..79369c1 100644 --- a/fs/ext2/xattr.c +++ b/fs/ext2/xattr.c @@ -532,11 +532,10 @@ bad_block: unlock_buffer(bh); ea_bdebug(bh, "cloning"); - header = kmalloc(bh->b_size, GFP_KERNEL); + header = kmemdup(HDR(bh), bh->b_size, GFP_KERNEL); error = -ENOMEM; if (header == NULL) goto cleanup; - memcpy(header, HDR(bh), bh->b_size); header->h_refcount = cpu_to_le32(1); offset = (char *)here - bh->b_data;