From mboxrd@z Thu Jan 1 00:00:00 1970 From: Julien Grall Subject: [PATCH] xen/arm: Directly return NULL if Xen fails to allocate domain struct Date: Fri, 31 Jan 2014 22:22:45 +0000 Message-ID: <1391206965-25727-1-git-send-email-julien.grall@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1W9MU7-0007Yf-Gj for xen-devel@lists.xenproject.org; Fri, 31 Jan 2014 22:22:51 +0000 Received: by mail-ea0-f169.google.com with SMTP id h10so2639868eak.14 for ; Fri, 31 Jan 2014 14:22:49 -0800 (PST) List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: stefano.stabellini@citrix.com, Julien Grall , tim@xen.org, ian.campbell@citrix.com, patches@linaro.org List-Id: xen-devel@lists.xenproject.org The current implementation of alloc_domain_struct, dereference the newly allocated pointer even if the allocation has failed. Signed-off-by: Julien Grall --- This is a bug fix for Xen 4.4. Without this patch if Xen run out of memory, it will segfault because it's trying to dereference a NULL pointer. --- xen/arch/arm/domain.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 635a9a4..c279a27 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -409,8 +409,10 @@ struct domain *alloc_domain_struct(void) struct domain *d; BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE); d = alloc_xenheap_pages(0, 0); - if ( d != NULL ) - clear_page(d); + if ( d == NULL ) + return NULL; + + clear_page(d); d->arch.grant_table_gpfn = xmalloc_array(xen_pfn_t, max_nr_grant_frames); return d; } -- 1.7.10.4