From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MBHCz-0003LT-Gp for qemu-devel@nongnu.org; Mon, 01 Jun 2009 19:46:25 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MBHCu-0003F5-RI for qemu-devel@nongnu.org; Mon, 01 Jun 2009 19:46:24 -0400 Received: from [199.232.76.173] (port=55823 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MBHCu-0003Ex-M9 for qemu-devel@nongnu.org; Mon, 01 Jun 2009 19:46:20 -0400 Received: from mail2.shareable.org ([80.68.89.115]:45682) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MBHCu-0000e3-0k for qemu-devel@nongnu.org; Mon, 01 Jun 2009 19:46:20 -0400 Date: Tue, 2 Jun 2009 00:46:17 +0100 From: Jamie Lokier Subject: Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently Message-ID: <20090601234617.GD28406@shareable.org> References: <1758936.71791243858884274.JavaMail.root@srv-05.w4a.fr> <1318873.71811243859093306.JavaMail.root@srv-05.w4a.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1318873.71811243859093306.JavaMail.root@srv-05.w4a.fr> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: jcd@tribudubois.net Cc: Kevin Wolf , qemu-devel@nongnu.org jcd@tribudubois.net wrote: > > ----- "Jamie Lokier" a écrit : > > > jcd@tribudubois.net wrote: > > > Hi Kevin, > > > > > > Thanks for pointing this. I guess it just sounds strange to me that > > > somebody would want to alloc 0 bytes. But why not ... > > > > Something that nobody pointed out is that sometimes you can have > > zero-length structures these days. E.g. if you have a struct > > containing a few spinlocks in the Linux kernel, it will be zero > > length > > when built on UP targets. I doubt if QEMU has any such structures, > > but it's the sort of thing that shouldn't break > > qemu_malloc(sizeof(some_type)). > > This is true but the kernel API is also making a clear distinction between the NULL returned value for allocation error and the specific ZERO_SIZE_PTR value returned for kmalloc(0, XXX). Things don't get mixed ... Ooh, smart. That crossed my mind for qemu_malloc() too: return (void*)16, will SEGFAULT just like NULL but is non-NULL. -- Jamie