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

From: Linus Torvalds
Date: Fri Jun 01 2007 - 21:05:25 EST




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