Messages in this thread | | | Date | Mon, 4 Jun 2007 11:47:18 -0700 (PDT) | From | Linus Torvalds <> | Subject | Re: SLUB: Return ZERO_SIZE_PTR for kmalloc(0) |
| |
On Fri, 1 Jun 2007, Christoph Lameter wrote: > > Instead of returning the smallest available object return ZERO_SIZE_PTR.
Ok, I just noticed that this still has a bug: not just kfree(), but krealloc() needs to treat ZERO_SIZE_PTR properly.
Your patch introduces two bugs in mm/slub.c:krealloc():
- The
if (unlikely(!p)) return kmalloc(new_size, flags);
test needs to be for NULL or ZERO_SIZE_PTR. Otherwise it will oops in ksize(p), I think.
- And the
if (unlikely(!new_size)) { kfree(p); return NULL; }
thing should logically return ZERO_SIZE_PTR instead of NULL.
So basically
krealloc(kmalloc(0), n, flags);
must work, and
krealloc(old, 0, flags)
should return a zero-sized allocation.
I'd forgotten about krealloc(), because that whole concept is fairly new.
Linus - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |