From: Himangi Saraogi <himangi774@gmail.com>
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.
Date: Thu, 7 Nov 2013 02:25:50 +0530 [thread overview]
Message-ID: <20131106205550.GA11060@himangi-Inspiron-N5110gmail.com> (raw)
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 <himangi774@gmail.com>
---
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++) {
--
1.7.9.5
next reply other threads:[~2013-11-06 20:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-06 20:55 Himangi Saraogi [this message]
2013-11-08 0:40 ` [OPW kernel] [PATCH v2] btrfs:check-integrity.c: replace kmalloc with kmalloc_array and kzalloc with kzalloc_array Rusty Russell
2013-11-15 19:59 ` Josef Bacik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20131106205550.GA11060@himangi-Inspiron-N5110gmail.com \
--to=himangi774@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=opw-kernel@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).