From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56060) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZMpf-0006uv-Bz for qemu-devel@nongnu.org; Wed, 01 Oct 2014 12:32:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XZMpa-000844-FB for qemu-devel@nongnu.org; Wed, 01 Oct 2014 12:32:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38299) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZMpa-00083p-9D for qemu-devel@nongnu.org; Wed, 01 Oct 2014 12:32:46 -0400 Date: Wed, 1 Oct 2014 17:32:34 +0100 From: "Dr. David Alan Gilbert" Message-ID: <20141001163233.GS2606@work-vm> References: <1412060952-19407-1-git-send-email-pl@kamp.de> <1412060952-19407-2-git-send-email-pl@kamp.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1412060952-19407-2-git-send-email-pl@kamp.de> Subject: Re: [Qemu-devel] [PATCHv2 1/2] util: introduce bitmap_try_new List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Lieven Cc: kwolf@redhat.com, pbonzini@redhat.com, ronniesahlberg@gmail.com, qemu-devel@nongnu.org, stefanha@redhat.com * Peter Lieven (pl@kamp.de) wrote: > regular bitmap_new simply aborts if the memory allocation fails. > bitmap_try_new returns NULL on failure and allows for proper > error handling. > > Signed-off-by: Peter Lieven > --- > include/qemu/bitmap.h | 13 +++++++++++-- > 1 file changed, 11 insertions(+), 2 deletions(-) > > diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h > index 1babd5d..edf4f17 100644 > --- a/include/qemu/bitmap.h > +++ b/include/qemu/bitmap.h > @@ -88,10 +88,19 @@ int slow_bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1, > int slow_bitmap_intersects(const unsigned long *bitmap1, > const unsigned long *bitmap2, long bits); > > -static inline unsigned long *bitmap_new(long nbits) > +static inline unsigned long *bitmap_try_new(long nbits) > { > long len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); > - return g_malloc0(len); > + return g_try_malloc0(len); > +} > + > +static inline unsigned long *bitmap_new(long nbits) > +{ > + unsigned long *ptr = bitmap_try_new(nbits); > + if (ptr == NULL) { > + abort(); > + } > + return ptr; > } This seems like a good idea; it's probably a good idea to deprecate use of bitmap_new and get rid of the other uses in the longterm (there aren't that many). size_t would be a nice type for the nbits; could you make your bitmap_try_new use that and then fix up those users as we convert them to use the try? Dave > > static inline void bitmap_zero(unsigned long *dst, long nbits) > -- > 1.7.9.5 > > -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK