DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] vhost: check malloc return value when allocating guest pages
@ 2017-05-11 15:25 Jens Freimann
  2017-05-18  8:14 ` Maxime Coquelin
  0 siblings, 1 reply; 3+ messages in thread
From: Jens Freimann @ 2017-05-11 15:25 UTC (permalink / raw)
  To: dev; +Cc: yuanhan.liu, maxime.coquelin

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 <jfreimann@redhat.com>
---
 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) +
-- 
2.9.3

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH] vhost: check malloc return value when allocating guest pages
  2017-05-11 15:25 [dpdk-dev] [PATCH] vhost: check malloc return value when allocating guest pages Jens Freimann
@ 2017-05-18  8:14 ` Maxime Coquelin
  2017-05-22  6:37   ` Yuanhan Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Maxime Coquelin @ 2017-05-18  8:14 UTC (permalink / raw)
  To: Jens Freimann, dev; +Cc: yuanhan.liu



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 <jfreimann@redhat.com>
> ---
>   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 <maxime.coquelin@redhat.com>

Thanks!
Maxime

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH] vhost: check malloc return value when allocating guest pages
  2017-05-18  8:14 ` Maxime Coquelin
@ 2017-05-22  6:37   ` Yuanhan Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Yuanhan Liu @ 2017-05-22  6:37 UTC (permalink / raw)
  To: Maxime Coquelin; +Cc: Jens Freimann, dev

On Thu, May 18, 2017 at 10:14:26AM +0200, Maxime Coquelin wrote:
> 
> 
> 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 <jfreimann@redhat.com>
> >---
> >  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 <maxime.coquelin@redhat.com>

Applied to dpdk-next-virtio.

Thanks.

	--yliu

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-05-22  6:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-11 15:25 [dpdk-dev] [PATCH] vhost: check malloc return value when allocating guest pages Jens Freimann
2017-05-18  8:14 ` Maxime Coquelin
2017-05-22  6:37   ` Yuanhan Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).