mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Whitcroft <apw@canonical.com>, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] checkpatch: Add --strict test for kmalloc/kzalloc with multiply
Date: Thu, 15 May 2014 16:04:46 -0700	[thread overview]
Message-ID: <1400195086.5058.26.camel@joe-AO725> (raw)
In-Reply-To: <20140515155844.041ee0bc17aae5f3b8eacd70@linux-foundation.org>

On Thu, 2014-05-15 at 15:58 -0700, Andrew Morton wrote:
> On Tue, 13 May 2014 16:48:49 -0700 Joe Perches <joe@perches.com> wrote:
> > Protect against sizeof overflows by preferring
> > kmalloc_array and kcalloc to kmalloc/kzalloc
> > with a sizeof multiply.
[]
> > +# check for k[mz]alloc with multiplies that could be kmalloc_array/kcalloc
> > +		if ($^V && $^V ge 5.10.0 &&
> > +		    $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/) {
> > +			my $oldfunc = $3;
> > +			my $a1 = $4;
> > +			my $a2 = $10;
> > +			my $newfunc = "kmalloc_array";
> > +			$newfunc = "kcalloc" if ($oldfunc eq "kzalloc");
> > +			if ($a1 =~ /^sizeof\s*\S/ || $a2 =~ /^sizeof\s*\S/) {
> > +				CHK("ALLOC_WITH_MULTIPLY",
> > +				    "Prefer $newfunc over $oldfunc with multiply\n" . $herecurr);
> > +			}
> > +		}
> > +
> 
> Why hide this behind --strict?

Non-obvious CHK/--strict tests are less controversial.

The block above it
"prefer foo = alloc(sizeof(*foo)) over foo = alloc(sizeof(struct bar))"
used CHK so I copied it.

I've no objection to making it WARN instead,



  reply	other threads:[~2014-05-15 23:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-13 23:48 Joe Perches
2014-05-15 22:58 ` Andrew Morton
2014-05-15 23:04   ` Joe Perches [this message]
2014-05-15 23:07     ` Andrew Morton
2014-05-15 23:27       ` [PATCH V2] checkpatch: Add warning " Joe Perches

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=1400195086.5058.26.camel@joe-AO725 \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=apw@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®