From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id EB52C20F for ; Thu, 18 May 2017 10:14:32 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1AE827F4A5; Thu, 18 May 2017 08:14:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1AE827F4A5 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=maxime.coquelin@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1AE827F4A5 Received: from [10.36.112.30] (ovpn-112-30.ams2.redhat.com [10.36.112.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 66A5B19C99; Thu, 18 May 2017 08:14:29 +0000 (UTC) To: Jens Freimann , dev@dpdk.org Cc: yuanhan.liu@linux.intel.com References: <20170511152526.18379-1-jfreimann@redhat.com> From: Maxime Coquelin Message-ID: <60b35110-df0e-f42b-c331-709b6435f737@redhat.com> Date: Thu, 18 May 2017 10:14:26 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.0 MIME-Version: 1.0 In-Reply-To: <20170511152526.18379-1-jfreimann@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 18 May 2017 08:14:32 +0000 (UTC) Subject: Re: [dpdk-dev] [PATCH] vhost: check malloc return value when allocating guest pages X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 May 2017 08:14:33 -0000 On 05/11/2017 05:25 PM, Jens Freimann wrote: > When we try to allocate guest pages we need to check the return value of > malloc(). Print an error message and return when it fails. > > Signed-off-by: Jens Freimann > --- > lib/librte_vhost/vhost_user.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c > index 5c8058b..437e41f 100644 > --- a/lib/librte_vhost/vhost_user.c > +++ b/lib/librte_vhost/vhost_user.c > @@ -515,6 +515,13 @@ vhost_user_set_mem_table(struct virtio_net *dev, struct VhostUserMsg *pmsg) > dev->max_guest_pages = 8; > dev->guest_pages = malloc(dev->max_guest_pages * > sizeof(struct guest_page)); > + if (dev->guest_pages == NULL) { > + RTE_LOG(ERR, VHOST_CONFIG, > + "(%d) failed to allocate memory " > + "for dev->guest_pages\n", > + dev->vid); > + return -1; > + } > } > > dev->mem = rte_zmalloc("vhost-mem-table", sizeof(struct rte_vhost_memory) + > Reviewed-by: Maxime Coquelin Thanks! Maxime