Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c

From: Denys Vlasenko
Date: Sun Aug 26 2007 - 10:29:55 EST


On Sunday 26 August 2007 01:23, Robert P. J. Day wrote:
> On Sun, 26 Aug 2007, Jesper Juhl wrote:
> > On 26/08/07, Robert P. J. Day <rpjday@xxxxxxxxxxxxxx> wrote:
> > > i was thinking more along the lines of
> > >
> > > msp_parts[i] = kcalloc(pcnt, sizeof(struct mtd_partition), GFP_KERNEL);
> > >
> > > which was kind of the obvious implication, no?
> >
> > I guess
> >
> > > unless there's a reason kcalloc() wouldn't work here, this is
> > > pretty much what kcalloc() was designed for.
> >
> > When Denys brought up the zeroing thing and mentioned kzalloc() I
> > did consider kcalloc() instead, but kzalloc() makes this allocation
> > nicely look like the preceding ones visually and I couldn't convince
> > myself that kcalloc() would give us any real benefit here.
> >
> > What exactely would using kcalloc() over kzalloc() here buy us?
>
> technically, nothing.

The idea of calloc is that it can check for underflow in parameter.

calloc(-1, 10000000) => easy to detect
malloc(-1 * 10000000) => malloc(-10000000) => not so trivial
--
vda
-
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/