Re: [RFC][PATCH] kmalloc + memset(foo, 0, bar) = kmalloc0

From: Rolf Eike Beer
Date: Thu Sep 11 2003 - 09:11:15 EST


Am Donnerstag, 11. September 2003 15:45 schrieben Sie:
> On Thu, Sep 11, 2003 at 03:40:58PM +0200, Rolf Eike Beer wrote:
> > Hi,
> >
> > a (very) simple grep in drivers/ showed more than 300 matches of code
> > like this:
> >
> > foo = kmalloc(bar, baz);
> > if (! foo)
> > return -ENOMEM;
> > memset(foo, 0, sizeof(foo));

> Erm. It would better *not* be there in such amounts - sizeof(foo) would
> be a size of pointer...

Eek, yes. Typo from me.

> > Why not add a small inlined function doing the memset for us
> > and reducing the code to
> >
> > foo = kmalloc0(bar, baz);
> > if (! foo)
> > return -ENOMEM;
>
> Bad choice of name - too easy to confuse with kmalloc().

Yes, maybe. But don't expect more innovations from me today, it's someone
else's turn ;)

Eike
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/