[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1475142864.31297.5.camel@tiscali.nl>
Date: Thu, 29 Sep 2016 11:54:24 +0200
From: Paul Bolle <pebolle@...cali.nl>
To: Andy Whitcroft <apw@...onical.com>, Joe Perches <joe@...ches.com>
Cc: SF Markus Elfring <elfring@...rs.sourceforge.net>,
dm-devel@...hat.com, linux-raid@...r.kernel.org,
Alasdair Kergon <agk@...hat.com>,
Mike Snitzer <snitzer@...hat.com>,
Shaohua Li <shli@...nel.org>,
LKML <linux-kernel@...r.kernel.org>,
kernel-janitors@...r.kernel.org,
Julia Lawall <julia.lawall@...6.fr>
Subject: Re: [PATCH 01/10] dm snapshot: Use kmalloc_array() in
init_origin_hash()
Andy, Joe,
On Thu, 2016-09-29 at 11:07 +0200, SF Markus Elfring wrote:
> * Multiplications for the size determination of memory allocations
> indicated that array data structures should be processed.
> Thus use the corresponding function "kmalloc_array".
>
> This issue was detected by using the Coccinelle software.
We have no hope of fixing Markus' homegrown coccinelle script. But we
could try to fix the checkpatch false positive here. Something like:
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 206a6b3..b47201d 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -5693,7 +5693,7 @@ sub process {
$r2 = $a1;
}
if ($r1 !~ /^sizeof\b/ && $r2 =~ /^sizeof\s*\S/ &&
- !($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*$/)) {
+ !($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*\b/)) {
if (WARN("ALLOC_WITH_MULTIPLY",
"Prefer $newfunc over $oldfunc with multiply\n" . $herecurr) &&
$fix) {
Does that work for you too?
> --- a/drivers/md/dm-snap.c
> +++ b/drivers/md/dm-snap.c
> @@ -326,8 +326,9 @@ static int init_origin_hash(void)
> {
> int i;
>
> - _origins = kmalloc(ORIGIN_HASH_SIZE * sizeof(struct list_head),
> - GFP_KERNEL);
> + _origins = kmalloc_array(ORIGIN_HASH_SIZE,
> + sizeof(*_origins),
> + GFP_KERNEL);
> if (!_origins) {
> DMERR("unable to allocate memory for _origins");
> return -ENOMEM;
> @@ -335,8 +336,9 @@ static int init_origin_hash(void)
> for (i = 0; i < ORIGIN_HASH_SIZE; i++)
> INIT_LIST_HEAD(_origins + i);
>
> - _dm_origins = kmalloc(ORIGIN_HASH_SIZE * sizeof(struct list_head),
> - GFP_KERNEL);
> + _dm_origins = kmalloc_array(ORIGIN_HASH_SIZE,
> + sizeof(*_dm_origins),
> + GFP_KERNEL);
> if (!_dm_origins) {
> DMERR("unable to allocate memory for _dm_origins");
> kfree(_origins);
Thanks,
Paul Bolle
Powered by blists - more mailing lists