diff mbox

[dpdk-dev,1/2] vhost: malloc -> rte_malloc for virtio_net and virt queue allocation

Message ID 1433474005-597-2-git-send-email-huawei.xie@intel.com (mailing list archive)
State Changes Requested, archived
Headers show

Commit Message

Huawei Xie June 5, 2015, 3:13 a.m. UTC
use rte_malloc/free for virtio_net and virt queue allocation/free

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
---
 lib/librte_vhost/virtio-net.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

Comments

Thomas Monjalon June 17, 2015, 5:06 p.m. UTC | #1
2015-06-05 11:13, Huawei Xie:
> use rte_malloc/free for virtio_net and virt queue allocation/free
> 
> Signed-off-by: Huawei Xie <huawei.xie@intel.com>

I suggest this title:
vhost: use rte_malloc to allocate device and queues
diff mbox

Patch

diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 4672e67..19b74d6 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -45,6 +45,7 @@ 
 #include <rte_log.h>
 #include <rte_string_fns.h>
 #include <rte_memory.h>
+#include <rte_malloc.h>
 #include <rte_virtio_net.h>
 
 #include "vhost-net.h"
@@ -202,9 +203,9 @@  static void
 free_device(struct virtio_net_config_ll *ll_dev)
 {
 	/* Free any malloc'd memory */
-	free(ll_dev->dev.virtqueue[VIRTIO_RXQ]);
-	free(ll_dev->dev.virtqueue[VIRTIO_TXQ]);
-	free(ll_dev);
+	rte_free(ll_dev->dev.virtqueue[VIRTIO_RXQ]);
+	rte_free(ll_dev->dev.virtqueue[VIRTIO_TXQ]);
+	rte_free(ll_dev);
 }
 
 /*
@@ -278,7 +279,7 @@  new_device(struct vhost_device_ctx ctx)
 	struct vhost_virtqueue *virtqueue_rx, *virtqueue_tx;
 
 	/* Setup device and virtqueues. */
-	new_ll_dev = malloc(sizeof(struct virtio_net_config_ll));
+	new_ll_dev = rte_malloc(NULL, sizeof(struct virtio_net_config_ll), 0);
 	if (new_ll_dev == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%"PRIu64") Failed to allocate memory for dev.\n",
@@ -286,19 +287,19 @@  new_device(struct vhost_device_ctx ctx)
 		return -1;
 	}
 
-	virtqueue_rx = malloc(sizeof(struct vhost_virtqueue));
+	virtqueue_rx = rte_malloc(NULL, sizeof(struct vhost_virtqueue), 0);
 	if (virtqueue_rx == NULL) {
-		free(new_ll_dev);
+		rte_free(new_ll_dev);
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%"PRIu64") Failed to allocate memory for rxq.\n",
 			ctx.fh);
 		return -1;
 	}
 
-	virtqueue_tx = malloc(sizeof(struct vhost_virtqueue));
+	virtqueue_tx = rte_malloc(NULL, sizeof(struct vhost_virtqueue), 0);
 	if (virtqueue_tx == NULL) {
-		free(virtqueue_rx);
-		free(new_ll_dev);
+		rte_free(virtqueue_rx);
+		rte_free(new_ll_dev);
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%"PRIu64") Failed to allocate memory for txq.\n",
 			ctx.fh);