From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48000) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YgHnX-0003kI-6p for qemu-devel@nongnu.org; Thu, 09 Apr 2015 15:07:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YgHnS-0008Cp-7m for qemu-devel@nongnu.org; Thu, 09 Apr 2015 15:07:31 -0400 Received: from mail-wg0-x233.google.com ([2a00:1450:400c:c00::233]:34320) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YgHnR-0008Ck-RR for qemu-devel@nongnu.org; Thu, 09 Apr 2015 15:07:26 -0400 Received: by wgso17 with SMTP id o17so18181330wgs.1 for ; Thu, 09 Apr 2015 12:07:25 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <5526CDE9.5060209@redhat.com> Date: Thu, 09 Apr 2015 21:07:21 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1428600256-18755-1-git-send-email-cota@braap.org> In-Reply-To: <1428600256-18755-1-git-send-email-cota@braap.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] translate-all: use g_malloc0 for all page descriptor allocations List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Emilio G. Cota" , qemu-devel@nongnu.org Cc: Peter Maydell On 09/04/2015 19:24, Emilio G. Cota wrote: > Since commit > > b7b5233a "bsd-user/mmap.c: Don't try to override g_malloc/g_free" > > the exception we make here for usermode has been unnecessary. > Get rid of it. > > Signed-off-by: Emilio G. Cota > --- > translate-all.c | 18 ++---------------- > 1 file changed, 2 insertions(+), 16 deletions(-) > > diff --git a/translate-all.c b/translate-all.c > index 11763c6..3a6d116 100644 > --- a/translate-all.c > +++ b/translate-all.c > @@ -389,18 +389,6 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc) > void **lp; > int i; > > -#if defined(CONFIG_USER_ONLY) > - /* We can't use g_malloc because it may recurse into a locked mutex. */ > -# define ALLOC(P, SIZE) \ > - do { \ > - P = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, \ > - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \ > - } while (0) > -#else > -# define ALLOC(P, SIZE) \ > - do { P = g_malloc0(SIZE); } while (0) > -#endif > - > /* Level 1. Always allocated. */ > lp = l1_map + ((index >> V_L1_SHIFT) & (V_L1_SIZE - 1)); > > @@ -412,7 +400,7 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc) > if (!alloc) { > return NULL; > } > - ALLOC(p, sizeof(void *) * V_L2_SIZE); > + p = g_malloc0(sizeof(void *) * V_L2_SIZE); Using g_new0 would be even better. :) Paolo > *lp = p; > } > > @@ -424,12 +412,10 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc) > if (!alloc) { > return NULL; > } > - ALLOC(pd, sizeof(PageDesc) * V_L2_SIZE); > + pd = g_malloc0(sizeof(PageDesc) * V_L2_SIZE); > *lp = pd; > } > > -#undef ALLOC > - > return pd + (index & (V_L2_SIZE - 1)); > } > >