DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] vhost: refine the vhost_new_device
@ 2018-06-08  9:18 xiangxia.m.yue
  2018-06-08 14:05 ` Maxime Coquelin
  2018-06-15  8:01 ` Maxime Coquelin
  0 siblings, 2 replies; 3+ messages in thread
From: xiangxia.m.yue @ 2018-06-08  9:18 UTC (permalink / raw)
  To: dev; +Cc: Tonghao Zhang

From: Tonghao Zhang <xiangxia.m.yue@gmail.com>

Make sure find avalid device id before allocating
virtio_net, if not, return directly. It may avoid
allocating and freeing virtio_net when there is
not valid device id.

Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
---
 lib/librte_vhost/vhost.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index afded49..ed7b7ac 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -268,21 +268,21 @@
 	struct virtio_net *dev;
 	int i;
 
-	dev = rte_zmalloc(NULL, sizeof(struct virtio_net), 0);
-	if (dev == NULL) {
-		RTE_LOG(ERR, VHOST_CONFIG,
-			"Failed to allocate memory for new dev.\n");
-		return -1;
-	}
-
 	for (i = 0; i < MAX_VHOST_DEVICE; i++) {
 		if (vhost_devices[i] == NULL)
 			break;
 	}
+
 	if (i == MAX_VHOST_DEVICE) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"Failed to find a free slot for new device.\n");
-		rte_free(dev);
+		return -1;
+	}
+
+	dev = rte_zmalloc(NULL, sizeof(struct virtio_net), 0);
+	if (dev == NULL) {
+		RTE_LOG(ERR, VHOST_CONFIG,
+			"Failed to allocate memory for new dev.\n");
 		return -1;
 	}
 
-- 
1.8.3.1

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

* Re: [dpdk-dev] [PATCH] vhost: refine the vhost_new_device
  2018-06-08  9:18 [dpdk-dev] [PATCH] vhost: refine the vhost_new_device xiangxia.m.yue
@ 2018-06-08 14:05 ` Maxime Coquelin
  2018-06-15  8:01 ` Maxime Coquelin
  1 sibling, 0 replies; 3+ messages in thread
From: Maxime Coquelin @ 2018-06-08 14:05 UTC (permalink / raw)
  To: xiangxia.m.yue, dev



On 06/08/2018 11:18 AM, xiangxia.m.yue@gmail.com wrote:
> From: Tonghao Zhang <xiangxia.m.yue@gmail.com>
> 
> Make sure find avalid device id before allocating
> virtio_net, if not, return directly. It may avoid
> allocating and freeing virtio_net when there is
> not valid device id.
> 
> Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
> ---
>   lib/librte_vhost/vhost.c | 16 ++++++++--------
>   1 file changed, 8 insertions(+), 8 deletions(-)
> 

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

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

* Re: [dpdk-dev] [PATCH] vhost: refine the vhost_new_device
  2018-06-08  9:18 [dpdk-dev] [PATCH] vhost: refine the vhost_new_device xiangxia.m.yue
  2018-06-08 14:05 ` Maxime Coquelin
@ 2018-06-15  8:01 ` Maxime Coquelin
  1 sibling, 0 replies; 3+ messages in thread
From: Maxime Coquelin @ 2018-06-15  8:01 UTC (permalink / raw)
  To: xiangxia.m.yue, dev



On 06/08/2018 11:18 AM, xiangxia.m.yue@gmail.com wrote:
> From: Tonghao Zhang<xiangxia.m.yue@gmail.com>
> 
> Make sure find avalid device id before allocating
> virtio_net, if not, return directly. It may avoid
> allocating and freeing virtio_net when there is
> not valid device id.
> 
> Signed-off-by: Tonghao Zhang<xiangxia.m.yue@gmail.com>
> ---
>   lib/librte_vhost/vhost.c | 16 ++++++++--------
>   1 file changed, 8 insertions(+), 8 deletions(-)

Applied to dpdk-next-virtio/master

Thanks,
Maxime

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

end of thread, other threads:[~2018-06-15  8:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-08  9:18 [dpdk-dev] [PATCH] vhost: refine the vhost_new_device xiangxia.m.yue
2018-06-08 14:05 ` Maxime Coquelin
2018-06-15  8:01 ` Maxime Coquelin

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).