Re: SLUB: Return ZERO_SIZE_PTR for kmalloc(0)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux