summaryrefslogtreecommitdiffstats
path: root/fs/ocfs2/alloc.c
diff options
context:
space:
mode:
authorFuqian Huang <huangfq.daxian@gmail.com>2019-07-11 23:53:19 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-07-12 14:05:41 -0400
commitd8b2fa657deaa73ff70d40aea9a54997fc0c7fc9 (patch)
tree86687af68f31040dc21d90e837c2d4e9ef644f70 /fs/ocfs2/alloc.c
parent4658d87cb38cb3ab3a234d1b8d63f65df4cce62b (diff)
ocfs2: 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. [akpm@linux-foundation.org: coding style fixes] Link: http://lkml.kernel.org/r/20190703163147.881-1-huangfq.daxian@gmail.com Signed-off-by: Fuqian Huang <huangfq.daxian@gmail.com> Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com> Cc: Mark Fasheh <mark@fasheh.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Junxiao Bi <junxiao.bi@oracle.com> Cc: Changwei Ge <gechangwei@live.cn> Cc: Gang He <ghe@suse.com> Cc: Jun Piao <piaojun@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/ocfs2/alloc.c')
-rw-r--r--fs/ocfs2/alloc.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
index d1348fc4ca6d..0c335b51043d 100644
--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -6191,17 +6191,17 @@ int ocfs2_begin_truncate_log_recovery(struct ocfs2_super *osb,
6191 if (le16_to_cpu(tl->tl_used)) { 6191 if (le16_to_cpu(tl->tl_used)) {
6192 trace_ocfs2_truncate_log_recovery_num(le16_to_cpu(tl->tl_used)); 6192 trace_ocfs2_truncate_log_recovery_num(le16_to_cpu(tl->tl_used));
6193 6193
6194 *tl_copy = kmalloc(tl_bh->b_size, GFP_KERNEL); 6194 /*
6195 * Assuming the write-out below goes well, this copy will be
6196 * passed back to recovery for processing.
6197 */
6198 *tl_copy = kmemdup(tl_bh->b_data, tl_bh->b_size, GFP_KERNEL);
6195 if (!(*tl_copy)) { 6199 if (!(*tl_copy)) {
6196 status = -ENOMEM; 6200 status = -ENOMEM;
6197 mlog_errno(status); 6201 mlog_errno(status);
6198 goto bail; 6202 goto bail;
6199 } 6203 }
6200 6204
6201 /* Assuming the write-out below goes well, this copy
6202 * will be passed back to recovery for processing. */
6203 memcpy(*tl_copy, tl_bh->b_data, tl_bh->b_size);
6204
6205 /* All we need to do to clear the truncate log is set 6205 /* All we need to do to clear the truncate log is set
6206 * tl_used. */ 6206 * tl_used. */
6207 tl->tl_used = 0; 6207 tl->tl_used = 0;