lkml.org 
[lkml]   [2014]   [May]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] checkpatch: Add --strict test for kmalloc/kzalloc with multiply
On Thu, 15 May 2014 16:04:46 -0700 Joe Perches <joe@perches.com> wrote:

> 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,

I'd prefer that - this is one of my regular comment-on-during-review
things.



\
 
 \ /
  Last update: 2014-05-16 01:21    [W:0.040 / U:0.328 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site