Re: SLUB: Return ZERO_SIZE_PTR for kmalloc(0)

From: Linus Torvalds
Date: Mon Jun 04 2007 - 14:47:42 EST




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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/