Re: [RFC] [PATCH] cpuset operations causes Badness at mm/slab.c:777 warning

Linus Torvalds
2007-06-02T01:05:23Z

On Fri, 1 Jun 2007, Christoph Lameter wrote:
>
> On Fri, 1 Jun 2007, Andrew Morton wrote:
>
> > I think it'd be better if we kept the WARN_ON_ONCE(size == 0) in there,
>
> The trouble with the WARN_ON is that it triggers even for code that is
> okay like noted by Jeremy.

Yes. Sometimes it's just more natural to have

ptr = kmalloc(size);
.. use it ..
free(ptr);

and if a *degenerate* case of size=0 happens, who cares? It should just
work, as long as we (obviously) don't actually try to access the pointer.

So I don't much like the WARN_ON(size == 0). I think it potentially just
causes people to write around it, and quite possibly causes the callers to
write code that is not at all more readable or maintainable!

That's why I'd much rather return BADPTR instead: we'll get an oops for
buggy code, but we don't penalize the "natural" and good code! So once you
return BADPTR, there really isn't any good reason for the WARN_ON.

Linus