Re: [RFC 0/4] CONFIG_STABLE to switch off development checks

Dave Kleikamp
2007-06-02T15:23:23Z

On Fri, 2007-06-01 at 11:58 -0700, Jeremy Fitzhardinge wrote:
> Christoph Lameter wrote:
> > Hmmm... We got there because SLUB initially return NULL for kmalloc(0).
> > Rationale: The user did not request any memory so we wont give him
> > any.
> >
> > That (to my surprise) caused some strange behavior of code and so we then
> > decided to keep SLAB behavior and return the smallest available object
> > size and put a warning in there. At some later point we plan to switch
> > to returning NULL for kmalloc(0).
> >
>
> Unfortunately, returning NULL is indistinguishable from ENOMEM, so the
> caller would have to check to see how much it asked for before deciding
> to really fail, which doesn't help things much.
>
> Or does it (should it) return ERRPTR(-ENOMEM)? Bit of a major API
> change if not.

I'm on Christoph's side here. I don't think it makes sense for any code
to ask to allocate zero bytes of memory and expect valid memory to be
returned.

Would a compromise be to return a pointer to some known invalid region?
This way the kmalloc(0) call would appear successful to the caller, but
any access to the memory would result in an exception.

Just my 2 cents,
Shaggy
--
David Kleikamp
IBM Linux Technology Center