From: Ian Jackson Subject: Re: [PATCH 20/21] libxc: check return values from malloc Date: Fri, 7 Jun 2013 11:45:26 +0100 Message-ID: <20913.47558.891719.174996@mariner.uk.xensource.com> References: <1370544726-30459-1-git-send-email-ian.jackson@eu.citrix.com> <1370544726-30459-21-git-send-email-ian.jackson@eu.citrix.com> <51B0E744.7080300@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <51B0E744.7080300@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Andrew Cooper Cc: "xen-devel@lists.xensource.com" , "mattjd@gmail.com" , "security@xen.org" List-Id: xen-devel@lists.xenproject.org Andrew Cooper writes ("Re: [PATCH 20/21] libxc: check return values from malloc"): > On 06/06/13 19:52, Ian Jackson wrote: > > if (!ctx->hvm && ctx->superpages) > > + { > > ctx->p2m_saved_batch = > > malloc(ROUNDUP(MAX_BATCH_SIZE * sizeof(xen_pfn_t), PAGE_SHIFT)); > > + if ( ctx->p2m_saved_batch == NULL ) > > + { > > + ERROR("saved batch memory alloc failed"); > > + errno = ENOMEM; > > + goto out; > > + } > > + } > > Can you not merge this NULL test into the if statement immediatly below > which does all the other NULL pointer checks? > > something like (!ctx->hvm && ctx->superpages && ctx->p2m_saved_batch == NULL I thought it better to duplicate the formulaic and entirely obvious error handling code than the non-obvious and semantically relevant test for whether to allocate. Ian.