From patchwork Wed Jul 3 13:17:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuqian Huang X-Patchwork-Id: 1126876 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="CCFmnMno"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45f1qh64p5z9sQp for ; Wed, 3 Jul 2019 23:17:36 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727130AbfGCNRg (ORCPT ); Wed, 3 Jul 2019 09:17:36 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:42090 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725830AbfGCNRg (ORCPT ); Wed, 3 Jul 2019 09:17:36 -0400 Received: by mail-pf1-f193.google.com with SMTP id q10so1268336pff.9; Wed, 03 Jul 2019 06:17:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=kID8MleQILhLJBSvhNclsUXpPABPaGgap1yaL7i2q0g=; b=CCFmnMno+D5GHdrxjpBvUh9B4GejAclzpHtSteg9DYMAldleYRZvdnvIATiqhNlMzS Bsf5LiQS7nVv5ri8fdtIp+OzbVxTgkydu1SDy2WrGQSeODbx/PVLOTwz45t0/vh+DOXq snKshU9fwZKy4JcndV7lwggCLt6V2+HZB54XlCcjfFTtzYDXcapKWzKNy4gQ3rdOVCU6 oHnziz1C+8jjiBLe9kL+YcDGwsg1WwrwMPnzd+18VBLuWO+ODOcArPVOieuSquDoaVn3 W+nxbehkRExt6sGueOQF5L7ZJGwGyomqT38z9YIIgCGlfUIRUZAv1y8nDUctow/gdhp6 wgJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=kID8MleQILhLJBSvhNclsUXpPABPaGgap1yaL7i2q0g=; b=cUIpHL/Pa2yaE/qzjgKmxqQaMavKJY0DntkJlyWdh/6dhFzP6q4Ye0QkVqZlS1SjNw y1T8wkzT7GAOAdSaFSiDTQBDGOO6GGZcBHNm1nZT2smMDhlHXw8FOIjJyQe89nkSbrZP jseqN6ovnugZA2MHtXCDhGrUn1TdQJ7httOFdmNBby31pnXhJTtJYVDdwvK2MzopUUlH ivVPYpVMivYd+Xw6re7Tzyr+CZCfelanv4UuLglxGmf75rlJQSKRBDkw6jhTgJ6hxF0V pJSxLYcII99qnKg5xL6ble3CXL5PDZGvlGwXBuRQCBKRGrVoU/Z5lHmXokJcw1rhy235 mK9w== X-Gm-Message-State: APjAAAWNypXYq4NJNVEzeAaCAiGHvKkcgXtYHi84o4QLrBZNnwi80hEz pMTXUTcRr7zgl5kKqe96Yjg= X-Google-Smtp-Source: APXvYqwEz82fG8Aqjq14RhP/3Hxg5ERz3mIlO9S73tgHII5YcrQYvlMJbJ7aineL7lUinnLUFpFD7w== X-Received: by 2002:a63:607:: with SMTP id 7mr34192556pgg.240.1562159855813; Wed, 03 Jul 2019 06:17:35 -0700 (PDT) Received: from hfq-skylake.ipads-lab.se.sjtu.edu.cn ([202.120.40.82]) by smtp.googlemail.com with ESMTPSA id u10sm2255542pgk.41.2019.07.03.06.17.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jul 2019 06:17:35 -0700 (PDT) From: Fuqian Huang Cc: Jan Kara , linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, Fuqian Huang Subject: [PATCH 23/30] ext2: Use kmemdup rather than duplicating its implementation Date: Wed, 3 Jul 2019 21:17:27 +0800 Message-Id: <20190703131727.25735-1-huangfq.daxian@gmail.com> X-Mailer: git-send-email 2.11.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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 --- fs/ext2/xattr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c index 1e33e0ac8cf1..a9c641cd5484 100644 --- a/fs/ext2/xattr.c +++ b/fs/ext2/xattr.c @@ -506,11 +506,10 @@ bad_block: ext2_error(sb, "ext2_xattr_set", 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; From patchwork Wed Jul 3 13:17:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuqian Huang X-Patchwork-Id: 1126877 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="j1orMTiJ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45f1qz042Pz9sPV for ; Wed, 3 Jul 2019 23:17:51 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727202AbfGCNRq (ORCPT ); Wed, 3 Jul 2019 09:17:46 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:47033 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725830AbfGCNRq (ORCPT ); Wed, 3 Jul 2019 09:17:46 -0400 Received: by mail-pl1-f195.google.com with SMTP id e5so1225599pls.13; Wed, 03 Jul 2019 06:17:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ovgGl+jGowxGh/5LJKQzh3sNG9BCZNG/DBPIgm5xu5k=; b=j1orMTiJfi+4JeL0B+RB28+WkHswD5L1q8Lai4m7ymMXWb+sxdS2NAxmK36T+YjWMR wEb6vyHaoAPi7I0FugPkwVGncWQg42OQBcYWsjI0yHg3/N73KO/LtEjTQbJJu7Yeouoq DYl8vkoOScbEwl8vwZAjoWXGHYFPi0zzuUOu/oqSsg2d5NPZG8bFk+186PbSChKNwYV/ yWOINDW95WEemSJeveBzMy5zY4fTQcbpkCjsLssXvoenyzS56iv96KIkINDpEOPC8Cas pjzqTrjOe4EK6t6vxptKq3mojuE2DFBN/Ndq8JNAb3ysDPMMwG2GgJJ+/P2B1F1CNJKG d6EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ovgGl+jGowxGh/5LJKQzh3sNG9BCZNG/DBPIgm5xu5k=; b=k47AdMrBvLx/4euRGrMxFir3SvAzbEkxugk29Ri/Q1lSyPFFFqyRuWQhSYH8/OJlMz vGjmtTW4fKkKggCx+9cEEGjpas7u84497Osrdv94/XPT7v7iBx9btWirfgZW+/+gV8ly uAd7cYtEWGUSJCf4Ez9M3BKLxAfgLFR4KNGUWrVC5so+a7Z8xIzITeIsR747Zx+F5ctc iz/LY1T/R0EUOKtJHtJrLvtkwyKOT4fPVyU5ngMixLL3K5C0T35B+qOxnDcHx3fJWbJ2 Bi8CKpeP2MQVIlyG6T9gY9LsxP+sLm1seAxrnpAvTs7vztAOhYHLncqAvrfT2RGXA5eN Ktsg== X-Gm-Message-State: APjAAAUpGOKEQNS8eEnEyrbTR2wMFWSoRUISePZpX2kzeYZuxVFV4w8l AI7ZJJh/vpmAgKuNseVLSDE= X-Google-Smtp-Source: APXvYqyR3nq9eHErOpO7QM45dzh/9Rzb7VaRo8EfRYr0NgWRIoMtDwcvnelQBys9vfnp7NTYe5wkhA== X-Received: by 2002:a17:902:2baa:: with SMTP id l39mr2445988plb.280.1562159865770; Wed, 03 Jul 2019 06:17:45 -0700 (PDT) Received: from hfq-skylake.ipads-lab.se.sjtu.edu.cn ([202.120.40.82]) by smtp.googlemail.com with ESMTPSA id w1sm2152938pjt.30.2019.07.03.06.17.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jul 2019 06:17:45 -0700 (PDT) From: Fuqian Huang Cc: Theodore Ts'o , Andreas Dilger , linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, Fuqian Huang Subject: [PATCH 24/30] ext4: Use kmemdup rather than duplicating its implementation Date: Wed, 3 Jul 2019 21:17:37 +0800 Message-Id: <20190703131737.25781-1-huangfq.daxian@gmail.com> X-Mailer: git-send-email 2.11.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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 --- fs/ext4/xattr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index 491f9ee4040e..d09040df7014 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -1898,11 +1898,10 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, unlock_buffer(bs->bh); ea_bdebug(bs->bh, "cloning"); - s->base = kmalloc(bs->bh->b_size, GFP_NOFS); + s->base = kmemdup(BHDR(bs->bh), bs->bh->b_size, GFP_NOFS); error = -ENOMEM; if (s->base == NULL) goto cleanup; - memcpy(s->base, BHDR(bs->bh), bs->bh->b_size); s->first = ENTRY(header(s->base)+1); header(s->base)->h_refcount = cpu_to_le32(1); s->here = ENTRY(s->base + offset);