From patchwork Wed Nov 6 20:55:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: HIMANGI SARAOGI X-Patchwork-Id: 3149101 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2F352BEEB2 for ; Wed, 6 Nov 2013 20:56:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2ECFA205E2 for ; Wed, 6 Nov 2013 20:56:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0C3B9205BB for ; Wed, 6 Nov 2013 20:56:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756017Ab3KFUz5 (ORCPT ); Wed, 6 Nov 2013 15:55:57 -0500 Received: from mail-pa0-f43.google.com ([209.85.220.43]:44951 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755711Ab3KFUz5 (ORCPT ); Wed, 6 Nov 2013 15:55:57 -0500 Received: by mail-pa0-f43.google.com with SMTP id hz1so222968pad.2 for ; Wed, 06 Nov 2013 12:55:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=X5PhV9XBHWmgdIPcOMLQ6mwA/jIE6IXvQFjcx/KXqGk=; b=Lz+ozxQDGZcv1u2SufjU3jH2kn/3ebkKChBFO08icFX18HqkEiQ7V2V5is9QD1ulKE TyFOFv75qoEM0j6OGuOIvtop2ijzgkqHabyUTDeAwcuEvSwTavfhZt2yNgLsMd3Wyt/k +pKgNA4E5Y9L95jYNdab37IhtBZ9ZtIfBQwxfaQk2XDiz8HT6EClZgFCdKtQtvDTxDGL wPjHJ5wT8nwXMCbiW8V6FJUsX6+9CuZD6aGhN2HzQMAcYGRrb0jOB09G0vjniCMDlFd+ o0Qf840GpfCxiH+/15muvvGn/E6IiUP6oGSljSaDwAG/91gVrBhSSTFOQhLBFu+AxfVv +wKQ== X-Received: by 10.66.66.11 with SMTP id b11mr6032886pat.154.1383771356238; Wed, 06 Nov 2013 12:55:56 -0800 (PST) Received: from himangi-Inspiron-N5110 ([14.139.82.6]) by mx.google.com with ESMTPSA id fk4sm703354pab.23.2013.11.06.12.55.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 06 Nov 2013 12:55:54 -0800 (PST) Date: Thu, 7 Nov 2013 02:25:50 +0530 From: Himangi Saraogi To: opw-kernel@googlegroups.com, linux-btrfs@vger.kernel.org Subject: [PATCH v2] btrfs:check-integrity.c: replace kmalloc with kmalloc_array and kzalloc with kzalloc_array. Message-ID: <20131106205550.GA11060@himangi-Inspiron-N5110gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch replaces kmalloc(size * nr, ) with kmalloc_array(nr, size) as kmalloc_array() is preferred because it can check that the calculation doesn't wrap and won't return a smaller allocation. Also kzalloc(size * nr) was replaced with kzalloc_array(). Signed-off-by: Himangi Saraogi Reviewed-by: Rusty Russell --- fs/btrfs/check-integrity.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c index 1c47be1..925a52b 100644 --- a/fs/btrfs/check-integrity.c +++ b/fs/btrfs/check-integrity.c @@ -1660,9 +1660,10 @@ static int btrfsic_read_block(struct btrfsic_state *state, num_pages = (block_ctx->len + (u64)PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; - block_ctx->mem_to_free = kzalloc((sizeof(*block_ctx->datav) + - sizeof(*block_ctx->pagev)) * - num_pages, GFP_NOFS); + block_ctx->mem_to_free = kzalloc_array(num_pages, + (sizeof(*block_ctx->datav) + + sizeof(*block_ctx->pagev)), + GFP_NOFS); if (!block_ctx->mem_to_free) return -1; block_ctx->datav = block_ctx->mem_to_free; @@ -3031,8 +3032,9 @@ void btrfsic_submit_bio(int rw, struct bio *bio) (unsigned long long)bio->bi_sector, dev_bytenr, bio->bi_bdev); - mapped_datav = kmalloc(sizeof(*mapped_datav) * bio->bi_vcnt, - GFP_NOFS); + mapped_datav = kmalloc_array(bio->bi_vcnt, + sizeof(*mapped_datav), + GFP_NOFS); if (!mapped_datav) goto leave; for (i = 0; i < bio->bi_vcnt; i++) {