Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2768794ybi; Thu, 4 Jul 2019 19:06:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqzuGS/NhDf/oR7+2Ca+syZFk6F0Tc5ubBKPfs7wqEMwNKIYvjcBZ022V3J+Slcd8F7LGzzp X-Received: by 2002:a17:902:7288:: with SMTP id d8mr1186280pll.133.1562292379862; Thu, 04 Jul 2019 19:06:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562292379; cv=none; d=google.com; s=arc-20160816; b=UcTDGq9718pfMjKP5WrBNcJAW5GDI1Wf/l6owDmLb3viH0JFvE/I15tUDs5ov95g5E W2ZPNGCgeq9eLly1Cz2atimlKzPDVQbhhd4TZFw5/hx0wn3v0CRBVO79E92/MB9T5Q8K grg5UHT/9SnGE/fyy4fdzJENiaPtISEtbx1+FXxcMMGFSsAqsxVCre2s+01h6/Zt5irB +eS1Xk3owvnFfZCrMXO8VL56epQuJpvJ95mxuwGRz1POiVrJrx3Dt2DU9iJDJ7g0LZHw mQWBMV85NYTU8l//zvrmTBwvDNTSsUfvSz1oCHjXL2JkED9z2CIOJTvqALD1WecCRUcw 1/zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=P8yvjJ5U/gp3LryO3+o9dGFCofDbdqVY0v1tf/ciW3s=; b=lvJoU3YySBSrkF+2b3sMz34wzNaj+7GAFNk/g2q77ELvcJSvua9YPJ+M5gbGutujbo E+x52Fy/QVonIS5Aix0FU2ZCB3JOl8dgjncXtL6Bqll/iboPlF3nxsNA3LXu6RHB/xLW FQu79HtgrRGkU4g5/NDLZMyWFhZVjMb0Jp72RbzOR68emu7YE1lCQ/Ob+ODfQjVn5BXh fTK15fbSle960S8bkSkP5sxRqC4+2sORO9rdtmvosoXGD/3t1IMrW51ymciCKSrdAlbM NTlGSuW9lYikRUu30V/CtBAoESckYv/hvkPZBSptlsupIOFytwBv94RVDZh2zacWQ9r9 w8kQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t63si7265253pfb.5.2019.07.04.19.06.04; Thu, 04 Jul 2019 19:06:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727342AbfGEBOn (ORCPT + 99 others); Thu, 4 Jul 2019 21:14:43 -0400 Received: from out4436.biz.mail.alibaba.com ([47.88.44.36]:62487 "EHLO out4436.biz.mail.alibaba.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726024AbfGEBOn (ORCPT ); Thu, 4 Jul 2019 21:14:43 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04395;MF=joseph.qi@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0TW2lgUv_1562289279; Received: from JosephdeMacBook-Pro.local(mailfrom:joseph.qi@linux.alibaba.com fp:SMTPD_---0TW2lgUv_1562289279) by smtp.aliyun-inc.com(127.0.0.1); Fri, 05 Jul 2019 09:14:40 +0800 Subject: Re: [PATCH v2 31/35] ocfs2: Use kmemdup rather than duplicating its implementation To: Fuqian Huang Cc: Mark Fasheh , Joel Becker , ocfs2-devel@oss.oracle.com, linux-kernel@vger.kernel.org, Andrew Morton References: <20190703163147.881-1-huangfq.daxian@gmail.com> From: Joseph Qi Message-ID: Date: Fri, 5 Jul 2019 09:14:39 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20190703163147.881-1-huangfq.daxian@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 19/7/4 00:31, Fuqian Huang wrote: > 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 Looks good. Reviewed-by: Joseph Qi > --- > Changes in v2: > - Fix a typo in commit message (memset -> memcpy) > > fs/ocfs2/alloc.c | 8 +++----- > fs/ocfs2/localalloc.c | 6 ++---- > 2 files changed, 5 insertions(+), 9 deletions(-) > > diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c > index d1348fc4ca6d..d4911d70c326 100644 > --- a/fs/ocfs2/alloc.c > +++ b/fs/ocfs2/alloc.c > @@ -6191,17 +6191,15 @@ int ocfs2_begin_truncate_log_recovery(struct ocfs2_super *osb, > if (le16_to_cpu(tl->tl_used)) { > trace_ocfs2_truncate_log_recovery_num(le16_to_cpu(tl->tl_used)); > > - *tl_copy = kmalloc(tl_bh->b_size, GFP_KERNEL); > + /* Assuming the write-out below goes well, this copy > + * will be passed back to recovery for processing. */ > + *tl_copy = kmemdup(tl_bh->b_data, tl_bh->b_size, GFP_KERNEL); > if (!(*tl_copy)) { > status = -ENOMEM; > mlog_errno(status); > goto bail; > } > > - /* Assuming the write-out below goes well, this copy > - * will be passed back to recovery for processing. */ > - memcpy(*tl_copy, tl_bh->b_data, tl_bh->b_size); > - > /* All we need to do to clear the truncate log is set > * tl_used. */ > tl->tl_used = 0; > diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c > index f03674afbd30..158e5af767fd 100644 > --- a/fs/ocfs2/localalloc.c > +++ b/fs/ocfs2/localalloc.c > @@ -424,12 +424,11 @@ void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb) > bh = osb->local_alloc_bh; > alloc = (struct ocfs2_dinode *) bh->b_data; > > - alloc_copy = kmalloc(bh->b_size, GFP_NOFS); > + alloc_copy = kmemdup(alloc, bh->b_size, GFP_NOFS); > if (!alloc_copy) { > status = -ENOMEM; > goto out_commit; > } > - memcpy(alloc_copy, alloc, bh->b_size); > > status = ocfs2_journal_access_di(handle, INODE_CACHE(local_alloc_inode), > bh, OCFS2_JOURNAL_ACCESS_WRITE); > @@ -1272,13 +1271,12 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb, > * local alloc shutdown won't try to double free main bitmap > * bits. Make a copy so the sync function knows which bits to > * free. */ > - alloc_copy = kmalloc(osb->local_alloc_bh->b_size, GFP_NOFS); > + alloc_copy = kmemdup(alloc, osb->local_alloc_bh->b_size, GFP_NOFS); > if (!alloc_copy) { > status = -ENOMEM; > mlog_errno(status); > goto bail; > } > - memcpy(alloc_copy, alloc, osb->local_alloc_bh->b_size); > > status = ocfs2_journal_access_di(handle, > INODE_CACHE(local_alloc_inode), >