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

From: viro
Date: Thu Sep 11 2003 - 08:48:56 EST


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

> 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().
-
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/