From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52382) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XLvuE-00070U-TC for qemu-devel@nongnu.org; Mon, 25 Aug 2014 11:10:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XLvu7-0003iK-Ou for qemu-devel@nongnu.org; Mon, 25 Aug 2014 11:10:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41967) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XLvu7-0003hu-Ge for qemu-devel@nongnu.org; Mon, 25 Aug 2014 11:09:55 -0400 Message-ID: <53FB51B4.40400@redhat.com> Date: Mon, 25 Aug 2014 09:09:40 -0600 From: Eric Blake MIME-Version: 1.0 References: <1408699567-6940-1-git-send-email-pl@kamp.de> <1408699567-6940-2-git-send-email-pl@kamp.de> In-Reply-To: <1408699567-6940-2-git-send-email-pl@kamp.de> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="CAtG1iXAnjKvmdLgsOEbfeWpSn9Qbgeqw" Subject: Re: [Qemu-devel] [PATCH 1/2] util: introduce bitmap_try_new List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Lieven , qemu-devel@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --CAtG1iXAnjKvmdLgsOEbfeWpSn9Qbgeqw Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 08/22/2014 03:26 AM, Peter Lieven wrote: > regular bitmap_new simply aborts if the memory allocation fails. > bitmap_try_new returns NULL on failure and allows for proper > error handling. >=20 > Signed-off-by: Peter Lieven > --- > include/qemu/bitmap.h | 6 ++++++ > 1 file changed, 6 insertions(+) >=20 > diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h > index 1babd5d..51b430f 100644 > --- a/include/qemu/bitmap.h > +++ b/include/qemu/bitmap.h > @@ -94,6 +94,12 @@ static inline unsigned long *bitmap_new(long nbits) > return g_malloc0(len); > } > =20 > +static inline unsigned long *bitmap_try_new(long nbits) > +{ > + long len =3D BITS_TO_LONGS(nbits) * sizeof(unsigned long); > + return g_try_malloc0(len); > +} > + What you have works, but I personally would have reimplemented bitmap_new as the first caller of bitmap_try_new in this patch, where bitmap_new handles a NULL bitmap_try_new return by abort()ing, so that it has the same behavior. By routing the one function to use the other, we are future-proofing: if initialization of a bitmap ever needs modification, we only update bitmap_try_new, rather than copying the updates to both functions. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --CAtG1iXAnjKvmdLgsOEbfeWpSn9Qbgeqw Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg iQEcBAEBCAAGBQJT+1G0AAoJEKeha0olJ0NqzPEH/1WnMfyhlhOGpGZVC+ZQULor Im02dYMIBdLoLaV45locmWNGvNtbXdfYWSjyLkNNMOGJTph8lvTod8X6c+TuTcxx QK/cvmOHVVY2h7HcNcOiSsHmfAqwskXuUn6GonOe4yPi1+3If2oJMvy44Gb2SMgk 43TePqhvxG+rVOiP/msoy6o/+WgrgKemCORpmHEz/YCXnQrck4A2dUViO9aiVgsY sAjX5s7vzoEz9EXt2trlsspUt7HMg0xpqhj+SegYYZaovmU6GDnEvgATsCKq2X8l cM2ahcgt+UM+UYbjVOLuOSMNTmNX1Y4RCfNy4hK+6MCk844sWh0IKFBPk51g1No= =QBij -----END PGP SIGNATURE----- --CAtG1iXAnjKvmdLgsOEbfeWpSn9Qbgeqw--