* [PATCH] btrfs:check-integrity.c: replace kmalloc with kmalloc_array
@ 2013-11-01 0:46 Himangi Saraogi
2013-11-06 17:37 ` David Sterba
0 siblings, 1 reply; 2+ messages in thread
From: Himangi Saraogi @ 2013-11-01 0:46 UTC (permalink / raw)
To: linux-btrfs
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.
Reviewed-by: Zach Brown <zab@redhat.com>
Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
---
fs/btrfs/check-integrity.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index 1c47be1..d61ffef 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -3031,8 +3031,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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] btrfs:check-integrity.c: replace kmalloc with kmalloc_array
2013-11-01 0:46 [PATCH] btrfs:check-integrity.c: replace kmalloc with kmalloc_array Himangi Saraogi
@ 2013-11-06 17:37 ` David Sterba
0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2013-11-06 17:37 UTC (permalink / raw)
To: Himangi Saraogi; +Cc: linux-btrfs
On Fri, Nov 01, 2013 at 06:16:00AM +0530, Himangi Saraogi wrote:
> 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.
Can you please convert all the instances in one patch? Feel free to use
the following cocinelle script, that found ~16 places that could use
the conversion.
$ cat kmalloc_array.cocci
@ @
expression E1, E2, E3;
@@
* \(kmalloc\|kzalloc\)(E1 * E2, E3)
---
The output is not a straight patch, the instances have to be reviewed manually
because the order of nritems and size may differ at each location.
david
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-11-06 17:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-01 0:46 [PATCH] btrfs:check-integrity.c: replace kmalloc with kmalloc_array Himangi Saraogi
2013-11-06 17:37 ` David Sterba
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).