Re: SLUB: Return ZERO_SIZE_PTR for kmalloc(0)
From: William Lee Irwin III
Date: Mon Jun 04 2007 - 14:05:00 EST
On Mon, Jun 04, 2007 at 10:50:41AM -0700, Linus Torvalds wrote:
> The exception is if you use the memory allocator as a "ID allocator", but
> quite frankly, if you use a size of zero, it's your own damn problem.
> Insane code is not an argument for insane behaviour.
> If people can't be bothered to create a "random ID generator" themselves,
> they had damn well better use "kmalloc(1)" rather than "kmalloc(0)" to get
> a unique cookie. Asking the allocator to do something idiotic because some
> idiot thinks a memory allocator is a cookie allocator is just crazy.
It's not such a great idea in general. Maybe it's a dumb device to cut
down on lines of code for merging or some such.
On Mon, Jun 04, 2007 at 10:50:41AM -0700, Linus Torvalds wrote:
> I can understand that things like user-level libraries have to take crazy
> people into account, but the kernel internal libraries definitely do not.
> (Right now we warn once for zero-sized allocations anyway, and all the
> cases we've found so far are either bugs that would have been found with
> ZERO_ALLOC_PTR or would have been perfectly fine with it, so I don't think
> anybody really _is_ that insane in the kernel)
There are always drivers for that, but I doubt any were sufficiently
creative to pick up on this. At least I've not see any.
-- wli
-
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/