Re: p = kmalloc(sizeof(*p), )

Pekka J Enberg
2005-09-20T10:07:42Z

On Tue, Sep 20, 2005 at 12:47:32PM +0300, Pekka J Enberg wrote:
> > To find candidates, something like:
> >
> > grep "kmalloc(sizeof([^*]" -r drivers/ | grep -v "sizeof(struct"
> >
> > And then use my eyes to find real bugs.

On Tue, 20 Sep 2005, Al Viro wrote:
> "grep for kmallocs that do not have _either_ form and look for bugs among
> them" is hardly usable as an argument in favour of one of them...

I would disagree with that. The _common case_ for allocation is:

p = kmalloc(sizeof(*p), ...);

For which you know that you are allocating enough memory for the struct.
Now the only way to screw it up is to write:

p = kmalloc(sizeof(p), ...);

That is trivial to grep for.

Yes, currently, typedefs and open-coded kcalloc's give false positives but
that's what kernel janitors are for...

Pekka